PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 年之前
123456789101112131415161718192021222324252627282930
  1. // Random.pde
  2. // -*- mode: C++ -*-
  3. //
  4. // Make a single stepper perform random changes in speed, position and acceleration
  5. //
  6. // Copyright (C) 2009 Mike McCauley
  7. // $Id: Random.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $
  8. #include <AccelStepper.h>
  9. // Define a stepper and the pins it will use
  10. AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
  11. void setup()
  12. {
  13. }
  14. void loop()
  15. {
  16. if (stepper.distanceToGo() == 0)
  17. {
  18. // Random change to speed, position and acceleration
  19. // Make sure we dont get 0 speed or accelerations
  20. delay(1000);
  21. stepper.moveTo(rand() % 200);
  22. stepper.setMaxSpeed((rand() % 200) + 1);
  23. stepper.setAcceleration((rand() % 200) + 1);
  24. }
  25. stepper.run();
  26. }