Hello World example for the PCF8574

Dependencies:   PCF8574 mbed

Fork of PCF8574_HelloWorld by Simon Ford

Files at this revision

API Documentation at this revision

Comitter:
aslam
Date:
Wed May 20 10:26:52 2015 +0000
Parent:
1:873215cad8d2
Commit message:
4x4 keypad interfacing through i2c to gpio expander IC (PCF8574)

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 873215cad8d2 -r 92715b8bee8f main.cpp
--- a/main.cpp	Wed Feb 11 07:46:38 2015 +0000
+++ b/main.cpp	Wed May 20 10:26:52 2015 +0000
@@ -1,43 +1,57 @@
 #include "mbed.h"
 #include "PCF8574.h"
 
-#define BAUD 115200
-#define TX_PIN p13
-#define RX_PIN p14
+#define BAUD 9600
+InterruptIn event(p12);
+Serial pc(USBTX, USBRX); 
+PCF8574 io(p9,p10,0x40);
+int data1 , data2;
 
- #include "MODSERIAL.h"
- 
- MODSERIAL pc(USBTX, USBRX);
- MODSERIAL uart(TX_PIN, RX_PIN);
- 
-PCF8574 io(p9,p10,0x70);
-
-int main(){
-        
-        pc.baud(BAUD);
-        uart.baud(BAUD);
-        pc.printf("Start\n\r");
-while(1) 
+void display(int data)
+{
+switch (data)
 {
-io.write(0x0);
-if ((io.read()) == 17) {
-//io.write(0x01);
-pc.printf("key Pressed SW1\n\r");
-}
-else if((io.read()) == 18)
-{
-//io.write(0x02);
-pc.printf("key Pressed SW2\n\r");
+    case 238: pc.printf("SW1 \n\r"); break;
+    case 237: pc.printf("SW2 \n\r"); break;
+    case 235: pc.printf("SW3 \n\r"); break;
+    case 231: pc.printf("SW4 \n\r"); break;
+    case 222: pc.printf("SW5 \n\r"); break;
+    case 221: pc.printf("SW6 \n\r"); break;
+    case 219: pc.printf("SW7 \n\r"); break;
+    case 215: pc.printf("SW8 \n\r"); break;
+    case 190: pc.printf("SW9 \n\r"); break;
+    case 189: pc.printf("SW10 \n\r"); break;
+    case 187: pc.printf("SW11 \n\r"); break;
+    case 183: pc.printf("SW12 \n\r"); break;
+    case 126: pc.printf("SW13 \n\r"); break;
+    case 125: pc.printf("SW14 \n\r"); break;
+    case 123: pc.printf("SW15 \n\r"); break;
+    case 119: pc.printf("SW16 \n\r"); break;
+    }    
 }
-else if((io.read()) == 20)
-{
-//io.write(0x04);
-pc.printf("key Pressed SW3\n\r");
-}
-else if((io.read()) == 24)
-{
-//io.write(0x08);
-pc.printf("key Pressed SW4\n\r");
-}
-}
+
+        void trigger() 
+            {
+                //event.fall(NULL);
+               //printf("triggered!\n");
+                io.write(0x0f);
+                data1 = io.read();
+            
+                io.write(0xf0);
+                data2 = io.read();
+                
+                display(data1+data2);
+                //wait(0.2);
+                //event.fall(&trigger);
+            }
+
+int main()
+{    
+    pc.printf("Start\n\r");
+    event.fall(&trigger);
+    //event.rise(&trigger);
+    while(1) 
+    {
+    
+    }
 }
\ No newline at end of file