As a reminder that not everything here at Jee Labs is about JeeNodes, here’s a clock for the Arduino (which keeps track of time, even when not plugged in):
This was built with an Arduino Duemilanove, a Plug Shield, an RTC Plug, and an LCD Plug piggy-backed onto a 2×16 character display.
Here’s the sketch:
But there could be some serious trouble ahead…
This code depends on an extended version of the LiquidCrystal library that comes with the Arduino IDE version 0017. Since I don’t want to modify that code, I had to use different names, so the PortsLCD.h/.cpp files use the following class names:
- LiquidCrystalBase – an abstract class containing all the generic LCD code from the original class
- LiquidCrystalPins – this is for use with plain pin connections, as before
- LiquidCrystalPort – this uses bit-banged I2C with one of 4 JeeNode ports
- LiquidCrystalI2C – this is for use with hardware I2C, using the Wire library
These names are slightly different from the previous ports-only version, btw.
So PortsLCD is a library which does everything the original did, and more. The flexibility is that you can write your sketches with this and then use any type of LCD you like with it, by just changing a single line of code. And if you’ve got a different hardware hookup, a new class can be added for it based on this same code, so that again your sketch only needs to change a single line of code to use it.
So far, so good. This is the benefit of object-oriented code and polymorphism.
But there is a price, due to the way the Arduino IDE does things: even if you don’t use the Wire library, you’ll need to include it in your sketch! For similar reasons, I’ve been forced to include the RF12 driver in all my demo sketches, even those that don’t use it. Leaving it out leads to build errors and prevents uploading.
This is not a C/C++ issue, the gcc compiler is actually quite smart about leaving out things which are never used. No – this complication is caused by the way in which the Arduino IDE tries to do some clever things to simplify naive use of libraries. I’ll go into this in another post – it is not a show stopper yet, but it may become one as I start combining more features and code, since memory on an ATmega is quite limited.
To put it bluntly: the way the Arduino IDE currently deals with libraries is a ticking time bomb…