我目前正在做一个学校项目,使用RasPi B+3和Adafruit 16x2带键盘的显示器
我用这些来显示两名球员的名字和分数,他们在空中曲棍球桌上打球。必须使用5个按钮(向上、向下、向右、向左、选择)输入姓名的用户。向上和向下控制字符:如果按下向上键,则将A更改为B,如果再次按下,则将B更改为C。如果按下向下键,则将C更改为B,如果再次按下,则将B更改为A。左右键用于控制要更改的角色的位置:如果按“左”键,则向左移动角色;如果按“右”键,则向右移动角色
我遇到的问题是,上述选项似乎都不起作用,LCD只有在代码启动时才会亮起,但LCD上不会出现任何字符
有人知道问题出在哪里吗
我在用Python3
这是我的代码:
import time
import Adafruit_CharLCD as LCD
# Initialize the LCD using the pins
lcd = LCD.Adafruit_CharLCDPlate()
button_1 = (LCD.SELECT, 'Select', (1,1,1))
button_2 = (LCD.LEFT, 'Left' , (1,0,0))
button_3 = (LCD.UP, 'Up' , (1,0,1))
button_4 = (LCD.DOWN, 'Down' , (1,1,0))
button_5 = (LCD.RIGHT, 'Right' , (1,0,1))
while cycle == true:
x = 65
y = 65
part = 1
while True:
#Part 1
#This part is for the name of player1
if part == 1:
if lcd.is_pressed(button_1):
part += 1
#To continue to part2
if lcd.is_pressed(button_3):
lcd.noblink
x += 1
cc=ord(x)
x_2 = cc
if x_2 > 90:
x_2 -= 25
#For moving from Z to A
lcd.message(char(x_2))
#moving the characters up 1 (A, B, C....)
if lcd.is_pressed(button_4):
lcd.noblink
x -= 1
cc=ord(x)
x_2 = cc
if x_2 < 65:
x_2 += 25
#For moving from A to Z
lcd.message(char(x_2))
#moving the characters down 1 Z, X, Y....)
if lcd.is_pressed(button_2):
remove(x_2)
lcd.move_left
x = 65
#moving the editable character to the left
if lcd.is_pressed(button_5):
append(x_2)
lcd.move_right
x = 65
#moving the editable character to the right
#Part 2
#This part is for the name of player2
if part == 2:
if lcd.is_pressed(button_1):
part += 1
#To continue to the next part (visualis the names)
if lcd.is_pressed(button_3):
lcd.noblink
y += 1
cc=ord(y)
y_2 = cc
if y_2 > 90:
y_2 -= 25
#For moving from Z to A
lcd.message(char(y_2))
#moving the characters up 1 (A, B, C....)
if lcd.is_pressed(button_4):
lcd.noblink
y -= 1
cc=ord(y)
y_2 = cc
if y_2 < 65:
y_2 += 25
#For moving from A to Z
lcd.message(char(y_2))
#moving the characters down 1 (Z, X, Y....)
if lcd.is_pressed(button_2):
remove(y_2)
lcd.move_left
y = 65
#moving the editable character to the left
if lcd.is_pressed(button_5):
append(y_2)
lcd.move_right
y = 65
#moving the editable character to the right
#Part 3
#This part is for displaying the first 7 Characters of the names (16/2=8 8-1=7 (this is for the spacing between the names) )
if part == 3:
# here must go the array to display the first and the second name
目前没有回答
相关问题 更多 >
编程相关推荐