Tipkalo pali LED-icu koja ispisuje S.O.S. u Morse-ovom codu
Dependents: MorseCODE-MarkoJuric
MorseWrite.cpp@0:40962a766bc2, 2021-05-07 (annotated)
- Committer:
- mjuric
- Date:
- Fri May 07 11:49:46 2021 +0000
- Revision:
- 0:40962a766bc2
Morse-code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mjuric | 0:40962a766bc2 | 1 | #include "MorseWrite.h" |
mjuric | 0:40962a766bc2 | 2 | #include "mbed.h" |
mjuric | 0:40962a766bc2 | 3 | |
mjuric | 0:40962a766bc2 | 4 | MorseWrite::MorseWrite(PinName pin) : _pin(pin){ |
mjuric | 0:40962a766bc2 | 5 | _pin = 0; |
mjuric | 0:40962a766bc2 | 6 | } |
mjuric | 0:40962a766bc2 | 7 | |
mjuric | 0:40962a766bc2 | 8 | void MorseWrite::write(int message, short n) { |
mjuric | 0:40962a766bc2 | 9 | for(int i=1; i<=n; i++) { |
mjuric | 0:40962a766bc2 | 10 | short symbol = message & 0b11; |
mjuric | 0:40962a766bc2 | 11 | message = message >> 2; |
mjuric | 0:40962a766bc2 | 12 | |
mjuric | 0:40962a766bc2 | 13 | switch(symbol){ |
mjuric | 0:40962a766bc2 | 14 | case 0b00: |
mjuric | 0:40962a766bc2 | 15 | _pin = 1; |
mjuric | 0:40962a766bc2 | 16 | wait(duration * dotDuration); |
mjuric | 0:40962a766bc2 | 17 | _pin = 0; |
mjuric | 0:40962a766bc2 | 18 | wait(duration); |
mjuric | 0:40962a766bc2 | 19 | break; |
mjuric | 0:40962a766bc2 | 20 | case 0b01: |
mjuric | 0:40962a766bc2 | 21 | _pin = 1; |
mjuric | 0:40962a766bc2 | 22 | wait(duration * dashDuration); |
mjuric | 0:40962a766bc2 | 23 | _pin = 0; |
mjuric | 0:40962a766bc2 | 24 | wait(duration); |
mjuric | 0:40962a766bc2 | 25 | break; |
mjuric | 0:40962a766bc2 | 26 | case 0b10: |
mjuric | 0:40962a766bc2 | 27 | _pin = 0; |
mjuric | 0:40962a766bc2 | 28 | wait(duration * newLetterDuration); |
mjuric | 0:40962a766bc2 | 29 | break; |
mjuric | 0:40962a766bc2 | 30 | case 0b11: |
mjuric | 0:40962a766bc2 | 31 | _pin = 0; |
mjuric | 0:40962a766bc2 | 32 | wait(duration * spaceDuration); |
mjuric | 0:40962a766bc2 | 33 | break; |
mjuric | 0:40962a766bc2 | 34 | } |
mjuric | 0:40962a766bc2 | 35 | } |
mjuric | 0:40962a766bc2 | 36 | } |