The Library¶
Published on 2017-08-06 in PewPew FeatherWing.
Today I finished the CircuitPython library for the PewPew Lite. It still has some room for improvement, especially in terms of memory use, but it already has the shape that I’m basically happy about.
I had to completely rewrite it from my initial code, since I want it to be a little bit higher level than it was initially. Apart from_init_, which is used for setup at the beginning, there are only four functions:
brightness sets the brightness of the LED matrix, so that you can do fade-ins and outs,
keys queries for keys that have been pressed since the last call (with de- bouncing),
tick waits until a specified time has passed from the last call, and
_show _that displays an image on the matrix.
Then there is a class for representing the images in memory, which have five methods:
from_lines creates an image from data you are providing,
from_text creates an image with your text rendered on it,
pixel that gets or sets the color of a single pixel,
box which draws a filled rectangle, and
blit for copying one image onto another.
That’s it. The whole library has about 200 lines of code (including the font data), but lets you conveniently do things such as scrolling, displaying text, displaying animations, showing maps, moving around sprites, etc.
For testing, I’m writing all this code on a Feather M0 Basic, which is the smallest and slowest device that runs CircuitPython — to make sure that the speed is acceptable for it, and that everything fits in the memory.
Here is a simple scrolling menu written using all this, which I plan to use for selecting the games at the beginning: