First of all, so sorry if this is in the wrong place, I just joined and have tried for several days to complete a little project, but to no avail ;-(..
I have Arduino UNO, IDE- 1.6.7, an IR receive led, and an IR send led, also a servo and a standard NEC protocol Arduino kit remote.
Many hours of searching gave me a sketch that works with the ir receive and moves the servo either left or right while holding the button down, also stops when released.
Using "irlib"
I have another sketch which uses "Nikonirlib", which when uploaded sends a signal to my Nikon camera every 1 second.
I have tried and tried to put these two sketches together and it compiles with no errors but the ir send led does nothing.
My end result would be to have the IR send to the nikon only when either of the remote buttons are being held down.
I have attached both codes, these are not mine and I give credit to the initial writers of these sketches.
The servo.ino has my attempt :
#include
#include
#include
// You will have to set these values depending on the protocol
// and remote codes that you are using. These are For the Adafruit
// Mini Remote
#define MY_PROTOCOL NEC
#define RIGHT_ARROW 0x538DC23D //Move several clockwise
#define LEFT_ARROW 0x538DF807 //Move servo counterclockwise
#define SELECT_BUTTON 0xfd906f //Center the servo
#define UP_ARROW 0xfda05f //Increased number of degrees servo moves
#define DOWN_ARROW 0xfdb04f //Decrease number of degrees servo moves
#define BUTTON_0 0xfd30cf //Pushing buttons 0-9 moves to fixed positions
#define BUTTON_1 0xfd08f7 // each 20 degrees greater
#define BUTTON_2 0xfd8877
#define BUTTON_3 0xfd48b7
#define BUTTON_4 0xfd28d7
#define BUTTON_5 0xfda857
#define BUTTON_6 0xfd6897
#define BUTTON_7 0xfd18e7
#define BUTTON_8 0xfd9867
#define BUTTON_9 0xfd58a7
IRrecv My_Receiver(11);//Receive on pin 11
IRdecode My_Decoder;
Servo My_Servo; // create servo object to control a servo
int pos; // variable to store the servo position
int Speed; // Number of degrees to move each time a left/right button is pressed
long Previous; // Stores previous code to handle NEC repeat codes
int CameraIrPin = 13;
void setup()
{
pinMode(CameraIrPin, OUTPUT);
My_Servo.attach(9); // attaches the servo on pin 9 to the servo object
pos = 90; // start at midpoint 90 degrees
Speed = 3; // servo moves 3 degrees each time left/right is pushed
My_Servo.write(pos); // Set initial position
My_Receiver.enableIRIn(); // Start the receiver
}
void loop()
{
if (My_Receiver.GetResults(&My_Decoder)) {
My_Decoder.decode();
if(My_Decoder.decode_type==MY_PROTOCOL) {
if(My_Decoder.value==0xFFFFFFFF)
My_Decoder.value=Previous;
switch(My_Decoder.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;
case BUTTON_0: pos=020; break;
case BUTTON_1: pos=120; break;
case BUTTON_2: pos=220; break;
case BUTTON_3: pos=320; break;
case BUTTON_4: pos=420; break;
case BUTTON_5: pos=520; break;
case BUTTON_6: pos=620; break;
case BUTTON_7: pos=720; break;
case BUTTON_8: pos=820; break;
case BUTTON_9: pos=920; break;
cameraSnap(CameraIrPin);
delay(1000);
}
My_Servo.write(pos); // tell servo to go to position in variable 'pos'
Previous=My_Decoder.value;
}
My_Receiver.resume();
}
}
This_moves_servo.ino (2.83 KB)
This_takes_a_photo.ino (1.01 KB)