A Better Sample For The Netduino ShieldStudio 4-digit Shield
I took some time to improve the code sample for Netduino ShieldStudio tool.
By Den Delimarsky in Hackery
April 30, 2011
I recently started working with the Netduino microcontroller and one of the initial projects I decided to tackle was creating a better sample for a LED matrix shield. It wasn’t really complicated – overall, it took me around an hour to put everything together and test it on a real device.
Image lost since transition to new blog
Here are some things that I added to the updated sample:
- Automatically initialize the I2CDevice instance when the LEDMatrix class is instantiated.
- Perform the device setup automatically on class instantiation
- Ability to write a single character in one matrix slot with additional effects (ShortBlink or LongBlink)
- Ability to directly write a string instead of passing single characters
- Support of different ways a string can de displayed (MarqueeRight, MarqueeLeft, Blocks)
- Built-in references for some special characters (e.g. currency symbols, arrow up, arrow down)
- Support for writing inverted characters (inverted background/foreground)
That being said, a simple snippet that would allow the user to pass a string would look like this:
|
|
Special symbols are introduced simply to reduce the amount of work needed to look for special characters. A simple for loop from 0 to 255 will reveal most of the characters that cannot be introduced from the keyboard in a single tap, if needed. The characters I included in the SpecialCharacters enum are the most useful for me.
Image lost since transition to new blog
Special blinking effects for characters are taking place “one slot at a time” due to the single-threaded nature of the Netduino CPU. This can be modified with a Timer and preserved object state, but for now I needed sequential blinking so this does the job perfectly.
Inverted characters are calculated by adding 128 to the default character byte value (according to the ASCII table – decimal) for alphanumeric characters and some symbols. The inverted version for the characters represented in the image above would look like this:
Image lost since transition to new blog
This is more of a “just for fun” class, but it extends the default sample to show some basic capabilities out of the box. You can download the ZIP here.
Here is a video of the class in action:
Video lost since transition to new blog
Requirements:
- Microsoft Visual C# Express 2010
- .NET Micro Framework 4.1 (used as the solution target)
- Netduino (either basic or Plus – both work fine)
- SheildStudio 4-digit LED Matrix shield
Feedback
Have any thoughts? Let me know on Twitter!