I'm new to remote control, and somewhat new to Arduino too.
I've tried to get the following code to work:
#include <IRLibAll.h>
#include <Servo.h>
#define MY_PROTOCOL NEC
#define RIGHT_ARROW ff5aa5 //Move several clockwise
#define LEFT_ARROW ff10ef //Move servo counterclockwise
#define SELECT_BUTTON ff38c7 //Center the servo
#define UP_ARROW ff18e7 //Increased number of degrees servo moves
#define DOWN_ARROW ff4ab5 //Decrease number of degrees servo moves
IRrecv myReceiver(2); //pin number for the receiver
IRdecode myDecoder;
Servo myServo; // create servo object to control a servo
int16_t pos; // variable to store the servo position
int16_t Speed; // Number of degrees to move each time a left/right button is pressed
uint32_t Previous;//handles NEC repeat codes
void setup() {
// put your setup code here, to run once:
myServo.attach(9); // attaches the servo on pin 9 to the servo object
pos = 90; // start at midpoint 90 degrees
Speed = 45; // servo moves 3 degrees each time left/right is pushed
myServo.write(pos); // Set initial position
myReceiver.enableIRIn(); // Start the receiver
}
void loop() {
// put your main code here, to run repeatedly:
if (myReceiver.getResults()) {
myDecoder.decode();
if(myDecoder.protocolNum==MY_PROTOCOL) {
if(myDecoder.value==0xFFFFFFFF)
myDecoder.value=Previous;
switch(myDecoder.value) {
case LEFT_ARROW: pos=min(180,pos+Speed); break;
case RIGHT_ARROW: pos=max(0,pos-Speed); break;
case SELECT_BUTTON: pos=90; break;
case UP_ARROW: Speed=min(10, Speed+1); break;
case DOWN_ARROW: Speed=max(1, Speed-1); break;
}
myServo.write(pos); // tell servo to go to position in variable 'pos'
Previous=myDecoder.value;
}
myReceiver.enableIRIn();
}
}
Also see pic of project.
I'm trying to use just 5 buttons of the remote (see pic) and I want to simply use them as follows:
LEFT_ARROW: --- a 45 degree turn to the left
RIGHT_ARROW -----a 45 degree turn to the right
SELECT_BUTTON: --(or actually the red OK button). center position 90 degrees (this is the little 180 degree servo we're talking about)
UP_ARROW --- a little different, a 90 degree turn to the right
DOWN_ARROW a 90 degree turn to the left
I didn't use all the other buttons on the remote, (or put them in the code). I got the hex codes (ff5aa5, etc.) from one of the dump programs - that worked.
Several problems:
the RLibAll.h library --- That does not compile, it is a master zip file, and you can't use the 'load zip' file function.
You can't use the 'add file' function either. On closer inspection the 'ReadMe' file doesn't look like it goes with the Master file. Thought I got it from a reputable source.
I also get the error:
Error compiling for board Arduino/Genuno Uno
I also 'type' error on the receiver.
The code was real close to what I was after, but there are some things I'm definitely not sure of, or don't understand, for example:
Speed = 45 (and then it mentions 3 degrees ???
and the
Speed=min(10, Speed+1); (not sure how that's supposed to work)
Hope the above helps.
I'd like to get this working, because I need to do some other projects with remote control; but I'm wondering if it would be easier using potentiometers instead of fumbling with the codes and libraries.
Thanks
