[Tutor] a list of tuples with varying lengths

Dennis Lee Bieber wlfraed at ix.netcom.com
Thu Jan 20 15:30:50 EST 2022


On Thu, 20 Jan 2022 17:28:00 +1100, Phil <phillor9 at gmail.com> declaimed the
following:


>I'm simulating an 8 x 8 Led matrix. The function that's not working 
>correctly is scrolling text and this is how I'm trying to get it going.
>
	Don't know if actual LED code may be of use (some of them incorporate
shift registers).

https://learn.adafruit.com/connecting-a-16x32-rgb-led-matrix-panel-to-a-raspberry-pi/overview

>The simple solution is to copy the letter slice to the led matrix and 
>then directly shift the displayed slice to the left one place before 
>adding the second slice but that's not how physical led displays work. 
>Data is written to the display but it cannot be read back.
>

	To my mind, the "simple solution" is similar to the linked Adafruit
article...

	PREBUILD the entire display string as a bitmap first. Then feed it to
the "simulated" display in a loop, wherein the end of each loop cycle
shifts the bitmap. Include enough empty columns to allow for blank screen
at start/end of the main loop.

	If each data item in the bitmap is one column (I'm not going to the
level of a physical "bitmap" image structure, just a list of column data)
in the display, scrolling is just a matter of each pass starting on a
different location (and use modulo to wrap at the end).

	Pseudo-code (I'm not going to take the time to actually build a working
version)

#build bitmap including initial blanks
# bitmap = [ 0x00, #8 times for blank display
#			0xnn, #as needed for text data ]
offset = 0
while True:	#obviously you'll want some way to interrupt/update
	for col in range(8):	#assume 8 column display
		writeDisplay(col, bitmap[(col+offset) % 8])
	offset += 1

OR, if writeDisplay() expects all 8x8 values

while True:
	writeDisplay(bitmap[offset % 8 : (offset + 8) % 8])
	offset += 1

	One exit could be offset > len(bitmap) so you could produce the next
bitmap string to display (hmmm, could be a point for threading -- one
thread gets the bitmap from a Queue and runs the above loop, and end of
bitmap it fetches next Queue bitmap. Main thread reads whatever source of
text and converts to bitmap lists). Reset offset to 0 on entry...


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/



More information about the Tutor mailing list