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 02 11:07:48 2014 +0000
Revision:
2:ac3b92ebf17a
Parent:
1:45e2e7c0754d
Child:
3:ed09f95739df
Faster LED tick

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 0:88d87b1c1f8b 1 #include "mbed.h"
wim 0:88d87b1c1f8b 2 #include "MCP23017.h"
wim 0:88d87b1c1f8b 3
wim 0:88d87b1c1f8b 4 DigitalOut myled1(LED1);
wim 0:88d87b1c1f8b 5 DigitalOut myled2(LED2);
wim 0:88d87b1c1f8b 6
wim 0:88d87b1c1f8b 7 Serial pc(USBTX, USBRX);
vtraveller 1:45e2e7c0754d 8 I2C i2c(I2C_SDA, I2C_SCL);
wim 0:88d87b1c1f8b 9
wim 0:88d87b1c1f8b 10 MCP23017 mcp23017 = MCP23017(i2c, 0x40);
wim 0:88d87b1c1f8b 11
wim 0:88d87b1c1f8b 12 int main() {
wim 0:88d87b1c1f8b 13
vtraveller 1:45e2e7c0754d 14 pc.printf("Hello World\n\r");
wim 0:88d87b1c1f8b 15
wim 0:88d87b1c1f8b 16 // I2C init
vtraveller 1:45e2e7c0754d 17 i2c.frequency(400000);
wim 0:88d87b1c1f8b 18
wim 0:88d87b1c1f8b 19 // Port A is databus - Output
wim 0:88d87b1c1f8b 20 mcp23017.direction(PORT_A, PORT_DIR_OUT);
wim 0:88d87b1c1f8b 21 // Port B is controlbus - Output
wim 0:88d87b1c1f8b 22 mcp23017.direction(PORT_B, PORT_DIR_OUT);
wim 0:88d87b1c1f8b 23
wim 0:88d87b1c1f8b 24 myled2 = 1;
vtraveller 1:45e2e7c0754d 25 pc.printf("MPC Init done\n\r");
wim 0:88d87b1c1f8b 26
wim 0:88d87b1c1f8b 27 while(1) {
wim 0:88d87b1c1f8b 28 myled1 = 1;
wim 0:88d87b1c1f8b 29 mcp23017.write(PORT_A, 0xFF);
wim 0:88d87b1c1f8b 30 mcp23017.write(PORT_B, 0xFF);
vtraveller 2:ac3b92ebf17a 31 wait(0.1);
wim 0:88d87b1c1f8b 32
wim 0:88d87b1c1f8b 33 myled1 = 0;
wim 0:88d87b1c1f8b 34 mcp23017.write(PORT_A, 0x00);
wim 0:88d87b1c1f8b 35 mcp23017.write(PORT_B, 0x00);
vtraveller 2:ac3b92ebf17a 36 wait(0.1);
wim 0:88d87b1c1f8b 37 pc.printf("*");
wim 0:88d87b1c1f8b 38 }
wim 0:88d87b1c1f8b 39 }