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:
Sun Aug 10 15:45:03 2014 +0000
Revision:
11:96146db429de
Parent:
10:3fcab08717fc
Child:
12:0fea8ebe6c1a
Added support for changing time.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vtraveller 10:3fcab08717fc 1 #include "mbed.h"
vtraveller 10:3fcab08717fc 2 #include "DateModule.h"
vtraveller 10:3fcab08717fc 3 #include "time_helper.h"
vtraveller 10:3fcab08717fc 4
vtraveller 10:3fcab08717fc 5 const char * k_aWeekDays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
vtraveller 10:3fcab08717fc 6
vtraveller 10:3fcab08717fc 7 DateModule::DateModule
vtraveller 10:3fcab08717fc 8 (
vtraveller 10:3fcab08717fc 9 Adafruit_RGBLCDShield & in_cLCD,
vtraveller 10:3fcab08717fc 10 RTclock & in_cRTclock
vtraveller 10:3fcab08717fc 11 )
vtraveller 10:3fcab08717fc 12 : Module(in_cLCD)
vtraveller 10:3fcab08717fc 13 , m_cRTclock(in_cRTclock)
vtraveller 10:3fcab08717fc 14 {
vtraveller 10:3fcab08717fc 15 }
vtraveller 10:3fcab08717fc 16
vtraveller 10:3fcab08717fc 17 DateModule::~DateModule()
vtraveller 10:3fcab08717fc 18 {
vtraveller 10:3fcab08717fc 19 }
vtraveller 11:96146db429de 20
vtraveller 11:96146db429de 21 void DateModule::change
vtraveller 11:96146db429de 22 (
vtraveller 11:96146db429de 23 int in_nIndexX,
vtraveller 11:96146db429de 24 int in_nCursorY,
vtraveller 11:96146db429de 25 bool in_bUp
vtraveller 11:96146db429de 26 )
vtraveller 11:96146db429de 27 {
vtraveller 11:96146db429de 28 tm sTM;
vtraveller 10:3fcab08717fc 29
vtraveller 11:96146db429de 30 // to get the current time information
vtraveller 11:96146db429de 31 if (!m_cRTclock.getTime(sTM)) GetTime(sTM);
vtraveller 11:96146db429de 32 bool bTwelveHour = m_cRTclock.isTwelveHour();
vtraveller 11:96146db429de 33
vtraveller 11:96146db429de 34 #if 0
vtraveller 11:96146db429de 35 switch (in_nIndexX)
vtraveller 11:96146db429de 36 {
vtraveller 11:96146db429de 37 case 0: m_nTemp += (in_bUp ? 1 : -1) * 10; break;
vtraveller 11:96146db429de 38 case 1: m_nTemp += (in_bUp ? 1 : -1); break;
vtraveller 11:96146db429de 39 }
vtraveller 11:96146db429de 40 #endif
vtraveller 11:96146db429de 41
vtraveller 11:96146db429de 42 if (!m_cRTclock.setTime(sTM,bTwelveHour)) SetTime(sTM);
vtraveller 11:96146db429de 43 }
vtraveller 11:96146db429de 44
vtraveller 10:3fcab08717fc 45 int DateModule::setCursor
vtraveller 10:3fcab08717fc 46 (
vtraveller 10:3fcab08717fc 47 int in_nIndex,
vtraveller 10:3fcab08717fc 48 int in_nCursorX,
vtraveller 10:3fcab08717fc 49 int in_nCursorY
vtraveller 10:3fcab08717fc 50 )
vtraveller 10:3fcab08717fc 51 {
vtraveller 10:3fcab08717fc 52 const int k_aCursor[] = { 2, 4, 5, 7, 8, 10, 11, 12, 13 };
vtraveller 10:3fcab08717fc 53
vtraveller 10:3fcab08717fc 54 int nIndex = in_nIndex;
vtraveller 10:3fcab08717fc 55 if (nIndex < 0) nIndex = 0;
vtraveller 10:3fcab08717fc 56 if (nIndex >= _countof(k_aCursor)) nIndex = _countof(k_aCursor) - 1;
vtraveller 10:3fcab08717fc 57
vtraveller 10:3fcab08717fc 58 int nCursorX = k_aCursor[nIndex];
vtraveller 10:3fcab08717fc 59 m_cLCD.setCursor(in_nCursorX + nCursorX,in_nCursorY);
vtraveller 10:3fcab08717fc 60
vtraveller 10:3fcab08717fc 61 return nIndex;
vtraveller 10:3fcab08717fc 62 }
vtraveller 10:3fcab08717fc 63
vtraveller 10:3fcab08717fc 64 void DateModule::show()
vtraveller 10:3fcab08717fc 65 {
vtraveller 10:3fcab08717fc 66 tm sTM;
vtraveller 10:3fcab08717fc 67
vtraveller 10:3fcab08717fc 68 // to get the current time information
vtraveller 10:3fcab08717fc 69 if (!m_cRTclock.getTime(sTM)) GetTime(sTM);
vtraveller 10:3fcab08717fc 70
vtraveller 10:3fcab08717fc 71 m_cLCD.printf ("%s %02i/%02i/%04i ", k_aWeekDays[sTM.tm_wday], sTM.tm_mday, sTM.tm_mon + 1, 1900 + sTM.tm_year);
vtraveller 10:3fcab08717fc 72 }