This is a Library I have created for a Project, the aim being to send the shutter release trigger signal to my Nikon D40x DSLR using an IR led. The code defaults to a 38.4KHz oscilation but can be set to any frequency.
Revision 0:083159111741, committed 2010-12-01
- Comitter:
- hazanjon
- Date:
- Wed Dec 01 00:36:04 2010 +0000
- Commit message:
- Beta
Changed in this revision
Pulse.cpp | Show annotated file Show diff for this revision Revisions of this file |
Pulse.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 083159111741 Pulse.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Pulse.cpp Wed Dec 01 00:36:04 2010 +0000 @@ -0,0 +1,50 @@ + +#include "Pulse.h" +#include "mbed.h" + + Pulse::Pulse(PinName pin) : output_pin(pin) { + output_pin = 0; + switch_state = false; + oscilation = 38400; //Set default oscilation to 38.4KHz + } + + void Pulse::send_pulse(int* sequence){ + int num_switches = (sizeof(sequence)/sizeof(int)); + int tick = 1000000/oscilation; + for(int i = 0; i < num_switches; i++){ + if(i % 2 == 0){ + change_state(); + output_pin = 1; + flipper.attach_us(this, &Pulse::flip_pin, tick); + wait_us(sequence[i]); + flipper.detach(); + change_state(); + output_pin = 0; + }else{ + wait_us(sequence[i]); + } + } + } + + void Pulse::set_osc(int khz){ + if(khz > 0 && khz <= 250000) //Make sure that the new oscilation is positive and also less than 250KHz + oscilation = khz; + } + + void Pulse::set_pin(PinName pin){ + output_pin = pin; + } + + void Pulse::flip_pin(){ + if(switch_state) //Stop the output from switching unless it is meant to be transmitting + output_pin = !output_pin; + else + output_pin = 0; + } + + void Pulse::change_state(){ + switch_state = !switch_state; + } + + +
diff -r 000000000000 -r 083159111741 Pulse.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Pulse.h Wed Dec 01 00:36:04 2010 +0000 @@ -0,0 +1,25 @@ +#ifndef MBED_PULSE_H +#define MBED_PULSE_H + +#include "mbed.h" + +class Pulse { +public: + Pulse(PinName pin); + + void send_pulse(int* sequence); + void set_osc(int hz); + void set_pin(PinName pin); + +private: + DigitalOut output_pin; + int oscilation; + bool switch_state; + Ticker flipper; + + void flip_pin(); + void change_state(); +}; + + +#endif