Mercurial > templog
annotate py/lcd.py @ 598:d4fbfb5c46ff rust
broken update of versions of things
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 07 Feb 2017 21:56:58 +0800 |
parents | 542efb356e46 |
children |
rev | line source |
---|---|
150 | 1 #!/home/matt/templog/venv/bin/python |
2 | |
3 import smbus | |
4 import time | |
5 import random | |
6 import sys | |
7 | |
8 class LCD(object): | |
9 | |
10 COMMAND = 0x00 | |
11 DATA = 0x40 | |
12 | |
13 def __init__(self): | |
14 self.bus = smbus.SMBus(1) | |
15 #self.address = 0b0111110 | |
16 self.address = 0x3e | |
17 | |
18 def setup(self): | |
19 time.sleep(0.01) | |
20 cmds = """0x38 function set | |
21 0x39 function set | |
22 0x17 freq | |
23 0x78 # was 0x74 contrast, 101000 = 8 contrast (32 below), total 40 | |
24 0x57 # was 0x54 # power/icon/contrast, 0110 = bon, c5 | |
25 0x6a # was 0x6f follower , follow onr, rab 010 = 1.5 | |
26 0x0c on/off""" | |
27 for l in cmds.split('\n'): | |
28 c = eval(l.split()[0]) | |
29 self.cmd(c) | |
30 | |
31 # self.cmd(0x38) | |
32 # self.cmd(0x39) | |
33 # self.cmd(0x14) | |
34 # self.cmd(0x78) # contrast | |
35 # self.cmd(0x57) # power/icon/contrast | |
36 # self.cmd(0x6f) # follower | |
37 # self.cmd(0x0c) | |
38 # self.cmd(0x01) | |
39 # self.cmd(0x04) | |
40 | |
41 def put(self, pos, word): | |
42 addr = 0b10000000 + (pos % 16) + (pos>=16)*40 | |
43 self.cmd(addr) | |
44 for char in word: | |
45 self.data(ord(char)) | |
46 | |
47 def write(self, a, b): | |
48 self.bus.write_byte_data(self.address, a, b) | |
49 time.sleep(0.0001) | |
50 | |
51 def cmd(self, cmd): | |
52 self.write(self.COMMAND, cmd) | |
53 | |
54 def data(self, data): | |
55 self.write(self.DATA, data) | |
56 | |
57 l = LCD() | |
58 l.setup() | |
59 l.put(0, 'a') | |
60 l.put(1, 'b') | |
61 l.put(4, 'b') | |
62 | |
154
542efb356e46
back to random words on the lcd
Matt Johnston <matt@ucc.asn.au>
parents:
150
diff
changeset
|
63 words = [word.strip() for word in file('/usr/share/dict/words', 'r')] |
542efb356e46
back to random words on the lcd
Matt Johnston <matt@ucc.asn.au>
parents:
150
diff
changeset
|
64 random.shuffle(words) |
542efb356e46
back to random words on the lcd
Matt Johnston <matt@ucc.asn.au>
parents:
150
diff
changeset
|
65 #words = file(sys.argv[1], 'r').read().split() |
150 | 66 |
67 pos = 0 | |
68 last = '' | |
69 for word in words: | |
70 word = (word + ' '*16)[:16] | |
71 #pos = (pos + 16) % 32 | |
72 #word = random.sample(words, 1)[0][:16] + ' '*16 | |
73 #char = chr(int(random.random() * 26) + ord('a')) | |
74 l.put(0, last) | |
75 l.put(16, word) | |
76 last = word | |
154
542efb356e46
back to random words on the lcd
Matt Johnston <matt@ucc.asn.au>
parents:
150
diff
changeset
|
77 time.sleep(0.3) |