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 // new class to play a note on Speaker based on PwmOut class
marcoperciavalle 2:39d67345f7b3 3 class Speaker
marcoperciavalle 2:39d67345f7b3 4 {
marcoperciavalle 2:39d67345f7b3 5 public:
marcoperciavalle 2:39d67345f7b3 6 Speaker(PinName pin) : _pin(pin) {
marcoperciavalle 2:39d67345f7b3 7 // _pin(pin) means pass pin to the Speaker Constructor
marcoperciavalle 2:39d67345f7b3 8 }
marcoperciavalle 2:39d67345f7b3 9
marcoperciavalle 2:39d67345f7b3 10 // class method to play a note based on PwmOut class
marcoperciavalle 2:39d67345f7b3 11 void PlayNote(float frequency, float duration, float volume) {
marcoperciavalle 2:39d67345f7b3 12 _pin.period(1.0/frequency); // higher number = more base
marcoperciavalle 2:39d67345f7b3 13 _pin = volume/2.0; // higher number = more weird treble
marcoperciavalle 2:39d67345f7b3 14 wait(duration);
marcoperciavalle 2:39d67345f7b3 15 _pin = 0.0;
marcoperciavalle 2:39d67345f7b3 16 }
marcoperciavalle 2:39d67345f7b3 17
marcoperciavalle 2:39d67345f7b3 18 private:
marcoperciavalle 2:39d67345f7b3 19 PwmOut _pin;
marcoperciavalle 2:39d67345f7b3 20 };