Advertisement
jfsimon1981

Untitled

Jun 29th, 2025
435
0
6 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <Stepper.h>
  2.  
  3. const int stepsPerRevolution = 200; // Steps per turn
  4. Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); // Wiring
  5.  
  6. int stepCount = 0;
  7.  
  8. void setup() {}
  9.  
  10. void loop() {
  11.   // read the sensor value:
  12.   int sensorReading = 256; // analogRead(A0);
  13.  
  14.   // map it to a range from 0 to 100:
  15.   int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
  16.  
  17.   // set the motor speed:
  18.   if (motorSpeed > 0) {
  19.     myStepper.setSpeed(motorSpeed);
  20.     // step 1/100 of a revolution:
  21.     myStepper.step(stepsPerRevolution / 100);
  22.   }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement