]> vault307.fbx.one Git - RPI-PICO-I2C-LCD.git/blob - pico_i2c_lcd_test.py
db05b81ef3af076b4f3905813e8a5a6ff7615ec0
[RPI-PICO-I2C-LCD.git] / pico_i2c_lcd_test.py
1 import utime
2
3 from machine import I2C
4 from lcd_api import LcdApi
5 from pico_i2c_lcd import I2cLcd
6
7 I2C_ADDR = 0x27
8 I2C_NUM_ROWS = 4
9 I2C_NUM_COLS = 20
10
11 def test_main():
12 #Test function for verifying basic functionality
13 print("Running test_main")
14 i2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000)
15 lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
16 lcd.putstr("It Works!")
17 utime.sleep(2)
18 lcd.clear()
19 count = 0
20 while True:
21 lcd.clear()
22 time = utime.localtime()
23 lcd.putstr("{year}/{month}/{day} {HH}:{MM}:{SS}".format(
24 year=str(time[0]), month=str(time[1]), day=str(time[2]),
25 HH=str(time[3]), MM=str(time[4]), SS=str(time[5])))
26 if count % 10 == 0:
27 print("Turning cursor on")
28 lcd.show_cursor()
29 if count % 10 == 1:
30 print("Turning cursor off")
31 lcd.hide_cursor()
32 if count % 10 == 2:
33 print("Turning blink cursor on")
34 lcd.blink_cursor_on()
35 if count % 10 == 3:
36 print("Turning blink cursor off")
37 lcd.blink_cursor_off()
38 if count % 10 == 4:
39 print("Turning backlight off")
40 lcd.backlight_off()
41 if count % 10 == 5:
42 print("Turning backlight on")
43 lcd.backlight_on()
44 if count % 10 == 6:
45 print("Turning display off")
46 lcd.display_off()
47 if count % 10 == 7:
48 print("Turning display on")
49 lcd.display_on()
50 if count % 10 == 8:
51 print("Filling display")
52 lcd.clear()
53 string = ""
54 for x in range(32, 32+I2C_NUM_ROWS*I2C_NUM_COLS):
55 string += chr(x)
56 lcd.putstr(string)
57 count += 1
58 utime.sleep(2)
59
60 #if __name__ == "__main__":
61 test_main()