Hello,
I would like my code to run at the press of the button. Currently, the stepper will only move when the button is actively pressed. I'd like for one press to cause the stepper to do two revolutions.
Any ideas?
Here is my code:
''#include <Stepper.h>
const int stepsPerRevolution = 150; // change this to fit the number of steps per revolution
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
const int buttonPin = 2;
int buttonState = 0;
int buttonPushCounter = 0; // counter for the number of button presses
int lastButtonState = 0; // previous state of the button
void setup() {
myStepper.setSpeed(120);
pinMode(buttonPin, INPUT_PULLUP); //high off and low on
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
buttonState = digitalRead(buttonPin);
if (buttonState == LOW) {
delay (100);
(buttonState = LOW);
delay (100);
Serial.println("on");
Spreader();
delay(500);
}
}
void Spreader() {
// read the pushbutton input pin:
myStepper.step(stepsPerRevolution * 2);
}
"