Programming Meggy Jr RGB
|
Last week we released an Arduino environment library for the Meggy Jr RGB. The code is an open source project here, and the downloadable package comes several example programs, ranging from very simple to moderately complex. (One of the examples is a new game called Froggy Jr, where you help your a little round green frog cross the street and then a river.)
Today, to make it all a bit more useful, we are releasing the Meggy Jr RGB Programing guide, which you can download Here (600 kB PDF file). |
Programming Meggy Jr RGB: How to Get Started
One of the demo programs included with the library, MeggyJr_MeggyBrite is a pixel art drawing program that shows off simple functions that make drawing pixels and making sounds surprisingly easy. These functions are documented in the programming guide. To go forward, try out the other demo programs too and look through their code. Start small, by modifying these programs to make them still work but do different things. Once you understand that basic process, you're good to go!
The function of the Meggy Jr Library is to provide a software interface to the Meggy Jr RGB hardware. One of the things that it does is to allocate a chunk of the AVR microcontroller's RAM to act as Display Memory, analogous to the video memory in a desktop computer system. The Display Memory is a sizeable array of data that fully describes the state of all 200 LEDs on the Meggy Jr RGB. The LED display is constantly redrawn at a rate of 150 times per second, fully reading out the contents of that Display Memory and using it to control the LEDs.
The Meggy Jr Library provides interface calls to directly set and read values in the Display Memory. While this can give you great control over the LEDs, it can also involve unwieldy data manipulation. In most cases the Meggy Jr Simplified Library is a much better place to start, so we will save discussion of the Display Memory for later.
The Meggy Jr Simplified Library (MJSL) is a set of macros and functions on top of the Meggy Jr Library that let you get started quickly without deep knowledge of the Display Memory or how the hardware works. It also removes the excess complexity that is normally associated with libraries in the Arduino environment, so you can just use the darned thing. And it really works well. (Note: the MJSL is *fully compatible* with the main library, since it is built on top of that. Any of the main library functions can be made to work here as well, however it is usually not necessary to do so.) Under the hood, the Meggy Jr Simplified Library uses the (full) Meggy Jr Library, with its Display Memory and internal functions, to constantly refresh the screen at 150 Hz. The Simplified Library also adds an additional memory array that makes drawing to the LED display more intuitive. Besides the Display Memory already mentioned, the MJSL uses a second off-screen drawing space called the "Game Slate," where we actually perform the drawing. (You don't have to use it for games, that's just the name of it.) The Game Slate is an 8x8 array of memory locations-- one for each pixel on the LED display-- and in each position we store the name of a pre-defined color that will be drawn in the corresponding pixel. Because the Game Slate is not part of the actual Display Memory, we can take our time drawing a new image without affecting what appears on the LED display. When we're finished drawing, we copy the Game Slate data to the Display Memory, looking up the color definitions in a look-up table. For complete documentation, please see the Meggy Jr RGB Programing guide, which you can download here as a 600 kB PDF file.
Quick Links
|






