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.

33 lines
870B

  1. // ProportionalControl.pde
  2. // -*- mode: C++ -*-
  3. //
  4. // Make a single stepper follow the analog value read from a pot or whatever
  5. // The stepper will move at a constant speed to each newly set posiiton,
  6. // depending on the value of the pot.
  7. //
  8. // Copyright (C) 2012 Mike McCauley
  9. // $Id: ProportionalControl.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $
  10. #include <AccelStepper.h>
  11. // Define a stepper and the pins it will use
  12. AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
  13. // This defines the analog input pin for reading the control voltage
  14. // Tested with a 10k linear pot between 5v and GND
  15. #define ANALOG_IN A0
  16. void setup()
  17. {
  18. stepper.setMaxSpeed(1000);
  19. }
  20. void loop()
  21. {
  22. // Read new position
  23. int analog_in = analogRead(ANALOG_IN);
  24. stepper.moveTo(analog_in);
  25. stepper.setSpeed(100);
  26. stepper.runSpeedToPosition();
  27. }