A month ago, I asked this one about multiplexing a string of numbers with 4 7-segment displays. But now I'm trying to update the code to multiplex a string of letters using 7 7-segment displays in python.
This is a new scheme. When I send data using the parallel port, Latch Enable receives the most significant bit (pin 9). In the second latch, Latch Enable accepts it as well, but denies it, which is why 7404.
This is either the address set (/ LE == False) or the data set (/ LE = True).
This is what I am trying to do. βXβ means the 7-segment display is off. But he cannot archive it.
XXXXXXX
XXXXXXS
XXXXXST
XXXXSTA
XXXSTAC
XXSTACK
XSTACKX
STACKX0
TACKX0V
ACKX0V3
CKX0V3R
KX0V3RF
X0VERFL
0VERFL0
VERFL0W
ERFL0WX
RFL0WXX
FL0WXXX
L0WXXXX
0WXXXXX
WXXXXXX
XXXXXXX
This will be the output for the string "STACK 0V3RFL0W".
:
import sys
import parallel
class Display(object):
def __init__(self):
'''Init and blank the "display".'''
self.display = [' '] * 4
self._update()
def setData(self,data):
'''Bits 0-3 are the "value".
Bits 4-7 are positions 0-3 (first-to-last).
'''
self.display = [' '] * 4
value = data & 0xF
if data & 0x10:
self.display[0] = str(value)
if data & 0x20:
self.display[1] = str(value)
if data & 0x40:
self.display[2] = str(value)
if data & 0x80:
self.display[3] = str(value)
self._update()
def _update(self):
'''Write over the same four terminal positions each time.'''
sys.stdout.write(''.join(self.display) + '\r')
if __name__ == '__main__':
p = Display()
pp=parallel.Parallel()
nums = raw_input("Enter a string of numbers: ")
stream = 'XXXX' + nums + 'XXXX'
data = [0] * 4
for i in range(len(stream)-3):
for pos in range(4):
value = stream[i+pos]
data[pos] = 0 if value == 'X' else (1<<(pos+4)) + int(value)
for delay in xrange(1000):
for d in data:
pp.setData(d)
p.setData(0)