Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Include the Arduino Stepper Library
- #include <Stepper.h>
- // Number of steps per output rotation
- const int stepsPerRevolution = 200;
- const int button1Pin = 12;
- const int button2Pin = 13;
- // Create Instance of Stepper library
- Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
- int Runtime = 0;
- int StpSpd = 60;
- int button1State = 0;
- int button2State = 0;
- void setup()
- {
- // set the speed at 60 rpm:
- myStepper.setSpeed(StpSpd);
- // initialize the serial port:
- Serial.begin(9600);
- pinMode(button1Pin, INPUT_PULLUP);
- pinMode(button2Pin, INPUT_PULLUP);
- }
- void loop()
- {
- button1State = digitalRead(button1Pin);
- button2State = digitalRead(button2Pin);
- if (button1State == LOW) {
- while (Runtime < 30)
- {
- Serial.println("clockwise");
- myStepper.step(stepsPerRevolution);
- StpSpd = StpSpd + 60;
- if (StpSpd > 240) {
- StpSpd = 240;
- }
- myStepper.setSpeed(StpSpd);
- Runtime++;
- }
- Runtime = 0;
- StpSpd = 60;
- myStepper.setSpeed(StpSpd);
- }
- if (button2State == LOW) {
- while (Runtime < 30)
- {
- Serial.println("counterclockwise");
- myStepper.step(stepsPerRevolution);
- StpSpd = StpSpd + 60;
- if (StpSpd > 240) {
- StpSpd = 240;
- }
- myStepper.setSpeed(StpSpd);
- Runtime++;
- }
- Runtime = 0;
- StpSpd = 60;
- myStepper.setSpeed(StpSpd);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement