все!В настоящее время я работаю над проектом Морзе на моем Raspberry Pi 3, который интерпретирует текст, который пользователь вводит в светодиодный сигнал на макете.Перед началом я проверил схему с другим фрагментом кода, и он показал, что он работает нормально.Тем не менее, когда я пытался запустить код в моем проекте, он в основном игнорировал функцию, которая отображает сигнал.Есть код:
#!/usr/bin/env python
from __future__ import print_function
import RPi.GPIO as GPIO
import time
import os
# Source of Morse is https://morsecode.scphillips.com/morse2.html
# 'step' = 1 /signal on/off
# 'dit' = step /dot
# 'dash' = 3 * step /dash
# 'pause' = 3 * step /pause after letters
# 'space' = 7 * step /pause between words
#
#
# Average number of letters for English word is 4.79
# However, the most common range is [5,6]
LED = 11
none = None
morse = [
[' '], # ' ' 32
['-.-.--'], # !
['.-..-.'], # "
[none], # #
[none], # $
[none], # %
['.-...'], # &
['.----.'], # '
['-.--.'], # (
['-.--.-'], # )
[none], # *
['.-.-.'], # +
['--..--'], # ,
['-....-'], # -
['.-.-.-'], # .
['-..-.'], # /
['----'], # 0
['.---'], # 1
['..---'], # 2
['...--'], # 3
['....-'], # 4
['.....'], # 5
['-....'], # 6
['--...'], # 7
['---..'], # 8
['----.'], # 9
['---...'], # :
[none], # ;
[none], # <
[none], # >
['..--..'], # ?
['.--.-.'], # @
['.-'], # A 65
['-...'], # 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 setup():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(LED, GPIO.OUT)
GPIO.output(LED, GPIO.HIGH)
def destroy():
GPIO.output(LED, GPIO.HIGH)
GPIO.cleanup()
def outPut(letter):
row = ord(letter) - 32
if (row >= 0) and (row <= 58):
for symb in range(len(morse[row])):
print (letter)
if (morse[row][symb] == '.'):
GPIO.output(LED, GPIO.LOW)
time.sleep(dot)
GPIO.output(LED, GPIO.HIGH)
time.sleep(dot)
elif (morse[row][symb] == '-'):
GPIO.output(LED, GPIO.LOW)
time.sleep(3 * dot)
GPIO.output(LED, GPIO.HIGH)
time.sleep(dot)
elif (morse[row][symb] == ' '):
GPIO.output(LED, GPIO.HIGH)
time.sleep(7 * dot)
else:
break
def exe():
while True:
os.system('clear')
freq = 0.5
print ('Make a choise:\n')
print (' [1] - Translate text to Morse Code\n [2] - Change tempo\n [Ctrl + C] - Quit\n')
print ('\n(Default tempo is 120 BPM ~ 2 steps per second)\n')
choice = raw_input()
if (choice == '1'):
os.system('clear')
print ('Enter the string: ')
inp = raw_input()
inp = inp.upper()
for i in range(len(inp)):
outPut(inp[i]) #Bypassing there
elif (choice == '2'):
os.system('clear')
print ('Choose tempo.\n')
print (' [1] - Words per Minute\n [2] - Beats per minute\n [3] - Characters per minute\n [B] - Back\n')
print ('Your choice: ')
pref = True
userValue = raw_input()
while pref:
if (userValue == '1'):
print ('\nHow many words per minute you want?\n')
move = float(raw_input())
freq = 60 / (move * 20)
pref = False
elif (userValue == '2'):
print ('\nHow many beats per minute do you want?\n')
move = float(raw_input())
freq = ((move / 60) ** (-1))
pref = False
elif (userValue == '3'):
print ('\nHow many characters per minute do you want?\n')
move = float(raw_input())
freq = 60 / move
pref = False
elif (userValue == 'b') or (userValue == 'B'):
pref = False
else:
print('INCORRECT CHOISE! TRY AGAIN!')
time.sleep(3)
else:
print ('INCORRECT CHOISE! TRY AGAIN!')
time.sleep(3)
if __name__ == '__main__':
setup()
try:
exe()
except KeyboardInterrupt:
destroy()
Это обход функции outPut ().Может кто-нибудь сказать, что не так?