CONTROLLING BIPOLAR STEPPER WITH IR REMOTE

Stepper w remote

#include <IRremote.h>
#include <AccelStepper.h>
#include <EEPROM.h>
#define dirPin 4
#define stepPin 3
#define motorInterfaceType 1
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
int RECV_PIN = 2; // must be on pin 2, interrupt pin
byte sta;
IRrecv irrecv(RECV_PIN);

decode_results results;
const int relPin = 5;
void setup()
{
Serial.begin(9600);
stepper.setMaxSpeed(1000);
attachInterrupt(0,CHECK_IR,CHANGE);
irrecv.enableIRIn();
pinMode(relPin,OUTPUT);
}
unsigned long last = millis();
int on = 0;
void loop() {
sta = EEPROM.read(2);
if(sta==1){
digitalWrite(relPin,HIGH);
stepper.setSpeed(50);
stepper.runSpeed();
}
if(sta==2){
digitalWrite(relPin,HIGH);
stepper.setSpeed(-50);
stepper.runSpeed();
}
if(sta==0){
digitalWrite(relPin,LOW);
}
}

void CHECK_IR(){
if (irrecv.decode(&results)) {

if (results.value == 0xEF1001FE) {

if (millis() – last > 250) {
on = !on;
(on ? rec1():rec2());
}
last = millis();
}
if (results.value == 0xEF1055AA) {

if (millis() – last > 250) {
on = !on;
(on ? rec1():rec3());
}
last = millis();
}
irrecv.resume();
}
}

void rec1(){
EEPROM.write(2, 0);
}
void rec2(){
EEPROM.write(2, 1);
}
void rec3(){
EEPROM.write(2, 2);
}