PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

31 行
724B

  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. }