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.

Dependencies:   FIFO

Fork of Morse by Romain Berrada

Committer:
marcoperciavalle
Date:
Sat Feb 03 11:45:23 2018 +0000
Revision:
2:39d67345f7b3
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.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcoperciavalle 2:39d67345f7b3 1 #include "mbed.h"
marcoperciavalle 2:39d67345f7b3 2 #include "Morse.h"
marcoperciavalle 2:39d67345f7b3 3 #include "Speaker.h"
marcoperciavalle 2:39d67345f7b3 4 #include "FIFO.h"
marcoperciavalle 2:39d67345f7b3 5 // Global Variables
marcoperciavalle 2:39d67345f7b3 6 float SpeakerFreq = 2000;
marcoperciavalle 2:39d67345f7b3 7 float SpeakerVol = 1;
marcoperciavalle 2:39d67345f7b3 8 float DotLength = 0.1; // Duration of a dot.
marcoperciavalle 2:39d67345f7b3 9 float Speed = 1.2/DotLength; // Words per minute (1 word = 50 dots).
marcoperciavalle 2:39d67345f7b3 10
marcoperciavalle 2:39d67345f7b3 11 int cnt_todo=0;
marcoperciavalle 2:39d67345f7b3 12 char* mdata;
marcoperciavalle 2:39d67345f7b3 13
marcoperciavalle 2:39d67345f7b3 14 FIFO <char> message(1000);
marcoperciavalle 2:39d67345f7b3 15 Speaker buzzer(PB_6);
marcoperciavalle 2:39d67345f7b3 16
marcoperciavalle 2:39d67345f7b3 17 char character_in, character_out;
marcoperciavalle 2:39d67345f7b3 18
marcoperciavalle 2:39d67345f7b3 19 Serial pc(USBTX, USBRX);
marcoperciavalle 2:39d67345f7b3 20
marcoperciavalle 2:39d67345f7b3 21 Thread thread_user_intf;
marcoperciavalle 2:39d67345f7b3 22
marcoperciavalle 2:39d67345f7b3 23 void pc_intf()
marcoperciavalle 2:39d67345f7b3 24 {
marcoperciavalle 2:39d67345f7b3 25 while(true) {
marcoperciavalle 2:39d67345f7b3 26 while(!pc.readable()) {};
marcoperciavalle 2:39d67345f7b3 27 cnt_todo++;
marcoperciavalle 2:39d67345f7b3 28 character_in = pc.getc();
marcoperciavalle 2:39d67345f7b3 29 message.put(character_in);
marcoperciavalle 2:39d67345f7b3 30 }
marcoperciavalle 2:39d67345f7b3 31 }
marcoperciavalle 2:39d67345f7b3 32
marcoperciavalle 2:39d67345f7b3 33 int main()
marcoperciavalle 2:39d67345f7b3 34 {
marcoperciavalle 2:39d67345f7b3 35 thread_user_intf.start(pc_intf);
marcoperciavalle 2:39d67345f7b3 36 while(true) {
marcoperciavalle 2:39d67345f7b3 37 if(cnt_todo>0) {
marcoperciavalle 2:39d67345f7b3 38 character_out = message.get();
marcoperciavalle 2:39d67345f7b3 39 mdata = EncodeMorse(character_out);
marcoperciavalle 2:39d67345f7b3 40 for (int i=0; i<strlen(mdata); i++) {
marcoperciavalle 2:39d67345f7b3 41 if(mdata[i]!='0')
marcoperciavalle 2:39d67345f7b3 42 buzzer.PlayNote(SpeakerFreq,((mdata[i]-'0')/Speed),SpeakerVol);
marcoperciavalle 2:39d67345f7b3 43 else
marcoperciavalle 2:39d67345f7b3 44 Thread::wait(1000/Speed);
marcoperciavalle 2:39d67345f7b3 45 }
marcoperciavalle 2:39d67345f7b3 46 Thread::wait(3000/Speed);
marcoperciavalle 2:39d67345f7b3 47 cnt_todo--;
marcoperciavalle 2:39d67345f7b3 48 }
marcoperciavalle 2:39d67345f7b3 49 }
marcoperciavalle 2:39d67345f7b3 50 }