]> vault307.fbx.one Git - RPI-PICO-I2C-LCD.git/blob - main.py
3d09455e27ff3e6b050ff1e0737e5a3b61b07db7
[RPI-PICO-I2C-LCD.git] / main.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!\nSecond line!\nThird Line!\nFourth Line!")
17 utime.sleep(2)
18 lcd.clear()
19 count = 0
20 while True:
21 lcd.clear()
22 lcd.putstr("%7d" % (utime.time() // 1000))
23 if count % 10 == 0:
24 print("Turning cursor on")
25 lcd.show_cursor()
26 if count % 10 == 1:
27 print("Turning cursor off")
28 lcd.hide_cursor()
29 if count % 10 == 2:
30 print("Turning blink cursor on")
31 lcd.blink_cursor_on()
32 if count % 10 == 3:
33 print("Turning blink cursor off")
34 lcd.blink_cursor_off()
35 if count % 10 == 4:
36 print("Turning backlight off")
37 lcd.backlight_off()
38 if count % 10 == 5:
39 print("Turning backlight on")
40 lcd.backlight_on()
41 if count % 10 == 6:
42 print("Turning display off")
43 lcd.display_off()
44 if count % 10 == 7:
45 print("Turning display on")
46 lcd.display_on()
47 if count % 10 == 8:
48 print("Filling display")
49 lcd.clear()
50 string = ""
51 for x in range(32, 32+I2C_NUM_ROWS*I2C_NUM_COLS):
52 string += chr(x)
53 lcd.putstr(string)
54 count += 1
55 utime.sleep(2)
56
57 #if __name__ == "__main__":
58 test_main()