PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

41 lines
1.0KB

  1. // Quickstop.pde
  2. // -*- mode: C++ -*-
  3. //
  4. // Check stop handling.
  5. // Calls stop() while the stepper is travelling at full speed, causing
  6. // the stepper to stop as quickly as possible, within the constraints of the
  7. // current acceleration.
  8. //
  9. // Copyright (C) 2012 Mike McCauley
  10. // $Id: $
  11. #include <AccelStepper.h>
  12. // Define a stepper and the pins it will use
  13. AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
  14. void setup()
  15. {
  16. stepper.setMaxSpeed(150);
  17. stepper.setAcceleration(100);
  18. }
  19. void loop()
  20. {
  21. stepper.moveTo(500);
  22. while (stepper.currentPosition() != 300) // Full speed up to 300
  23. stepper.run();
  24. stepper.stop(); // Stop as fast as possible: sets new target
  25. stepper.runToPosition();
  26. // Now stopped after quickstop
  27. // Now go backwards
  28. stepper.moveTo(-500);
  29. while (stepper.currentPosition() != 0) // Full speed basck to 0
  30. stepper.run();
  31. stepper.stop(); // Stop as fast as possible: sets new target
  32. stepper.runToPosition();
  33. // Now stopped after quickstop
  34. }