-
Notifications
You must be signed in to change notification settings - Fork 3
/
morse_audio_comm.py
62 lines (42 loc) · 1.11 KB
/
morse_audio_comm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import RPi.GPIO as GPIO
import time
import sys
from morse_code_trans import text2morse_trans
from morse_code_trans import print_morse
PIN = 13
UNIT_TIME = 0.01
def init():
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(PIN, GPIO.OUT)
def morse_dot():
GPIO.output(PIN, GPIO.HIGH)
time.sleep(UNIT_TIME)
def morse_dash():
GPIO.output(PIN, GPIO.HIGH)
time.sleep(UNIT_TIME*3)
def morse_char_gap():
GPIO.output(PIN, GPIO.LOW)
time.sleep(UNIT_TIME*3)
def morse_word_gap():
GPIO.output(PIN, GPIO.LOW)
time.sleep(UNIT_TIME*7)
text = "hey there" # input()
morse_code = text2morse_trans(text)
print(morse_code)
def transmit_morse(morse_code_list):
init()
for word in morse_code_list:
if word == " ":
morse_word_gap()
else:
for char in word:
if char == ".":
morse_dot()
morse_char_gap()
elif char == "-":
morse_dash()
morse_char_gap()
else:
continue
transmit_morse(morse_code)