All is back up and working…
Also, if anyone gets around to enjoying coding source for morse code…
#!/usr/bin/python3
# Testing Motors Again
import gpiod
from time import sleep
CODE = {' ': ' ',
"'": '.----.',
'(': '-.--.-',
')': '-.--.-',
',': '--..--',
'-': '-....-',
'.': '.-.-.-',
'/': '-..-.',
'0': '-----',
'1': '.----',
'2': '..---',
'3': '...--',
'4': '....-',
'5': '.....',
'6': '-....',
'7': '--...',
'8': '---..',
'9': '----.',
':': '---...',
';': '-.-.-.',
'?': '..--..',
'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': '--..',
'_': '..--.-'}
def dot():
gpio8.set_value(1)
sleep(0.2)
gpio8.set_value(0)
sleep(0.2)
def dash():
gpio8.set_value(1)
sleep(0.5)
gpio8.set_value(0)
sleep(0.2)
#while True:
# input = raw_input('What would you like to send? ')
# for letter in input:
# for symbol in CODE[letter.upper()]:
# if symbol == '-':
# dash()
# elif symbol == '.':
# dot()
# else:
# time.sleep(0.5)
# time.sleep(0.5)
gpio8 = gpiod.find_line("GPIO14")
gpio8.request(consumer="Beagsss", type=gpiod.LINE_REQ_DIR_OUT, default_val=0)
try:
while True:
input = input('What shall we send...?')
for letter in input:
for symbol in CODE[letter.upper()]:
if symbol == '-':
dash()
elif symbol == '.':
dot()
else:
sleep(0.5)
sleep(0.5)
except KeyboardInterrupt:
gpio8.set_value(0)
pass
print("Hey...done for now?")
I have found that source from this site, https://www.cl.cam.ac.uk/ , with their RPi code, switching to Python3 and gpiod.h use cases is as easy as one would think…
Seth
P.S. Enjoy. It works but it errors out. Do you know why this code errors out when you type .
or -
?
The commented out Python2 code is the original from the link given and so is the dictionary in Python2/3.