Example of how to use an Ada Fruit RGB LCD with the Ada Fruit RGB LCD Shield Library

Dependencies:   AdaFruit_RGBLCDShield MCP23017 mbed RTclock

Dependents:   SX1276_GPS

Fork of MCP_test by Wim Huiskamp

Updated the Adafruit RGB LCD Shield test app with a module system.

It pulls in RTclock which is another library I did for controlling the DS1307 RTC in a sane way (marries stdlib time and the RTC together cleanly). You don't need an RTC to run the example, it'll just use stdlib time instead. This class also maps RTC to system time, so if you loose the RTC the mbed will free run.

Four modules are defined in the modules folder plus the module base class. These examples provide:

  • title menu item
  • time menu item (updates automatically)
  • date menu item
  • fake temp menu item

Press select to switch modes: menu->cursor->change

Menu switches menu items going up/down. Cursor allows you to move around editable fields using the cursor keys / marker. Change allows you to move left/right on a particular line and change values by using up/down on an item with the blink box.

Custom fonts are defined for UI arrows and degree character.

If you want a menu item to update over time then you need to implement the canRefresh() member function in any child module you derive from class Module. Make it return true to receive update requests in your show() member function. Date and time both check when refreshing to see if anything has changed, then update.

main() registers a table of modules with the MenuManager. Others can be added easily by creating children derived from the Module base class..

Depending on what you want to do you may need to adjust the loop wait time in MenuManager::loop(). If you don't balance this based on work you need to do then the key presses may get a little lively. I may adjust the key checking to be fixed to 200ms regardless of loop wait time, however the catch there is that you'll consume more power the more loops you do so the wait is still important.

Happy coding!

Committer:
vtraveller
Date:
Thu Oct 09 10:21:03 2014 +0000
Revision:
27:b6c3dd9a1d8c
Parent:
26:0cfd95d8f270
Child:
28:fbcd3bac0cd7
Updated key detection for uneditable modules.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 0:88d87b1c1f8b 1 #include "mbed.h"
vtraveller 13:9641bc42db92 2
vtraveller 25:24654d08a99a 3 #include "lcdadafruit.h"
vtraveller 25:24654d08a99a 4 #include "lcd2004.h"
vtraveller 26:0cfd95d8f270 5 #include "keyreaderadafruit.h"
vtraveller 25:24654d08a99a 6 #include "keyreadernull.h"
vtraveller 10:3fcab08717fc 7 #include "RTclock.h"
vtraveller 10:3fcab08717fc 8
vtraveller 10:3fcab08717fc 9 #include "DateModule.h"
vtraveller 10:3fcab08717fc 10 #include "TempModule.h"
vtraveller 10:3fcab08717fc 11 #include "TimeModule.h"
vtraveller 10:3fcab08717fc 12 #include "TitleModule.h"
vtraveller 17:731a47339cb8 13 #include "SyncModule.h"
wim 0:88d87b1c1f8b 14
vtraveller 13:9641bc42db92 15 #include "MenuManager.h"
vtraveller 10:3fcab08717fc 16
vtraveller 13:9641bc42db92 17 //Serial cPC(SERIAL_TX, SERIAL_RX);
vtraveller 3:ed09f95739df 18
vtraveller 3:ed09f95739df 19 int main()
vtraveller 21:c44cfd3259c0 20 {
vtraveller 21:c44cfd3259c0 21 // Share the I2C across multiple devices
vtraveller 21:c44cfd3259c0 22 I2C cI2C(I2C_SDA, I2C_SCL); // D3, D6
vtraveller 21:c44cfd3259c0 23 cI2C.frequency(400000); // I2C can handle two different frequencies - switch to high speed if asked
vtraveller 25:24654d08a99a 24
vtraveller 27:b6c3dd9a1d8c 25 LCDadafruit cLCD(cI2C);
vtraveller 27:b6c3dd9a1d8c 26 //LCD2004 cLCD(cI2C);
vtraveller 26:0cfd95d8f270 27 //KeyReaderNull cKeys(cI2C);
vtraveller 26:0cfd95d8f270 28 KeyReaderAdafruit cKeys(cI2C);
vtraveller 20:93c70a1869ee 29
vtraveller 23:94d2f0d62247 30 RTclock cClock(cI2C, 0x68 << 1, RTclock::eDS3231);
vtraveller 13:9641bc42db92 31
vtraveller 13:9641bc42db92 32 // Spin up RTC
vtraveller 19:72c02acb601d 33 cClock.mapTime();
vtraveller 17:731a47339cb8 34
vtraveller 10:3fcab08717fc 35 // Set up display modules
vtraveller 10:3fcab08717fc 36 Module * aModules[] =
vtraveller 10:3fcab08717fc 37 {
vtraveller 25:24654d08a99a 38 new TitleModule(cLCD,cClock),
vtraveller 22:dd8197db4478 39 new TempModule(cLCD,cI2C,0x18 << 1),
vtraveller 17:731a47339cb8 40 new TimeModule(cLCD,cClock),
vtraveller 20:93c70a1869ee 41 new DateModule(cLCD,cClock),
vtraveller 19:72c02acb601d 42 new SyncModule(cLCD,cClock),
vtraveller 10:3fcab08717fc 43 };
vtraveller 10:3fcab08717fc 44
vtraveller 13:9641bc42db92 45 // Set up the menu manager
vtraveller 25:24654d08a99a 46 // MenuManager cMenuManager(aModules,_countof(aModules),cLCD,cKeys,16,2);
vtraveller 25:24654d08a99a 47 MenuManager cMenuManager(aModules,_countof(aModules),cLCD,cKeys);
vtraveller 13:9641bc42db92 48
vtraveller 13:9641bc42db92 49 // Start menu manager loop
vtraveller 13:9641bc42db92 50 cMenuManager.loop();
wim 0:88d87b1c1f8b 51 }