From f4c47931434fa8a884204b41b49ffb95ea316ca4 Mon Sep 17 00:00:00 2001 From: Davide N Date: Wed, 22 Jan 2025 10:27:36 +0100 Subject: [PATCH 1/2] first morse project --- projects/01-morse-tx/main.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 projects/01-morse-tx/main.py diff --git a/projects/01-morse-tx/main.py b/projects/01-morse-tx/main.py new file mode 100644 index 0000000..6cf0a79 --- /dev/null +++ b/projects/01-morse-tx/main.py @@ -0,0 +1,33 @@ +import sys +from time import sleep_ms + +from modulino import ModulinoBuzzer + +buzzer = ModulinoBuzzer() + +pause = 200 # pause in millisecond +dotDuration = 50 +lineDuration = 200 + +while True: + print("Insert the message:") + data = sys.stdin.readline() + for l in data: + print(l) + if l == " ": + sleep_ms(7 * pause) + else: + if l == "s": + buzzer.tone(440, dotDuration, True) + sleep_ms(pause) + buzzer.tone(440, dotDuration, True) + sleep_ms(pause) + buzzer.tone(440, dotDuration, True) + sleep_ms(pause) + elif l == "o": + buzzer.tone(440, lineDuration, True) + sleep_ms(pause) + buzzer.tone(440, lineDuration, True) + sleep_ms(pause) + buzzer.tone(440, lineDuration, True) + sleep_ms(2 * pause) From 90a0576f27f97017f0481dbaab5e29cd31d6ffe6 Mon Sep 17 00:00:00 2001 From: Davide N Date: Fri, 31 Jan 2025 11:32:34 +0100 Subject: [PATCH 2/2] change morse pause --- projects/01-morse-tx/main.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/projects/01-morse-tx/main.py b/projects/01-morse-tx/main.py index 6cf0a79..92a9659 100644 --- a/projects/01-morse-tx/main.py +++ b/projects/01-morse-tx/main.py @@ -5,9 +5,16 @@ buzzer = ModulinoBuzzer() -pause = 200 # pause in millisecond -dotDuration = 50 -lineDuration = 200 + +duration = 200 # duration in millisecond + +dit = duration +dah = 3 * duration + +pause = duration +letterPause = 2 * duration +wordPause = 6 * duration # in total 7 duration + while True: print("Insert the message:") @@ -15,19 +22,20 @@ for l in data: print(l) if l == " ": - sleep_ms(7 * pause) + sleep_ms(wordPause) else: if l == "s": - buzzer.tone(440, dotDuration, True) + buzzer.tone(440, dit, True) sleep_ms(pause) - buzzer.tone(440, dotDuration, True) + buzzer.tone(440, dit, True) sleep_ms(pause) - buzzer.tone(440, dotDuration, True) + buzzer.tone(440, dit, True) sleep_ms(pause) elif l == "o": - buzzer.tone(440, lineDuration, True) + buzzer.tone(440, dah, True) + sleep_ms(pause) + buzzer.tone(440, dah, True) sleep_ms(pause) - buzzer.tone(440, lineDuration, True) + buzzer.tone(440, dah, True) sleep_ms(pause) - buzzer.tone(440, lineDuration, True) - sleep_ms(2 * pause) + sleep_ms(letterPause)