root / Ports / examples / snapNikon / snapNikon.pde
History | View | Annotate | Download (1.2 KB)
| 1 | //>>> The latest version of this code can be found at https://github.com/jcw/ !! |
|---|---|
| 2 | |
| 3 | // Send a remote command to take a snapshot on a Nikon camera, using infrared |
| 4 | // 2010-06-10 <jcw@equi4.com> http://opensource.org/licenses/mit-license.php |
| 5 | // $Id: snapNikon.pde 7763 2011-12-11 01:28:16Z jcw $ |
| 6 | |
| 7 | // IR LED connected between DIO1 and GND with a 33 ohm resistor in series |
| 8 | // using direct pin I/O for speed and PINx output for fast toggling |
| 9 | // |
| 10 | // the timing info was found at http://www.bigmike.it/ircontrol/ |
| 11 | |
| 12 | void setup () {
|
| 13 | digitalWrite(4, 0); // off |
| 14 | pinMode(4, OUTPUT); |
| 15 | } |
| 16 | |
| 17 | // 38.4 Khz is 26 us cycle, so toggle at 13 us and correct for overhead |
| 18 | static void send(word us) {
|
| 19 | // this won't overflow for pulses up to 3327 us |
| 20 | byte count = us / 13; |
| 21 | do {
|
| 22 | PIND = bit(4); // toggles the IR LED pin |
| 23 | delayMicroseconds(12); |
| 24 | } while (--count); |
| 25 | bitClear(PORTD, 4); // make sure the LED is off at the end |
| 26 | } |
| 27 | |
| 28 | static void snapshot() {
|
| 29 | for (byte i = 0; i < 2; ++i) {
|
| 30 | send(2000); |
| 31 | delay(28); |
| 32 | send(400); |
| 33 | delayMicroseconds(1600); |
| 34 | send(400); |
| 35 | delayMicroseconds(3600); |
| 36 | send(400); |
| 37 | delay(63); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | void loop () {
|
| 42 | snapshot(); |
| 43 | delay(3000); |
| 44 | } |