Encoding messsages, continuously written on serial terminal, in Morse code. Resulting code is played by a buzzer. Please, use local echo on terminal for more impressive experience. To verify coded messages, there are some app for smartphone.
Fork of Morse by
Diff: main.cpp
- Revision:
- 2:39d67345f7b3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Feb 03 11:45:23 2018 +0000 @@ -0,0 +1,50 @@ +#include "mbed.h" +#include "Morse.h" +#include "Speaker.h" +#include "FIFO.h" +// Global Variables +float SpeakerFreq = 2000; +float SpeakerVol = 1; +float DotLength = 0.1; // Duration of a dot. +float Speed = 1.2/DotLength; // Words per minute (1 word = 50 dots). + +int cnt_todo=0; +char* mdata; + +FIFO <char> message(1000); +Speaker buzzer(PB_6); + +char character_in, character_out; + +Serial pc(USBTX, USBRX); + +Thread thread_user_intf; + +void pc_intf() +{ + while(true) { + while(!pc.readable()) {}; + cnt_todo++; + character_in = pc.getc(); + message.put(character_in); + } +} + +int main() +{ + thread_user_intf.start(pc_intf); + while(true) { + if(cnt_todo>0) { + character_out = message.get(); + mdata = EncodeMorse(character_out); + for (int i=0; i<strlen(mdata); i++) { + if(mdata[i]!='0') + buzzer.PlayNote(SpeakerFreq,((mdata[i]-'0')/Speed),SpeakerVol); + else + Thread::wait(1000/Speed); + } + Thread::wait(3000/Speed); + cnt_todo--; + } + } +}