#include <IRremote.h>
#include <Stepper.h>
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 2, 3, 4, 5);
int currentStepCount = 0;
int Receiver = 6;
IRrecv irrecv(Receiver);
decode_results results;
void setup() {
Serial.begin(9600);
myStepper.setSpeed(30);
irrecv.enableIRIn();
}
void loop() {
if (irrecv.decode()) {
button();
Serial.print("Sudut: ");
Serial.print(currentStep());
Serial.println("°");
irrecv.resume();
}
}
void button() {
int inputan = irrecv.decodedIRData.command;
if (inputan == 2) {
if(currentStep() < 200){
myStepper.step(1);
currentStepCount++;
}
}
if (inputan == 152) {
if(currentStep() > 0){
myStepper.step(-1);
currentStepCount--;
}
}
}
int currentStep() {
return currentStepCount;
}