charlcd_i2c_mono_simpletest.py
1 """Simple test for 16x2 character lcd connected to an MCP23008 I2C LCD backpack.""" 2 import time 3 import board 4 import busio 5 import adafruit_character_lcd.character_lcd_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_I2C(i2c, lcd_columns, lcd_rows) 16 17 # Turn backlight on 18 lcd.backlight = True 19 # Print a two line message 20 lcd.message = "Hello\nCircuitPython" 21 # Wait 5s 22 time.sleep(5) 23 lcd.clear() 24 # Print two line message right to left 25 lcd.text_direction = lcd.RIGHT_TO_LEFT 26 lcd.message = "Hello\nCircuitPython" 27 # Wait 5s 28 time.sleep(5) 29 # Return text direction to left to right 30 lcd.text_direction = lcd.LEFT_TO_RIGHT 31 # Display cursor 32 lcd.clear() 33 lcd.cursor = True 34 lcd.message = "Cursor! " 35 # Wait 5s 36 time.sleep(5) 37 # Display blinking cursor 38 lcd.clear() 39 lcd.blink = True 40 lcd.message = "Blinky Cursor!" 41 # Wait 5s 42 time.sleep(5) 43 lcd.blink = False 44 lcd.clear() 45 # Create message to scroll 46 scroll_msg = "<-- Scroll" 47 lcd.message = scroll_msg 48 # Scroll message to the left 49 for i in range(len(scroll_msg)): 50 time.sleep(0.5) 51 lcd.move_left() 52 lcd.clear() 53 lcd.message = "Going to sleep\nCya later!" 54 time.sleep(5) 55 # Turn backlight off 56 lcd.backlight = False 57 time.sleep(2)