Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Stepper.h>
- const int stepsPerRevolution = 200; // Steps per turn
- Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); // Wiring
- int stepCount = 0;
- void setup() {}
- void loop() {
- // read the sensor value:
- int sensorReading = 256; // analogRead(A0);
- // map it to a range from 0 to 100:
- int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
- // set the motor speed:
- if (motorSpeed > 0) {
- myStepper.setSpeed(motorSpeed);
- // step 1/100 of a revolution:
- myStepper.step(stepsPerRevolution / 100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement