Morse code encoder library
Diff: morse.h
- Revision:
- 0:27c38e4d6e4e
- Child:
- 1:e377d081edea
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/morse.h Sun Jul 13 09:26:34 2014 +0000 @@ -0,0 +1,71 @@ +#ifndef MBED_MORSE_H +#define MBED_MORSE_H + +#include "mbed.h" + +/** class to generate Morse code tone and keying signal. + * sound with a buzzer, based on a PwmOut, + * keying signal base on a DigitalOut + * + * Example: + * @code + * // Morse sample + * #include "mbed.h" + * #include "morse.h" + * + * char* codes[] = { ".-", "-...", "-.-.", "-..", ".", + * "..-.", "--.", "....", "..", ".---", + * "-.-", ".-..", "--", "-.", "---", + * ".--.", "--.-", ".-.", "...", "-", + * "..-", "...-", ".--", "-..-", "-.--", "--..", " " + * }; + * + * Morse morse; + * //Morse morse(dp24, LED1); + * //Morse morse(dp24, LED1, 0.1, 800); + * + * int main() + * { + * int i; + * + * while(1) { + * for (i = 0; i < 27; i++) { + * morse.code(codes[i]); + * } + * } + * } + * @endcode + */ + +namespace mbed { +/* Class: Morse + * A class whitch uses pwm and digitalout to generate morse tone and signal. + */ +class Morse { + +private: + float cw_tick; + float freq; + DigitalOut _pin; + PwmOut _pwm; + + void beep (int k); + void space(int k); + +public: + + void setfreq(float f); + float getfreq(void); + void settick(float t); + float gettick(void); + + void code(char* code); + + Morse(void); + Morse(PinName pwm, PinName led); + Morse(PinName pwm, PinName led, float t); + Morse(PinName pwm, PinName led, float t, float f); + +}; // end of class definition Morse +} // end of namespace mbed +#endif