I have a continuous servo motor connected to my Arduino UNO. I want it to react to the Hexadecimal code received by an Infrared remote. I want the motor to rotate once in one direction and then rotate once in the reverse direction and then stop until triggered by the remote again. At the moment, the remote will cause the the motor to rotate once in one way but then it rotates continuously in the reverse direction. Any help would be much appreciated!
#include "IRremote.h"
#include <Servo.h>
int receiver = 11; // Signal Pin of IR receiver to Arduino Digital Pin 11
Servo servoMain;
IRrecv irrecv(receiver);
decode_results results;
void setup()
{
Serial.begin(9600);
Serial.println("IR Receiver Button Decode");
irrecv.enableIRIn(); // Start the receiver
servoMain.attach(10);
}
void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
translateIR();
irrecv.resume(); // receive the next value
}
}
void translateIR() // takes action based on IR code received
// describing Remote IR codes
{
switch (results.value)
{
case 551520375: servoMain.write(180); delay(1000); servoMain.write(0); delay(1000); break;
default: break;
}
delay(500); // Do not get immediate repeat
} //END translateIR