Last night, for Hallowe’en, I made some simple animations on the PiLite and put it in our window to attract trick-or-treaters.
I’ve done some work on the PiLite before, including an implementation of Tetris and a python library to make it simpler to program.
My PiLite python library already contains a function called set_fb() which allows the full matrix of LEDs to be set in one command, by sending a string of 126 ‘1’s and ‘0’s, which are then translated on to the LED matrix as LEDs being ON and OFF respectively.
There are a few problems with this function, which make it hard to visualise what will appear on the LEDs:
- it requires input in one long string
- the string works down each column of the matrix in turn, rather than across each row
- ‘1’ and ‘0’ aren’t obviously different enough to allow quick visualisation
For this reason, I’ve added a new function, set_fb_pic(), which still takes a string which is translated to the full LED matrix, but now, to address the issues above:
- it strips all whitespace from the string, so if you like you can use a multi-line string and/or leave a space between each “pixel”
- the string now works across each row in turn, like a normal string
- ‘*’ and ‘.’ can now be used in the string in place of ‘1’ and ‘0’ to allow simpler visualisation
So whereas, in my original test.py code, the code to display a “PacMan” type sprite was:
p.set_fb("000000000000000000000111000011111110011111110111111111111101111111101111011000110011000110000000000000000000000000000000000000")
The code to display a pumpkin in halloween.py using the new function is the more obvious:
p.set_fb_pic(""" ....*******... ...*********.. ..**..***..**. ..***********. ..***********. ..**.......**. ..**.*.*.*.**. ...*********.. ....*******... """)
Well, I think it’s more obvious anyway!
I also wanted to produce a bit of a lightning effect, to just flash random pixels, so I also added
set_fb_random()
which sets the full LED array randomly.
As usual, the code is all available on github.
Got any pics of the matrix lit up?
No, sadly, I didn’t take any, we were too busy answering the door!
i will probly try to do somthing like this ps me from coderdojo ryan