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:
Sat Aug 30 16:30:27 2014 +0000
Revision:
20:93c70a1869ee
Parent:
19:72c02acb601d
Child:
21:c44cfd3259c0
Updated with temp sensor support.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 0:88d87b1c1f8b 1 #include "mbed.h"
vtraveller 13:9641bc42db92 2
vtraveller 4:d70e37f6c6bd 3 #include "Adafruit_RGBLCDShield.h"
vtraveller 10:3fcab08717fc 4 #include "RTclock.h"
vtraveller 10:3fcab08717fc 5
vtraveller 10:3fcab08717fc 6 #include "DateModule.h"
vtraveller 10:3fcab08717fc 7 #include "TempModule.h"
vtraveller 10:3fcab08717fc 8 #include "TimeModule.h"
vtraveller 10:3fcab08717fc 9 #include "TitleModule.h"
vtraveller 17:731a47339cb8 10 #include "SyncModule.h"
wim 0:88d87b1c1f8b 11
vtraveller 13:9641bc42db92 12 #include "MenuManager.h"
vtraveller 10:3fcab08717fc 13
vtraveller 13:9641bc42db92 14 //Serial cPC(SERIAL_TX, SERIAL_RX);
vtraveller 3:ed09f95739df 15
vtraveller 3:ed09f95739df 16 int main()
vtraveller 13:9641bc42db92 17 {
vtraveller 13:9641bc42db92 18 MCP23017 cMCP23017 = MCP23017(I2C_SDA, I2C_SCL, 0x40, true);
vtraveller 20:93c70a1869ee 19 //MCP23017 cMCP23017 = MCP23017(I2C_SDA, I2C_SCL, 0x4E, true);
vtraveller 17:731a47339cb8 20
vtraveller 20:93c70a1869ee 21 Adafruit_RGBLCDShield cLCD(cMCP23017);
vtraveller 20:93c70a1869ee 22 //Adafruit_RGBLCDShield cLCD(cMCP23017,1<<0,1<<1, 1<< 2, 1<<4, 1<<5, 1<<6, 1<<7);
vtraveller 20:93c70a1869ee 23
vtraveller 20:93c70a1869ee 24 RTclock cClock(I2C_SDA, I2C_SCL, RTclock::eDS3231);
vtraveller 19:72c02acb601d 25 //RTclock cClock(D3, D6);
vtraveller 13:9641bc42db92 26
vtraveller 13:9641bc42db92 27 // Spin up RTC
vtraveller 19:72c02acb601d 28 cClock.mapTime();
vtraveller 17:731a47339cb8 29
vtraveller 10:3fcab08717fc 30 // Set up display modules
vtraveller 10:3fcab08717fc 31 Module * aModules[] =
vtraveller 10:3fcab08717fc 32 {
vtraveller 20:93c70a1869ee 33 new TempModule(cLCD),
vtraveller 17:731a47339cb8 34 new TimeModule(cLCD,cClock),
vtraveller 20:93c70a1869ee 35 new DateModule(cLCD,cClock),
vtraveller 19:72c02acb601d 36 new SyncModule(cLCD,cClock),
vtraveller 20:93c70a1869ee 37 new TitleModule(cLCD),
vtraveller 10:3fcab08717fc 38 };
vtraveller 10:3fcab08717fc 39
vtraveller 13:9641bc42db92 40 // Set up the menu manager
vtraveller 20:93c70a1869ee 41 MenuManager cMenuManager(aModules,_countof(aModules),cLCD,16,2);
vtraveller 20:93c70a1869ee 42 //MenuManager cMenuManager(aModules,_countof(aModules),cLCD,20,4);
vtraveller 13:9641bc42db92 43
vtraveller 13:9641bc42db92 44 // Start menu manager loop
vtraveller 13:9641bc42db92 45 cMenuManager.loop();
wim 0:88d87b1c1f8b 46 }