In the past couple of posts, I have documented how I built a LED Message board using some modules from Sure Electronics and then wrote a C program to scroll messages across it. This of course cool, but to really make it insteresting you need interesting messages to scroll. To get interesting messages you have to get connected. Since the Raspberry Pi is Unix based, you could easily start piping programs togther. I wanted someting a little more complicated though so I decided to write a Node JS program. In order to write to hardware devices like the Message Board you need to put together a Module and most of the time it will have to have some C++ code to do it, and that is a exactly what I did.
Node JS is an Ascrynous Programming langauge. This means that there is generally only one thing happening at a time and you wait for it to finish before doing the next. If you need to something that might take a long time, (Blocking in Comp Sci terms), you pass it a function to call when it is done and then go onto the next item.
The basic structure for the overall program is:
- Create an array of message you wish to display
- Create a function that is tied to the Scrolling Complete event from your Message Board, and will start scrolling the next message in the array. Also update the Array with any new messages.
- Start scrolling the First message.
Of course the whole point of doing this was to scroll interesting messages from the Internet. To get those “interesting messages”, I built a couple of tiny Node Module to pull NPR and ESPN Headlines.
So there you have it! A simple way to scroll messages off the Internet and impress (annoy) your co-workers.
Here is the code: