forked from yorkhackspace/SpacehackClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCDTest.py
More file actions
59 lines (50 loc) · 1.68 KB
/
LCDTest.py
File metadata and controls
59 lines (50 loc) · 1.68 KB
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
# SpaceHack! Game client main module
#York Hackspace January 2014
#This runs on a Beaglebone Black
import Adafruit_BBIO.GPIO as GPIO
from Adafruit_CharLCD import Adafruit_CharLCD
#Three HD44780 LCDs - 20x4 instructions display and two 16x2 control labels
lcd = [Adafruit_CharLCD(), Adafruit_CharLCD(), Adafruit_CharLCD()]
lcdpins = ["P9_15", "P8_16", "P9_13"]
#Pretty print to the LCDs taking into account width
def display(message, width, screen):
words = message.split(" ")
line = ""
pos=0
lcd[screen].clear()
for word in words:
if len(line) + len(word) > width:
lcd[screen].setCursor(0, pos)
lcd[screen].message(line.rstrip() + '\n')
line = word + " "
pos += 1
else:
line += word + " "
lcd[screen].setCursor(0, pos)
lcd[screen].message(line.rstrip())
#Process an incoming config for a round
def processRoundConfig(roundconfigstring):
roundconfig = json.loads(roundconfigstring)
display(roundconfig['instructions'], 20, 0)
for ctrlid in controlids:
controlsetup = roundconfig[ctrlid]
lcdwrite(controlsetup['name'], ctrlid)
#there's more to setup of course
def displayBar(num):
lcd[0].setCursor(0,3)
lcd[0].message(chr(255)*num + ' '*(20-num))
#LCDs share a data bus but have different enable pins
for i in range(3):
lcd[i].pin_e = lcdpins[i]
GPIO.setup(lcdpins[i], GPIO.OUT)
GPIO.output(lcdpins[i], GPIO.LOW)
lcd[0].begin(20, 4)
display("Awaiting instructions!", 20, 0)
lcd[1].begin(16, 2)
display("Ready control 1!", 16, 1)
lcd[2].begin(16, 2)
display("Ready control 2!", 16, 2)
for i in range(21):
displayBar(i)
for i in range(21):
displayBar(20-i)