The motor will respond to the first button press correctly, but then it will just spin forever. Looking at the serial monitor, it will only display the input of the first press and none after that. I have tried many things to fix this, but this is my first day coding like this.
#include <IRremote.h>
#include <Stepper.h>
int RECV_PIN = 3;
IRrecv irrecv(RECV_PIN);
decode_results results;
int steps = 2038;
Stepper myStepper = Stepper(steps, 8, 10, 9, 11);
void setup() {
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value);
switch (results.value) {
case 3877175040: // Replace this with the actual value for your up button
myStepper.setSpeed(5);
myStepper.step(steps); // Move the stepper motor
delay(10); // Introduce a delay to control speed
myStepper.setSpeed(0);
myStepper.step(0); // Stop the stepper motor after releasing the button
break;
case 381032832: // Replace this with the actual value for your stop button
myStepper.setSpeed(0);
myStepper.step(0); // Stop the stepper motor
break;
case 2907897600: // Replace this with the actual value for your down button
myStepper.setSpeed(-5); // Reverse direction (example: counterclockwise)
myStepper.step(steps); // Move the stepper motor
delay(10); // Introduce a delay to control speed
myStepper.setSpeed(0);
myStepper.step(0); // Stop the stepper motor after releasing the button
break;
}
irrecv.resume(); // Receive the next value
}
}