[Tutor] a list of tuples with varying lengths

Phil phillor9 at gmail.com
Thu Jan 20 01:28:00 EST 2022


On 19/1/22 20:10, Peter Otten wrote:
> Thank you Roel and Peter,

I think the main problem was that I needed a break to give myself a 
chance to think more clearly.

My stubborn use of "for i in range(len(x))" instead of "for i in x" has 
once again led me down the wrong path.

This is the key to the solution:

for row in table:
     for s, d in row:

> By the way, the table you give doesn't look like a "lookup table" which
> is typically used to provide a "key" (the list index in your case) and
> return a "value" (here a complete row). But you seem to want the
> individual tuples, and all of them.
I stand corrected again and extracting the individual tuples was the 
crux of the problem. I use lookup tables frequently. A second lookup 
table in this project uses a letter of the alphabet to return the 
letter's hex values.
>
> Perhaps you'd like to explain the problem you are trying solve?
> Some of us might be willing clear things up a bit for you ;)

OK, it's quite likely that there's a far better plan of attack to solve 
this problem.

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.

I'm using a 5 x 7 font and the letter, for example, 'P' is stored like this:

self.letter_table = ["0x7f", "0x09", "0x09", "0x09", "0x06"]

A function converts this to a byte list, so 'P' now looks like this:

[
   1111000,
   1000100,
   1000100,
   1111000,
   1000000,
   1000000,
   1000000
]

Now this is where the 's' and 'd' comes in, 's' is the source (byte 
list) and 'd' is the destination (the led matrix).

So the first column of the byte list is stored on the last column (the 
right hand side) of the led matrix during the first time interval. 
During the second time interval, the same column of the byte list is 
stored on the second last column of the led matrix and the second column 
of the byte table is stored on the last column of the led matrix. This 
continues until the entire letter is displayed on the led matrix. Each 
slice of the letter is shifted across the led matrix in 5 time intervals.

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.

What I'm trying to create, in effect, is a led matrix driver and the 
only function, so far, that doesn't work correctly is scrolling text.

I can see that my solution would only work for one 8 x 8 display and the 
complicated source destination table would become even more complex if I 
added more displays.

Another thought that I experimented with was to create a virtual window 
of leds that I could move across the byte list but that became even more 
complex.

Any thoughts on a less convoluted solution are most welcome.

-- 

Regards,
Phil



More information about the Tutor mailing list