Bi-Color (Red/Green) 24-Bar Bargraph
This commit is contained in:
parent
2eac70d266
commit
32e04b7d34
|
@ -1,22 +0,0 @@
|
|||
class HT16K33:
|
||||
def __init__(self, i2, a = 0x70):
|
||||
self.i2 = i2
|
||||
self.a = a
|
||||
self.command(0x21) # Clock on
|
||||
self.command(0x81) # Display on
|
||||
self.bright(15)
|
||||
self.load([0] * 16)
|
||||
|
||||
def bright(self, n):
|
||||
assert 0 <= n < 16
|
||||
self.command(0xe0 + n)
|
||||
|
||||
def command(self, b):
|
||||
assert(self.i2.start(self.a, 0))
|
||||
assert(self.i2.write([b]))
|
||||
self.i2.stop()
|
||||
|
||||
def load(self, b128):
|
||||
self.i2.start(self.a, 0)
|
||||
self.i2.write([0] + b128)
|
||||
self.i2.stop()
|
|
@ -4,13 +4,11 @@ import time
|
|||
import struct
|
||||
from collections import OrderedDict
|
||||
|
||||
__version__ = '0.0.2'
|
||||
__version__ = '0.0.3'
|
||||
|
||||
PYTHON2 = (sys.version_info < (3, 0))
|
||||
|
||||
from lm75b import *
|
||||
import EDS
|
||||
import bargraph
|
||||
|
||||
class I2CTimeout(Exception):
|
||||
pass
|
||||
|
|
|
@ -1,24 +1,17 @@
|
|||
"""
|
||||
Example for Bi-Color (Red/Green) 24-Bar Bargraph, based on HT16K33.
|
||||
Available from Adafruit.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import serial
|
||||
import time
|
||||
import struct
|
||||
import random
|
||||
|
||||
from i2cdriver import I2CDriver
|
||||
|
||||
from ht16k33 import HT16K33
|
||||
|
||||
class bargraph(HT16K33):
|
||||
def image(self, bb):
|
||||
def swiz(b):
|
||||
bs = [str((b >> n) & 1) for n in range(8)]
|
||||
return int(bs[7] + bs[0] + bs[1] + bs[2] + bs[3] + bs[4] + bs[5] + bs[6], 2)
|
||||
bb = [swiz(b) for b in bb]
|
||||
self.load([b for s in zip(bb,bb) for b in s])
|
||||
|
||||
def char(self, c):
|
||||
n = ord(c)
|
||||
ch = font[n * 8:n * 8 + 8]
|
||||
self.image(ch)
|
||||
|
||||
def set(self, pix):
|
||||
rr = pix
|
||||
def paint(r, i):
|
||||
|
@ -33,3 +26,12 @@ class bargraph(HT16K33):
|
|||
[paint(red, i) for i in range(24) if (pix[i] & 1)]
|
||||
[paint(grn, i) for i in range(24) if (pix[i] & 2)]
|
||||
self.load([red[0], grn[0], red[1], grn[1], red[2], grn[2]])
|
||||
|
||||
if __name__ == '__main__':
|
||||
i2 = I2CDriver(sys.argv[1])
|
||||
|
||||
d0 = bargraph(i2)
|
||||
|
||||
for i in range(60):
|
||||
d0.set([random.choice((0,1,2,3)) for i in range(24)])
|
||||
time.sleep(.08)
|
|
@ -0,0 +1,3 @@
|
|||
python led8x8.py /dev/ttyUSB0
|
||||
# python EDS-take-a-ticket.py /dev/ttyUSB0
|
||||
# python i2cgui.py
|
|
@ -19,9 +19,6 @@ setup(name='i2cdriver',
|
|||
install_requires=['pyserial'],
|
||||
py_modules = [
|
||||
'i2cdriver',
|
||||
'lm75b',
|
||||
'EDS',
|
||||
'ht16k33',
|
||||
'bargraph',
|
||||
],
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue