// Stepper motor on Wokwi!
#include <IRremote.h>
#include <Stepper.h>
#define PIN_RECEIVER 0 // Signal Pin of IR receiver
IRrecv receiver(PIN_RECEIVER);
const int StepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper1(StepsPerRevolution, 2,3,4,5);
Stepper myStepper2(StepsPerRevolution, 6,7,8,9);
void setup() {
receiver.enableIRIn(); // Start the receiver
// set the speed at 60 rpm:
myStepper1.setSpeed(60);
myStepper2.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// Checks received an IR signal
if (receiver.decode()) {
translateIR();
receiver.resume();// Receive the next value
}
}
void translateIR(){
// Takes command based on IR code received
switch (receiver.decodedIRData.command){
case 162: //power
break;
case 2: //plus
break;
case 224: //prev.
// step one revolution in the other direction:
myStepper1.step(-StepsPerRevolution);
myStepper2.step(-StepsPerRevolution);
break;
case 144: //next
// step one revolution in one direction:
myStepper1.step(StepsPerRevolution);
myStepper2.step(StepsPerRevolution);
break;
case 176: //key: c
break;
case 48: //num 1
break;
case 24: //num 2
break;
}
}