Unfortunately, as soon as the stepper stops, both boards go black (LEDs turn off) for a second, and then they re-start, but the Trinket is now in "programming mode" (DotStar is red) instead of waiting for the next button press. I don't think it's a code issue, but code is below. I'm guessing it's something the stepper driver is doing when it finishes it's run..? Any ideas? Thanks!
Code: Select all
#include <Stepper.h>
const int buttonPin = 4; // the number of the pushbutton pin
const int stepsPerRevolution = 200; //how many steps
// initialize the stepper library on pins 0 through 3:
Stepper myStepper(stepsPerRevolution, 0, 1, 2, 3);
int rpm = 240; //speed variable
int rot = 20; //how many turns
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
pour();
}
}
void pour() {
delay(500);
myStepper.setSpeed(rpm);
// turn the desired amount:
myStepper.step(stepsPerRevolution * rot);
while (digitalRead(buttonPin) == HIGH) {
}
}