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 12:39:25 2014 +0000
Revision:
3:ed09f95739df
Parent:
2:ac3b92ebf17a
Child:
4:d70e37f6c6bd
snapshot

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
vtraveller 3:ed09f95739df 4 Serial pc(SERIAL_TX, SERIAL_RX);
wim 0:88d87b1c1f8b 5
vtraveller 3:ed09f95739df 6 MCP23017 mcp23017 = MCP23017(I2C_SDA, I2C_SCL, 0x40);
wim 0:88d87b1c1f8b 7
vtraveller 3:ed09f95739df 8 #define RED 0x1
vtraveller 3:ed09f95739df 9 #define YELLOW 0x3
vtraveller 3:ed09f95739df 10 #define GREEN 0x2
vtraveller 3:ed09f95739df 11 #define TEAL 0x6
vtraveller 3:ed09f95739df 12 #define BLUE 0x4
vtraveller 3:ed09f95739df 13 #define VIOLET 0x5
vtraveller 3:ed09f95739df 14 #define WHITE 0x7
vtraveller 3:ed09f95739df 15
vtraveller 3:ed09f95739df 16 // Allows to set the backlight, if the LCD backpack is used
vtraveller 3:ed09f95739df 17 void SetBacklight(unsigned char status)
vtraveller 3:ed09f95739df 18 {
vtraveller 3:ed09f95739df 19 pc.printf("Backlight: %i\n\r", status);
vtraveller 3:ed09f95739df 20
vtraveller 3:ed09f95739df 21 mcp23017.digitalWrite(8, (~(status >> 2) & 0x1));
vtraveller 3:ed09f95739df 22 mcp23017.digitalWrite(7, (~(status >> 1) & 0x1));
vtraveller 3:ed09f95739df 23 mcp23017.digitalWrite(6, (~status & 0x1));
vtraveller 3:ed09f95739df 24 }
wim 0:88d87b1c1f8b 25
vtraveller 3:ed09f95739df 26 void LED(bool bOn)
vtraveller 3:ed09f95739df 27 {
vtraveller 3:ed09f95739df 28 pc.printf("LED: %s\n\r", bOn ? "On" : "Off");
vtraveller 3:ed09f95739df 29 //mcp23017.write(PORT_A, bOn ? 0x10 : 0xFF);
vtraveller 3:ed09f95739df 30 //mcp23017.write(PORT_B, bOn ? 0x10 : 0xFF);
vtraveller 3:ed09f95739df 31 }
vtraveller 3:ed09f95739df 32
vtraveller 3:ed09f95739df 33 int main()
vtraveller 3:ed09f95739df 34 {
vtraveller 3:ed09f95739df 35 pc.printf("START\n\r");
wim 0:88d87b1c1f8b 36
wim 0:88d87b1c1f8b 37 // I2C init
vtraveller 3:ed09f95739df 38 //mcp23017.i2c.frequency(400000);
wim 0:88d87b1c1f8b 39
wim 0:88d87b1c1f8b 40 // Port A is databus - Output
vtraveller 3:ed09f95739df 41 //mcp23017.direction(PORT_A, PORT_DIR_OUT);
vtraveller 3:ed09f95739df 42
wim 0:88d87b1c1f8b 43 // Port B is controlbus - Output
vtraveller 3:ed09f95739df 44 //mcp23017.direction(PORT_B, PORT_DIR_OUT);
vtraveller 3:ed09f95739df 45
vtraveller 3:ed09f95739df 46 pc.printf("mcp23017.config(0,1,0);\n\r");
vtraveller 3:ed09f95739df 47 mcp23017.config(0,1,0);
vtraveller 3:ed09f95739df 48 wait(0.5);
wim 0:88d87b1c1f8b 49
vtraveller 3:ed09f95739df 50 pc.printf("mcp23017.pinMode\n\r");
vtraveller 3:ed09f95739df 51 mcp23017.pinMode(8, DIR_OUTPUT);
vtraveller 3:ed09f95739df 52 mcp23017.pinMode(7, DIR_OUTPUT);
vtraveller 3:ed09f95739df 53 mcp23017.pinMode(6, DIR_OUTPUT);
vtraveller 3:ed09f95739df 54
vtraveller 3:ed09f95739df 55 SetBacklight(WHITE);
vtraveller 3:ed09f95739df 56
vtraveller 3:ed09f95739df 57 wait(0.5);
vtraveller 1:45e2e7c0754d 58 pc.printf("MPC Init done\n\r");
wim 0:88d87b1c1f8b 59
vtraveller 3:ed09f95739df 60 LED(false);
vtraveller 3:ed09f95739df 61 LED(true);
vtraveller 3:ed09f95739df 62
vtraveller 3:ed09f95739df 63 SetBacklight(RED);
vtraveller 3:ed09f95739df 64 pc.printf("FINISHED\n\r");
wim 0:88d87b1c1f8b 65 }