/ examples / charlcd_keypad_simpletest.py
charlcd_keypad_simpletest.py
 1  """Simple test for keypad on I2C RGB character LCD Shield or Pi Plate kits"""
 2  import time
 3  import board
 4  import busio
 5  import adafruit_character_lcd.character_lcd_rgb_i2c as character_lcd
 6  
 7  # Modify this if you have a different sized Character LCD
 8  lcd_columns = 16
 9  lcd_rows = 2
10  
11  # Initialise I2C bus.
12  i2c = busio.I2C(board.SCL, board.SDA)
13  
14  # Initialise the LCD class
15  lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)
16  
17  lcd.clear()
18  lcd.color = [100, 0, 0]
19  while True:
20      if lcd.left_button:
21          print("Left!")
22          lcd.message = "Left!"
23  
24      elif lcd.up_button:
25          print("Up!")
26          lcd.message = "Up!"
27  
28      elif lcd.down_button:
29          print("Down!")
30          lcd.message = "Down!"
31  
32      elif lcd.right_button:
33          print("Right!")
34          lcd.message = "Right!"
35  
36      elif lcd.select_button:
37          print("Select!")
38          lcd.message = "Select!"
39  
40      else:
41          time.sleep(0.1)
42          lcd.clear()