带有键盘的Adafruit 16x2显示器无法正常工作,无法接受RasPi B + 3上的按钮输入

时间:2018-11-08 12:34:50

标签: python python-3.x raspberry-pi3 adafruit

我目前正在从事一个学校项目,并使用带键盘的RasPi B + 3和Adafruit 16x2显示器。

我正在使用这些显示在冰球桌上打球的2位球员的姓名和得分。谁必须使用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

0 个答案:

没有答案