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