Created
February 20, 2013 21:47
-
-
Save pierot/4999922 to your computer and use it in GitHub Desktop.
send_ir.pde
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This sketch will send out a Nikon D50 trigger signal (probably works with most Nikons) | |
// See the full tutorial at http://www.ladyada.net/learn/sensors/ir.html | |
// this code is public domain, please enjoy! | |
int IRledPin = 13; // LED connected to digital pin 13 | |
// The setup() method runs once, when the sketch starts | |
void setup() { | |
// initialize the IR digital pin as an output: | |
pinMode(IRledPin, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
Serial.println("Sending IR signal"); | |
SendTVCode(); | |
delay(60*1000); // wait one minute (60 seconds * 1000 milliseconds) | |
} | |
// This procedure sends a 38KHz pulse to the IRledPin | |
// for a certain # of microseconds. We'll use this whenever we need to send codes | |
void pulseIR(long microsecs) { | |
// we'll count down from the number of microseconds we are told to wait | |
cli(); // this turns off any background interrupts | |
while (microsecs > 0) { | |
// 38 kHz is about 13 microseconds high and 13 microseconds low | |
digitalWrite(IRledPin, HIGH); // this takes about 3 microseconds to happen | |
delayMicroseconds(10); // hang out for 10 microseconds, you can also change this to 9 if its not working | |
digitalWrite(IRledPin, LOW); // this also takes about 3 microseconds | |
delayMicroseconds(10); // hang out for 10 microseconds, you can also change this to 9 if its not working | |
// so 26 microseconds altogether | |
microsecs -= 26; | |
} | |
sei(); // this turns them back on | |
} | |
void SendTVCode() { | |
// This is the code for my particular Nikon, for others use the tutorial | |
// to 'grab' the proper code from the remote | |
pulseIR(4500); | |
delay(44); | |
pulseIR(600); | |
delayMicroseconds(3500); | |
pulseIR(300); | |
delayMicroseconds(0); | |
pulseIR(600); | |
delay(65); // wait 65 milliseconds before sending it again | |
pulseIR(4500); | |
delay(44); | |
pulseIR(600); | |
delayMicroseconds(3500); | |
pulseIR(300); | |
delayMicroseconds(0); | |
pulseIR(600); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment