lektion 02 erweitert
This commit is contained in:
1 parent
e07f1c2b92
commit
c60910e505
5 files changed
+309
-20
No files matched your search
@@ -0,0 +1,44 @@
|
||||
from gpiozero import LED
|
||||
from time import sleep
|
||||
|
||||
led = LED(17)
|
||||
|
||||
MORSE = {
|
||||
"A": ".-", "B": "-...", "C": "-.-.", "D": "-..", "E": ".",
|
||||
"F": "..-.", "G": "--.", "H": "....", "I": "..", "J": ".---",
|
||||
"K": "-.-", "L": ".-..", "M": "--", "N": "-.", "O": "---",
|
||||
"P": ".--.", "Q": "--.-", "R": ".-.", "S": "...", "T": "-",
|
||||
"U": "..-", "V": "...-", "W": ".--", "X": "-..-", "Y": "-.--", "Z": "--..",
|
||||
"0": "-----", "1": ".----", "2": "..---", "3": "...--", "4": "....-",
|
||||
"5": ".....", "6": "-....", "7": "--...", "8": "---..", "9": "----."
|
||||
}
|
||||
|
||||
|
||||
def morse_senden(text):
|
||||
for zeichen in text.upper():
|
||||
if zeichen == " ":
|
||||
sleep(1.4)
|
||||
continue
|
||||
|
||||
code = MORSE.get(zeichen)
|
||||
if code is None:
|
||||
print("Zeichen wird übersprungen:", zeichen)
|
||||
continue
|
||||
|
||||
print(zeichen, code)
|
||||
for signal in code:
|
||||
led.on()
|
||||
if signal == ".":
|
||||
sleep(0.2)
|
||||
else:
|
||||
sleep(0.6)
|
||||
led.off()
|
||||
sleep(0.2)
|
||||
sleep(0.4)
|
||||
|
||||
|
||||
try:
|
||||
morse_senden("SOS HALLO")
|
||||
finally:
|
||||
led.off()
|
||||
led.close()
|
||||
Reference in new issue
Block a user