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:
Fri Oct 10 11:10:56 2014 +0000
Revision:
28:fbcd3bac0cd7
Parent:
19:72c02acb601d
Reduced write delay - faster LCD response

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vtraveller 17:731a47339cb8 1 #include "mbed.h"
vtraveller 17:731a47339cb8 2 #include "SyncModule.h"
vtraveller 17:731a47339cb8 3 #include "extra_chars.h"
vtraveller 17:731a47339cb8 4
vtraveller 17:731a47339cb8 5 SyncModule::SyncModule
vtraveller 17:731a47339cb8 6 (
vtraveller 17:731a47339cb8 7 Serial & in_cDisplay,
vtraveller 17:731a47339cb8 8 RTclock & in_cClock
vtraveller 17:731a47339cb8 9 )
vtraveller 17:731a47339cb8 10 : Module(in_cDisplay)
vtraveller 17:731a47339cb8 11 , m_cClock(in_cClock)
vtraveller 17:731a47339cb8 12 , m_eMode(eModeLast)
vtraveller 17:731a47339cb8 13 , m_bSync(false)
vtraveller 17:731a47339cb8 14 {
vtraveller 17:731a47339cb8 15 }
vtraveller 17:731a47339cb8 16
vtraveller 17:731a47339cb8 17 SyncModule::~SyncModule()
vtraveller 17:731a47339cb8 18 {
vtraveller 17:731a47339cb8 19 }
vtraveller 17:731a47339cb8 20
vtraveller 17:731a47339cb8 21 void SyncModule::change
vtraveller 17:731a47339cb8 22 (
vtraveller 17:731a47339cb8 23 size_t /* in_nIndex */,
vtraveller 17:731a47339cb8 24 bool /* in_bUp */
vtraveller 17:731a47339cb8 25 )
vtraveller 17:731a47339cb8 26 {
vtraveller 17:731a47339cb8 27 m_bSync = (m_bSync) ? false : true;
vtraveller 17:731a47339cb8 28 }
vtraveller 17:731a47339cb8 29
vtraveller 17:731a47339cb8 30 int SyncModule::getCursorOffset(size_t & inout_nIndex)
vtraveller 17:731a47339cb8 31 {
vtraveller 17:731a47339cb8 32 return m_bSync ? 13 : 12;
vtraveller 17:731a47339cb8 33 }
vtraveller 17:731a47339cb8 34
vtraveller 17:731a47339cb8 35 void SyncModule::onModeChange(EModes in_eMode)
vtraveller 17:731a47339cb8 36 {
vtraveller 17:731a47339cb8 37 EModes eOldMode = m_eMode;
vtraveller 17:731a47339cb8 38 m_eMode = in_eMode;
vtraveller 17:731a47339cb8 39
vtraveller 17:731a47339cb8 40 if (eModeChange != eOldMode) return;
vtraveller 17:731a47339cb8 41 if (eModeMenu != m_eMode) return;
vtraveller 17:731a47339cb8 42
vtraveller 17:731a47339cb8 43 if (m_bSync)
vtraveller 17:731a47339cb8 44 {
vtraveller 17:731a47339cb8 45 // Sync the internal mbed clock (stdlib)
vtraveller 19:72c02acb601d 46 m_cClock.mapTime();
vtraveller 17:731a47339cb8 47 m_bSync = false;
vtraveller 17:731a47339cb8 48 }
vtraveller 17:731a47339cb8 49 }
vtraveller 17:731a47339cb8 50
vtraveller 17:731a47339cb8 51 void SyncModule::show(bool /*in_bRefresh*/)
vtraveller 17:731a47339cb8 52 {
vtraveller 17:731a47339cb8 53 switch (m_eMode)
vtraveller 17:731a47339cb8 54 {
vtraveller 17:731a47339cb8 55 case eModeChange:
vtraveller 17:731a47339cb8 56 case eModeSelect:
vtraveller 17:731a47339cb8 57 m_cDisplay.printf("Sync Time? %s ",m_bSync ? "yes" : "no");
vtraveller 17:731a47339cb8 58 break;
vtraveller 17:731a47339cb8 59
vtraveller 17:731a47339cb8 60 default:
vtraveller 17:731a47339cb8 61 m_cDisplay.printf("Sync Time %c ",eRight);
vtraveller 17:731a47339cb8 62 }
vtraveller 17:731a47339cb8 63 }