this is code for a steering servo for a IR remote controlled car,
at the moment the servo stays in full left or right position unless the
"center" button is pressed, i would like the servo to center itself when it
recieves no input from the IR remote.
EX: press right button the servo steers right, release button the servo centers itself
can anyone help ?
***************************
#include <Servo.h>
#include <IRremote.h>
unsigned long Value2 = 0xFF10EF; // left
unsigned long Value1 = 0xFF5AA5; // right
unsigned long Value3 = 0xFF38C7; // center
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
Servo servo1;
// the setup routine runs once when you press reset:
void setup() {
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
// initialize the digital pin as an output.
servo1.attach(10); // attack servo to digital pin 10
}
// the loop routine runs over and over again forever:
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
if(results.value == Value1) { //right
servo1.write(179);
}
if(results.value == Value2) { //left
servo1.write(1);
}
if(results.value == Value3) { //center
servo1.write(80);
}
}
**********************************