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