I'm trying to be able to move a servo to predefined positions with an IR remote, but I'm having trouble understanding part of the IR programming. I'm using the IR library by Ken Shirriff. But here is the biggest problem I am facing so far.
I have searched all over the place, but cannot seem to find any good reference to the commands or code that are available to use. What I mean by that is, say compared to the servo library, I can find reference to what functions are available for the servos such as myservo.write(), myservo.read(), myservo.attach(), etc. However I have been unable to find any similar reference for the IR library. The only commands I found are ones I've attempted to reverse engineer from the examples, and being a newbie, I have found trying to reverse engineer these IR examples to be much more difficult. If i had a reference to what commands were available, and the correct format to use them in it would be much easier.
Here is the work in progress code that I have so far........
#include <IRremote.h>
#include <Servo.h>
int RECV_PIN = 11;
Servo myservo; // create servo object to control a servo
int position1; //servo position 1
int position2; //servo position 2
int position3; //servo position 3
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
position1 = 0; //default servo positon 1
position2 = 90; //default servo position 2
position3 = 179; //default servo position 3
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
myservo.attach(9); // attaches the servo on pin 9
myservo.write(position3); //start the servo out at position 3
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
}
Now I used the example IRrecvDemo in order to map the buttons of my NEC remote. For example button one gave me FFA25D, button 2 gave me FF629D, button 3 gave me FFE21D. But i'm unsure of the correct code to link them, so that pressing button 1 will cause myservo.write(position1).
Also, I copied all the IR code from the example, and I'm unsure if the serial portions, such as "Serial.begin(9600);" and "Serial.println(results.value, HEX);", are necessary. Can that stuff be taken out? Isn't that only necessary if I'm wanting to view the data with the serial monitor?
Thanks for the help. Eventually what I want it to do is have 3 different buttons for 3 different servo positions. Then have an up and a down button that move the servo 1 degree at a time in either direction. Then have 3 storage buttons (so that I can basically program the main 3 servo positions by using the up and down buttons to move the servo exactly where i want it, and press the corresponding store button to store that as position 1, 2, and 3). Then finally I will want to store those 3 values in eeprom so that I won't have to redo them every time the power is turned off.