I have this source. I am testing it now and I have come to a stalemate so far with I/O.
I am receiving my Input only as Output on the console instead of my Input being a LED signifying the Input was an Event.
Here is the random source. Can you see where I am going incorrect here?
#!/usr/bin/python3
# Testing Motors Again
# Dictionary from https://www.cl.cam.ac.uk/ and ideas
import gpiod
from time import sleep
chip_path_one = "/dev/gpiochip3"
chip_path_two = "/dev/gpiochip2"
line_offset_one = 14
line_offset_two = 38
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.6)
gpio8.set_value(0)
sleep(0.2)
def text_to_morse(text):
morse_code = ''
for char in text.upper():
morse_code += CODE.get(char, '') + ' '
return morse_code.strip()
def morse_to_text(morse):
text = ''
morse_words = morse.split(' ') # Split by triple spaces for words
for word in morse_words:
morse_chars = word.split(' ')
for char in morse_chars:
for key, value in CODE.items():
if value == char:
text += key
break
text += ' '
return text.strip()
gpio8 = gpiod.find_line("GPIO14")
gpio8.request(consumer="BeagleY-AI", type=gpiod.LINE_REQ_DIR_OUT, default_val=0)
gpio7 = gpiod.find_line("GPIO4")
gpio7.request(consumer="BeagleY-AI", type=gpiod.LINE_REQ_DIR_IN, default_val=0)
try:
while True:
inp = input('What shall we send...?\n')
for letter in inp:
for symbol in CODE[letter.upper()]:
if symbol == '-':
dash()
elif symbol == '.':
dot()
else:
sleep(1)
sleep(1)
text = inp
morse = text_to_morse(text)
print(f"Text: {text}")
print(f"Morse: {morse}")
translated_text = morse_to_text(morse)
print(f"Translated: {translated_text}")
if gpio7.get_value() == True:
for letter in text:
for symbol in CODE[letter.upper()]:
print(f'Here: {text}')
sleep(1)
gpio8.set_value(1)
else:
gpio7.get_value() == False
gpio8.set_value(0)
except KeyboardInterrupt:
gpio8.set_value(0)
pass
print("Hey...done for now?\n")
So, if inp
equals my input, say FF
or gg
or whatever, the remorse.py file has a LED in the physical world that lights up in Morse Code but then just lights up once the input event has happened. Also, the switch once tapped already lights the LED at the end of the source that runs until I CTRL-C the script or it repeats in asking for input.
The first section of the source works. Morse Code works but my I/O is a bit off…
Seth