#include <IRremote.h>
#include <Stepper.h>
const int stepsPerRevolution = 200;
#define IR_PIN 2
#define STEPPER_PIN1 10
#define STEPPER_PIN2 11
#define STEPPER_PIN3 12
#define STEPPER_PIN4 13
IRrecv irrecv(IR_PIN);
decode_results results;
Stepper stepper(stepsPerRevolution, STEPPER_PIN1, STEPPER_PIN2, STEPPER_PIN3, STEPPER_PIN4);
int previous = 0;
int stepperSteps = 0;
void setup() {
stepper.setSpeed(200);
irrecv.enableIRIn();
}
void loop() {
if (irrecv.decode()) {
switch (irrecv.decodedIRData.command) {
case 2: // Tombol +
stepperSteps += 1;
if (stepperSteps > stepsPerRevolution) {
stepperSteps = stepsPerRevolution;
}
break;
case 152: // Tombol -
stepperSteps -= 1;
if (stepperSteps < 0) {
stepperSteps = 0;
}
break;
}
irrecv.resume();
stepper.step(stepperSteps - previous);
previous = stepperSteps;
}
}