-
Notifications
You must be signed in to change notification settings - Fork 2
/
LCDtest.py
executable file
·61 lines (54 loc) · 2.31 KB
/
LCDtest.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
from time import sleep
import copy
import atexit
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate
import convertAccentCharutf8
from GlyphSprites import Sprites
# Initialize the LCD plate. Should auto-detect correct I2C bus. If not,
# pass '0' for early 256 MB Model B boards or '1' for all later versions
lcd = Adafruit_CharLCDPlate()
atexit.register(lcd.stop)
lcd.backlight(True)
lcd.createChar(0, Sprites.horizontalLines)
# Clear display and show greeting, pause 1 sec
lcd.clear()
lcd.message("Adafruit RGB LCD\nPlate w/Keypad!\x00")
sleep(1)
# Cycle through backlight colors
col = (lcd.RED, lcd.YELLOW, lcd.GREEN, lcd.TEAL,
lcd.BLUE, lcd.VIOLET, lcd.WHITE, lcd.OFF)
for c in col:
lcd.ledRGB(c)
sleep(.5)
# Poll buttons, display message & set backlight accordingly
btn = ((lcd.LEFT, u'\x00Vin très rouge à boire dans le vignoble du chateau', lcd.RED, [Sprites.horizontalLines]),
(lcd.UP, u'\x00 Sita sings \x01\n\x00 the blues \x01', lcd.BLUE, [Sprites.musicalNote, Sprites.bellSymbol]),
(lcd.DOWN, u'\x00see fields\n\x00 of green', lcd.GREEN, [Sprites.bellSymbol]),
(lcd.RIGHT, u'Purple mountain\nmajesties\x00\x01\x02', lcd.VIOLET,
[Sprites.hourglassFull, Sprites.hourglassMid, Sprites.hourglassEmpty]),
(lcd.SELECT, u'', lcd.WHITE, []))
prev = -1
while True:
sleep(.1)
lcd.scrollDisplayLeft()
buttonState = lcd.buttons()
for b in btn:
if (buttonState & (1 << b[0])) != 0:
if b is not prev:
(convertedMessage, glyphList, charList) = convertAccentCharutf8.convertMsg(b[1].encode('cp1252'),
copy.deepcopy(b[3]), [], 8)
print(repr((convertedMessage, glyphList, charList)))
for (i, glyph) in enumerate(glyphList): # copy glyphs to the LCD memory (b[3] + accent chars)
lcd.createChar(i, glyph)
sleep(.5)
print(b[1])
lcd.clear()
lcd.message(convertedMessage)
lcd.ledRGB(b[2])
# sleep(2)
#lcd.clear()
#lcd.message('Displays special\n\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09|||||||')
prev = b
break