CaryCoders / Mbed 2 deprecated SX1276_GPS

Dependencies:   SX1276Lib AdaFruit_RGBLCD MCP23017 mbed

Fork of AdaFruit_RGBLCD by Justin Howard

Revision:
3:ed09f95739df
Parent:
2:ac3b92ebf17a
Child:
4:d70e37f6c6bd
--- a/main.cpp	Sat Aug 02 11:07:48 2014 +0000
+++ b/main.cpp	Sat Aug 02 12:39:25 2014 +0000
@@ -1,39 +1,65 @@
 #include "mbed.h"
 #include "MCP23017.h"
 
-DigitalOut myled1(LED1);
-DigitalOut myled2(LED2);
+Serial pc(SERIAL_TX, SERIAL_RX);
 
-Serial pc(USBTX, USBRX);
-I2C i2c(I2C_SDA, I2C_SCL);
+MCP23017 mcp23017 = MCP23017(I2C_SDA, I2C_SCL, 0x40);
 
-MCP23017 mcp23017 = MCP23017(i2c, 0x40);
+#define RED 0x1
+#define YELLOW 0x3
+#define GREEN 0x2
+#define TEAL 0x6
+#define BLUE 0x4
+#define VIOLET 0x5
+#define WHITE 0x7
+    
+// Allows to set the backlight, if the LCD backpack is used
+void SetBacklight(unsigned char status)
+{
+    pc.printf("Backlight: %i\n\r", status);
+    
+    mcp23017.digitalWrite(8, (~(status >> 2) & 0x1));
+    mcp23017.digitalWrite(7, (~(status >> 1) & 0x1));
+    mcp23017.digitalWrite(6, (~status & 0x1));
+}
 
-int main() {
-    
-    pc.printf("Hello World\n\r");
+void LED(bool bOn)
+{
+    pc.printf("LED: %s\n\r", bOn ? "On" : "Off");
+    //mcp23017.write(PORT_A, bOn ? 0x10 : 0xFF);
+    //mcp23017.write(PORT_B, bOn ? 0x10 : 0xFF);
+}
+
+int main()
+{    
+    pc.printf("START\n\r");
     
     // I2C init
-    i2c.frequency(400000);
+    //mcp23017.i2c.frequency(400000);
     
     // Port A is databus - Output
-    mcp23017.direction(PORT_A, PORT_DIR_OUT);
+    //mcp23017.direction(PORT_A, PORT_DIR_OUT);
+    
     // Port B is controlbus - Output       
-    mcp23017.direction(PORT_B, PORT_DIR_OUT); 
+    //mcp23017.direction(PORT_B, PORT_DIR_OUT); 
+    
+    pc.printf("mcp23017.config(0,1,0);\n\r");
+    mcp23017.config(0,1,0);
+    wait(0.5);
     
-    myled2 = 1;
+    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");           
     
-    while(1) {
-        myled1 = 1;
-        mcp23017.write(PORT_A, 0xFF);
-        mcp23017.write(PORT_B, 0xFF);        
-        wait(0.1);
-           
-        myled1 = 0;
-        mcp23017.write(PORT_A, 0x00);
-        mcp23017.write(PORT_B, 0x00);        
-        wait(0.1);
-        pc.printf("*");
-    }
+    LED(false);
+    LED(true);
+    
+    SetBacklight(RED);
+    pc.printf("FINISHED\n\r");
 }