Hello,
I'm trying to write a simple ir remote to motor program but it doesn't continue while I hold the button down. It just runs the stepper.step once and then stops. Only when I let go of the one button on the remote will it do it again. I want the stepper to continue until I let go of that button. I thought it was the delay at the end of the translateIR function but that didn't work. Should I eliminate the delay?
Thanks,
Josh
#include <Stepper.h>
#include "IRremote.h"
int receiver = 5; // Signal Pin of IR receiver to Arduino Digital Pin
/*-----( Declare objects )-----*/
IRrecv irrecv(receiver);
decode_results results;
// create instance of 'irrecv'
// create instance of 'decode_results'
// Define motor pins connected to ULN2003 driver
#define MP1 8 // IN1 on the ULN2003
#define MP2 9 // IN2 on the ULN2003
#define MP3 10 // IN3 on the ULN2003
#define MP4 11 // IN4 on the ULN2003
#define SPR 2048 // Steps per revolution (for 28BYJ-48 stepper motor)
int homePos = 1024;
int loc=0;
// Create Stepper object
Stepper stepper(SPR, MP1, MP3, MP2, MP4);
void translateIR() // takes action based on IR code received
// describing Remote IR codes
{
switch(results.value)
{
case 0xFFA25D: Serial.println("POWER"); break;
case 0xFFE21D: Serial.println("VOL STOP"); break;
case 0xFF629D: Serial.println("MODE"); break;
case 0xFF22DD: Serial.println("PAUSE"); break;
case 0xFF02FD: Serial.println("FAST BACK"); break;
case 0xFFC23D: Serial.println("FAST FORWARD"); break;
case 0xFFE01F: Serial.println("EQ"); break;
case 0xFFA857: Serial.println("VOL-"); break;
case 0xFF906F: Serial.println("VOL+"); break;
case 0xFF9867: Serial.println("RETURN"); break;
case 0xFFB04F: Serial.println("USB SCAN"); break;
case 0xFF6897: Serial.println("0"); break;
case 0xFF30CF: Serial.println("1"); stepper.step(1000); break;
case 0xFF18E7: Serial.println("2"); stepper.step(-1000) break;
case 0xFF7A85: Serial.println("3"); break;
case 0xFF10EF: Serial.println("4"); break;
case 0xFF38C7: Serial.println("5"); break;
case 0xFF5AA5: Serial.println("6"); break;
case 0xFF42BD: Serial.println("7"); break;
case 0xFF4AB5: Serial.println("8"); break;
case 0xFF52AD: Serial.println("9"); break;
case 0xFFFFFFFF: Serial.println(" REPEAT");break;
default:
Serial.println(" other button ");
}// End Case
delay(10); // Do not get immediate repeat
} //END translateIR
void setup()
{
Serial.begin(9600);
// Set motor speed
// Set speed to 10 RPM
// HAVE TO SET STEPPER SPEED HERE
stepper.setSpeed(10);
irrecv.enableIRIn();
Serial.begin(9600);
}
void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
translateIR();
irrecv.resume(); // receive the next value
}
}
