Example of how to use an Ada Fruit RGB LCD with the Ada Fruit RGB LCD Shield Library
Dependencies: AdaFruit_RGBLCDShield MCP23017 mbed RTclock
Fork of MCP_test by
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!
Revision 5:6c9ee7e3a20c, committed 2014-08-02
- Comitter:
- vtraveller
- Date:
- Sat Aug 02 14:16:30 2014 +0000
- Parent:
- 4:d70e37f6c6bd
- Child:
- 6:a6be2aede8f2
- Commit message:
- Improved pull-up resisitor code
Changed in this revision
--- a/AdaFruit_RGBLCDShield.cpp Sat Aug 02 13:50:40 2014 +0000
+++ b/AdaFruit_RGBLCDShield.cpp Sat Aug 02 14:16:30 2014 +0000
@@ -28,7 +28,9 @@
#define delayMicroseconds(a) wait(a / 1000000)
-/* Remove Arduino i2c (wire) interface
+/* MBED TURNED OFF
+
+Arduino i2c (wire) interface
#include <Wire.h>
#ifdef __AVR__
@@ -63,6 +65,8 @@
// can't assume that its in that state when a sketch starts (and the
// RGBLCDShield constructor is called).
+// MBED - wired in serial
+// MBED - wired in _i2c
Adafruit_RGBLCDShield::Adafruit_RGBLCDShield(MCP23017 & inMCP)
: Serial(SERIAL_TX, SERIAL_RX)
, _i2c(inMCP)
@@ -128,7 +132,7 @@
if (_i2cAddr != 255) {
//_i2c.begin(_i2cAddr);
//WIRE.begin();
- //_i2c->begin();
+ _i2c.reset();
_i2c.pinMode(8, OUTPUT);
_i2c.pinMode(6, OUTPUT);
@@ -143,12 +147,14 @@
for (uint8_t i=0; i<4; i++)
_i2c.pinMode(_data_pins[i], OUTPUT);
+ unsigned short nPullups = 0;
for (uint8_t i=0; i<5; i++) {
_i2c.pinMode(_button_pins[i], INPUT);
+ nPullups |= (1 << _button_pins[i]);
//_i2c.pullUp(_button_pins[i], 1);
}
- _i2c.internalPullupMask(0xffff);
+ _i2c.internalPullupMask(nPullups);
}
if (lines > 1) {
@@ -349,7 +355,7 @@
_i2c.digitalWrite(p, d);
} else {
// straightup IO
- // @@@ TURNED OFF @@@
+ // MBED TURNED OFF
//digitalWrite(p, d);
}
}
@@ -369,7 +375,7 @@
_i2c.pinMode(p, d);
} else {
// straightup IO
- //@@@ TURNED OFF @@@
+ // MBED TURNED OFF
//pinMode(p, d);
}
}
--- a/Adafruit_RGBLCDShield.h Sat Aug 02 13:50:40 2014 +0000
+++ b/Adafruit_RGBLCDShield.h Sat Aug 02 14:16:30 2014 +0000
@@ -64,10 +64,10 @@
#define BUTTON_SELECT 0x01
class Adafruit_RGBLCDShield
-// : public Print
- : public Serial
+ : public Serial // MBED was Print
{
public:
+ // Updated constructor
Adafruit_RGBLCDShield(MCP23017 & inMCP);
void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
--- a/main.cpp Sat Aug 02 13:50:40 2014 +0000
+++ b/main.cpp Sat Aug 02 14:16:30 2014 +0000
@@ -84,44 +84,31 @@
int main()
{
pc.printf("\n\rSTART\n\r");
-
- // I2C init
- //mcp23017.i2c.frequency(400000);
-
- // Port A is databus - Output
- //mcp23017.direction(PORT_A, PORT_DIR_OUT);
-
- // Port B is controlbus - Output
- //mcp23017.direction(PORT_B, PORT_DIR_OUT);
-
+
+ // Take MCP out of reset to show its backlight
pc.printf("mcp23017.config(0,1,0);\n\r");
mcp23017.config(0,1,0);
+
+ wait(0.5);
+
+ pc.printf("\n\rInitialise LCD\n\r");
+ lcd.begin(16,2);
+
+ pc.printf("\n\rShow a letter\n\r");
+ lcd._putc('A');
+
wait(0.5);
- //pc.printf("mcp23017.pinMode\n\r");
- //mcp23017.pinMode(8, DIR_OUTPUT);
- //mcp23017.pinMode(7, DIR_OUTPUT);
- //mcp23017.pinMode(6, DIR_OUTPUT);
-
- //SetBacklight(WHITE);
-
- //wait(0.5);
- //pc.printf("MPC Init done\n\r");
-
- lcd.begin(16,2);
- lcd.display();
-
- lcd._putc('A');
- wait(0.5);
-
+ pc.printf("\n\rPrint Hello World\n\r");
lcd.printf("Hello, world!");
lcd.setBacklight(GREEN);
+ wait(0.5);
+
+ pc.printf("\n\rEntering key tracking loop\n\r");
while (true)
{
loop();
wait(0.2);
- }
-
- //pc.printf("FINISHED\n\r");
+ }
}
