From 32e04b7d34b8bc54bb090f4687ab92990bc2faa7 Mon Sep 17 00:00:00 2001 From: James Bowman Date: Sun, 3 Mar 2019 16:59:43 -0800 Subject: [PATCH] Bi-Color (Red/Green) 24-Bar Bargraph --- python/ht16k33.py | 22 ---------------------- python/i2cdriver.py | 4 +--- python/{ => samples}/bargraph.py | 30 ++++++++++++++++-------------- python/samples/go | 3 +++ python/setup.py | 3 --- 5 files changed, 20 insertions(+), 42 deletions(-) delete mode 100644 python/ht16k33.py rename python/{ => samples}/bargraph.py (57%) create mode 100644 python/samples/go diff --git a/python/ht16k33.py b/python/ht16k33.py deleted file mode 100644 index f7382ac..0000000 --- a/python/ht16k33.py +++ /dev/null @@ -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() diff --git a/python/i2cdriver.py b/python/i2cdriver.py index f01449a..4bffc75 100644 --- a/python/i2cdriver.py +++ b/python/i2cdriver.py @@ -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 diff --git a/python/bargraph.py b/python/samples/bargraph.py similarity index 57% rename from python/bargraph.py rename to python/samples/bargraph.py index b913804..82634ce 100644 --- a/python/bargraph.py +++ b/python/samples/bargraph.py @@ -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) diff --git a/python/samples/go b/python/samples/go new file mode 100644 index 0000000..e4f77bf --- /dev/null +++ b/python/samples/go @@ -0,0 +1,3 @@ +python led8x8.py /dev/ttyUSB0 +# python EDS-take-a-ticket.py /dev/ttyUSB0 +# python i2cgui.py diff --git a/python/setup.py b/python/setup.py index fd863d2..c5bf492 100644 --- a/python/setup.py +++ b/python/setup.py @@ -19,9 +19,6 @@ setup(name='i2cdriver', install_requires=['pyserial'], py_modules = [ 'i2cdriver', - 'lm75b', 'EDS', - 'ht16k33', - 'bargraph', ], )