[Tutor] Alphabet lookup table
Alan Gauld
alan.gauld at yahoo.co.uk
Fri Jan 28 02:51:40 EST 2022
On 28/01/2022 05:35, Phil wrote:
> I have a 5 x 7 font lookup table class method that returns five hex
> values for a character. So far I've only created six entries and being
> basically lazy I'm wondering if something like this has already been
> created, failing that, is this the correct way to go about it anyway?
>
Assuming this is still part of your LED simulation then yes,
this is a fairly common approach. You might find it easier
to use binary rather than hex though. And I'd put the letter
definitions into a separate module - that way it's easy to
change "fonts" by renaming the files.
alpha_table = {
'P' : ['0b01111111',
'0b00001001',
'0b00001001',
'0b00001001',
'0b00000110'],
'H' : ['0b01111111',
'0b00000100',
'0b00000100',
'0b00000100',
'0b01111111'],
I : [ etc...
> An Internet search didn't reveal such a module.
>
> class Alphabet:
> def __init__(self):
> self.alpha_table = {'P': ['0x7f', '0x09', '0x09', '0x09', '0x06'],
> 'H': ['0x7f', '0x08', '0x08',
> '0x08', '0x7f'],
> 'I': ['0x00', '0x41', '0x7f',
> '0x41', '0x00'],
}
>
> def get_char(self, char):
> return self.alpha_table[char]
>
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list