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:
Tue Aug 12 04:25:08 2014 +0000
Revision:
15:d1eaddb363be
Parent:
14:8b359e1e68f3
Child:
20:93c70a1869ee
Added refresh parameter to show().; Updated time and date to only refresh if there's a change.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vtraveller 10:3fcab08717fc 1 #include "mbed.h"
vtraveller 10:3fcab08717fc 2 #include "TempModule.h"
vtraveller 10:3fcab08717fc 3
vtraveller 10:3fcab08717fc 4 #include "extra_chars.h"
vtraveller 10:3fcab08717fc 5
vtraveller 13:9641bc42db92 6 TempModule::TempModule(Serial & in_cDisplay)
vtraveller 13:9641bc42db92 7 : Module(in_cDisplay)
vtraveller 11:96146db429de 8 , m_nTemp(28)
vtraveller 10:3fcab08717fc 9 {
vtraveller 10:3fcab08717fc 10 }
vtraveller 10:3fcab08717fc 11
vtraveller 10:3fcab08717fc 12 TempModule::~TempModule()
vtraveller 10:3fcab08717fc 13 {
vtraveller 10:3fcab08717fc 14 }
vtraveller 11:96146db429de 15
vtraveller 11:96146db429de 16 void TempModule::change
vtraveller 11:96146db429de 17 (
vtraveller 13:9641bc42db92 18 size_t in_nIndex,
vtraveller 11:96146db429de 19 bool in_bUp
vtraveller 11:96146db429de 20 )
vtraveller 11:96146db429de 21 {
vtraveller 11:96146db429de 22 enum ETemp
vtraveller 11:96146db429de 23 {
vtraveller 11:96146db429de 24 eTens = 0,
vtraveller 11:96146db429de 25 eSingles = 1,
vtraveller 11:96146db429de 26 };
vtraveller 10:3fcab08717fc 27
vtraveller 13:9641bc42db92 28 switch (in_nIndex)
vtraveller 11:96146db429de 29 {
vtraveller 11:96146db429de 30 case eTens: m_nTemp += (in_bUp ? 1 : -1) * 10; break;
vtraveller 11:96146db429de 31 case eSingles: m_nTemp += (in_bUp ? 1 : -1); break;
vtraveller 11:96146db429de 32 }
vtraveller 11:96146db429de 33
vtraveller 11:96146db429de 34 if (m_nTemp > 40) m_nTemp = 40;
vtraveller 11:96146db429de 35 if (m_nTemp < -40) m_nTemp = -40;
vtraveller 11:96146db429de 36 }
vtraveller 11:96146db429de 37
vtraveller 13:9641bc42db92 38 int TempModule::getCursorOffset(size_t & inout_nIndex)
vtraveller 10:3fcab08717fc 39 {
vtraveller 10:3fcab08717fc 40 const int k_aCursor[] = { 6, 7 };
vtraveller 10:3fcab08717fc 41
vtraveller 14:8b359e1e68f3 42 if ((int)inout_nIndex < 0) inout_nIndex = 0;
vtraveller 13:9641bc42db92 43 if (inout_nIndex >= _countof(k_aCursor)) inout_nIndex = _countof(k_aCursor) - 1;
vtraveller 10:3fcab08717fc 44
vtraveller 13:9641bc42db92 45 return k_aCursor[inout_nIndex];
vtraveller 10:3fcab08717fc 46 }
vtraveller 10:3fcab08717fc 47
vtraveller 15:d1eaddb363be 48 void TempModule::show(bool /*in_bRefresh*/)
vtraveller 10:3fcab08717fc 49 {
vtraveller 13:9641bc42db92 50 m_cDisplay.printf("Room: %i%cC ",m_nTemp,eDegree);
vtraveller 10:3fcab08717fc 51 }