Tipkalo pali LED-icu koja ispisuje S.O.S. u Morse-ovom codu
Dependents: MorseCODE-MarkoJuric
Revision 0:40962a766bc2, committed 2021-05-07
- Comitter:
- mjuric
- Date:
- Fri May 07 11:49:46 2021 +0000
- Commit message:
- Morse-code
Changed in this revision
MorseWrite.cpp | Show annotated file Show diff for this revision Revisions of this file |
MorseWrite.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MorseWrite.cpp Fri May 07 11:49:46 2021 +0000 @@ -0,0 +1,36 @@ +#include "MorseWrite.h" +#include "mbed.h" + +MorseWrite::MorseWrite(PinName pin) : _pin(pin){ + _pin = 0; +} + +void MorseWrite::write(int message, short n) { + for(int i=1; i<=n; i++) { + short symbol = message & 0b11; + message = message >> 2; + + switch(symbol){ + case 0b00: + _pin = 1; + wait(duration * dotDuration); + _pin = 0; + wait(duration); + break; + case 0b01: + _pin = 1; + wait(duration * dashDuration); + _pin = 0; + wait(duration); + break; + case 0b10: + _pin = 0; + wait(duration * newLetterDuration); + break; + case 0b11: + _pin = 0; + wait(duration * spaceDuration); + break; + } + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MorseWrite.h Fri May 07 11:49:46 2021 +0000 @@ -0,0 +1,20 @@ +#ifndef MBED_MORSEWRITE_H +#define MBED_MORSEWRITE_H + +#include "mbed.h" + +class MorseWrite { +public: + MorseWrite(PinName pin); + void write(int message, short n); + +private: + DigitalOut _pin; + const short dotDuration = 1; + const short dashDuration = 3; + const short newLetterDuration = 3; + const short spaceDuration = 7; + const float duration = 0.3; +}; + +#endif \ No newline at end of file