]> vault307.fbx.one Git - lcdTracker.git/blob - groveLCD.py
token board using LCD
[lcdTracker.git] / groveLCD.py
1 import machine, time
2
3 i2c=machine.I2C(0)
4
5
6 # this device has two I2C addresses
7 DISPLAY_RGB_ADDR = 0x62
8 DISPLAY_TEXT_ADDR = 0x3e
9
10 RGB_REG0=0x00
11 RGB_REG1=0x01
12 RGB_REG5=0x08
13 RGB_REGR=0x04
14 RGB_REGG=0x03
15 RGB_REGB=0x02
16
17 i2c=machine.I2C(0)
18
19 def reg_write(i2c,addr,reg,data):
20 msg=bytearray()
21 msg.append(data)
22 i2c.writeto_mem(addr,reg,msg)
23
24 # set backlight to (R,G,B) (values from 0..255 for each)
25 def setRGB(r,g,b):
26 reg_write(i2c,DISPLAY_RGB_ADDR,RGB_REG0,0)
27 reg_write(i2c,DISPLAY_RGB_ADDR,RGB_REG1,0)
28 reg_write(i2c,DISPLAY_RGB_ADDR,RGB_REG5,0xaa)
29 reg_write(i2c,DISPLAY_RGB_ADDR,RGB_REGR,r)
30 reg_write(i2c,DISPLAY_RGB_ADDR,RGB_REGG,g)
31 reg_write(i2c,DISPLAY_RGB_ADDR,RGB_REGB,b)
32
33 def textCommand(cmd):
34 reg_write(i2c,DISPLAY_TEXT_ADDR,0x80,cmd)
35
36 def setText(text):
37 textCommand(0x01)
38 time.sleep(.05)
39 textCommand(0x08 | 0x04)
40 textCommand(0x28)
41 time.sleep(.05)
42 count=0
43 row=0
44 for c in text:
45 if c == '\n' or count == 16:
46 count=0
47 row+=1
48 if row ==2:
49 break
50 textCommand(0xc0)
51 if c == '\n':
52 continue
53 count +=1
54 reg_write(i2c,DISPLAY_TEXT_ADDR,0x40,ord(c))
55
56 def setText_norefresh(text):
57 textCommand(0x02) # return home
58 time.sleep(.05)
59 textCommand(0x08 | 0x04) # display on, no cursor
60 textCommand(0x28) # 2 lines
61 time.sleep(.05)
62 count = 0
63 row = 0
64 while len(text) < 32: #clears the rest of the screen
65 text += ' '
66 for c in text:
67 if c == '\n' or count == 16:
68 count = 0
69 row += 1
70 if row == 2:
71 break
72 textCommand(0xc0)
73 if c == '\n':
74 continue
75 count += 1
76 reg_write(i2c,DISPLAY_TEXT_ADDR,0x40,ord(c))
77
78 def clearText():
79 textCommand(0x01)