This is my first contribution. Please moderator, if I'm going about this the wrong way, let me know.
Here is interrupt driven code for controlling a 3461BS quad 7-seg display. (Google didn't find any)
I'm sure it can be converted to a class, but that's beyond my current capability. (I've tried to do it though)
Also, the Interrupt routine (def refreshdisp(time): ) lends itself to be done in Assembler. Routine is basically pseudo code. (Also beyond my current capability)
Any clever coder prepared to encapsulate the code? I'd love to learn how it's done.
It's rather heavy on pincount, but hey, someone else will want to do it. So, here it is:
pyboard via 3461BS mnenomic Driver Current drawn Note:
X1 120 ohm 11 seg-A Straight 13mA Resistors can be increased to 560 ohm
X2 120 ohm 7 seg-B Straight 13mA This will reduce current to 3mA/segment.
X3 120 ohm 4 seg-C Straight 13mA Forward voltage drop over segment is 1.6 V
X4 120 ohm 2 seg-D Straight 13mA Subtract this from your drive voltage to
X5 120 ohm 1 seg-E Straight 13mA calculate the drive current/resistance
X6 120 ohm 10 seg-F Straight 13mA
X7 120 ohm 5 seg-G Straight 13mA
X8 120 ohm 3 seg-dp Straight 13mA
X9 4k7 & BC557 12 DIG1 BC557 E->GND, B->4k7 , C->DIG1 Max current 104mA for all 8 segments on. (="8.")
X10 4k7 & BC557 9 DIG2 " " " C->DIG2 Only one digit will be on at a time.
X11 4k7 & BC557 8 DIG3 " " " C->DIG3 See note above to reduce max current
X12 4k7 & BC557 6 DIG4 " " " C->DIG4 to 24mA.
Code: Select all
#TiensZ. 4 x 7-seg display driver for pyboard. # Seed from: https://github.com/m01/sevensegment/blob/master/sevensegment.py from pyb import Pin import pyb import stm import machine # the mapping of numbers to segments needed for displaying that number numbers = [ 0xC0, #0 0xF9, #1 0xA4, #2 0xB0, #3 0x99, #4 0x92, #5 0x82, #6 0xF8, #7 0x00, #8 0x90, #9 0xFF, #space ] segmentpins = ['X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8'] digitpins = ['X9','X10','X11','X12'] segmentdrv = [0,0,0,0,0,0,0,0] digitdrv = [0,0,0,0] digitvalue = [0xFF,0xFF,0xFF,0xFF] INTindex =  #Shouldn't be 0 at first entry of INT routine. for s in range(8): # Init segment drivers segmentdrv[s] = Pin(segmentpins[s], Pin.OUT_PP) for s in range(4): # Init digit drivers digitdrv[s] = Pin(digitpins[s], Pin.OUT_PP) def showvalue(value): #value = string text string of 4 digits and dp No error checking here! # allowed is 0 to 9, decimal point, space. No dp in posn 0. #use this to change the displayed value. counter = 0 for s in value: setdp = False if s == '.': setdp = True counter -= 1 elif s == ' ': i = 10 else: i = int(s) digitvalue[counter] = numbers[i] if setdp: # digitvalue[counter] = (digitvalue[counter] - 0x80) counter += 1 def refreshdisp(time): #: The heart of 7-seg. Int routine to refresh display @ 300hz/4 digitdrv[INTindex].high() if INTindex == 0: INTindex = 3 else: INTindex -= 1 machine.mem16[stm.GPIOA + stm.GPIO_ODR] = digitvalue[INTindex] digitdrv[INTindex].low() #Initialise the Interrupt routine. refresh = pyb.Timer(4, freq=300) refresh.callback(refreshdisp) #start of Main while True: pyb.delay(1000) showvalue(' 2 .4') pyb.delay(1000) showvalue('356.7')