Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SX1276Lib AdaFruit_RGBLCD MCP23017 mbed
Fork of AdaFruit_RGBLCD by
Diff: main.cpp
- Revision:
- 4:d70e37f6c6bd
- Parent:
- 3:ed09f95739df
- Child:
- 5:6c9ee7e3a20c
--- a/main.cpp Sat Aug 02 12:39:25 2014 +0000 +++ b/main.cpp Sat Aug 02 13:50:40 2014 +0000 @@ -1,9 +1,12 @@ #include "mbed.h" -#include "MCP23017.h" + +#include "Adafruit_RGBLCDShield.h" +//#include "MCP23017.h" Serial pc(SERIAL_TX, SERIAL_RX); MCP23017 mcp23017 = MCP23017(I2C_SDA, I2C_SCL, 0x40); +Adafruit_RGBLCDShield lcd(mcp23017); #define RED 0x1 #define YELLOW 0x3 @@ -23,16 +26,64 @@ mcp23017.digitalWrite(6, (~status & 0x1)); } -void LED(bool bOn) +void loop() { - pc.printf("LED: %s\n\r", bOn ? "On" : "Off"); - //mcp23017.write(PORT_A, bOn ? 0x10 : 0xFF); - //mcp23017.write(PORT_B, bOn ? 0x10 : 0xFF); + // set the cursor to column 0, line 1 + // (note: line 1 is the second row, since counting begins with 0): + lcd.setCursor(0, 1); + + uint8_t buttons = lcd.readButtons(); + + if (buttons) + { + lcd.clear(); + lcd.setCursor(0,0); + + if (buttons & BUTTON_UP) + { + pc.printf("UP "); + + lcd.printf("UP "); + lcd.setBacklight(RED); + } + + if (buttons & BUTTON_DOWN) + { + pc.printf("DOWN "); + + lcd.printf("DOWN "); + lcd.setBacklight(YELLOW); + } + + if (buttons & BUTTON_LEFT) + { + pc.printf("LEFT "); + + lcd.printf("LEFT "); + lcd.setBacklight(GREEN); + } + + if (buttons & BUTTON_RIGHT) + { + pc.printf("RIGHT "); + + lcd.printf("RIGHT "); + lcd.setBacklight(TEAL); + } + + if (buttons & BUTTON_SELECT) + { + pc.printf("SELECT "); + + lcd.printf("SELECT "); + lcd.setBacklight(VIOLET); + } + } } int main() { - pc.printf("START\n\r"); + pc.printf("\n\rSTART\n\r"); // I2C init //mcp23017.i2c.frequency(400000); @@ -47,19 +98,30 @@ mcp23017.config(0,1,0); wait(0.5); - pc.printf("mcp23017.pinMode\n\r"); - mcp23017.pinMode(8, DIR_OUTPUT); - mcp23017.pinMode(7, DIR_OUTPUT); - mcp23017.pinMode(6, DIR_OUTPUT); + //pc.printf("mcp23017.pinMode\n\r"); + //mcp23017.pinMode(8, DIR_OUTPUT); + //mcp23017.pinMode(7, DIR_OUTPUT); + //mcp23017.pinMode(6, DIR_OUTPUT); - SetBacklight(WHITE); + //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("MPC Init done\n\r"); + + lcd.printf("Hello, world!"); + lcd.setBacklight(GREEN); - LED(false); - LED(true); + while (true) + { + loop(); + wait(0.2); + } - SetBacklight(RED); - pc.printf("FINISHED\n\r"); + //pc.printf("FINISHED\n\r"); }