Example of how to use the library for the MCP23017 16 bit expander port for I2C.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
wim
Date:
Sat Dec 18 19:44:49 2010 +0000
Commit message:
Initial version

Changed in this revision

MCP23017.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 88d87b1c1f8b MCP23017.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MCP23017.lib	Sat Dec 18 19:44:49 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/wim/code/MCP23017/#5696b886a895
diff -r 000000000000 -r 88d87b1c1f8b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Dec 18 19:44:49 2010 +0000
@@ -0,0 +1,39 @@
+#include "mbed.h"
+#include "MCP23017.h"
+
+DigitalOut myled1(LED1);
+DigitalOut myled2(LED2);
+
+Serial pc(USBTX, USBRX);
+I2C i2c(p9, p10);
+
+MCP23017 mcp23017 = MCP23017(i2c, 0x40);
+
+int main() {
+    
+    pc.printf("Hello World\n");
+    
+    // I2C init
+    i2c.frequency(100000);
+    
+    // Port A is databus - Output
+    mcp23017.direction(PORT_A, PORT_DIR_OUT);
+    // Port B is controlbus - Output       
+    mcp23017.direction(PORT_B, PORT_DIR_OUT); 
+    
+    myled2 = 1;
+    pc.printf("MPC Init done\n");           
+    
+    while(1) {
+        myled1 = 1;
+        mcp23017.write(PORT_A, 0xFF);
+        mcp23017.write(PORT_B, 0xFF);        
+        wait(0.2);
+           
+        myled1 = 0;
+        mcp23017.write(PORT_A, 0x00);
+        mcp23017.write(PORT_B, 0x00);        
+        wait(0.2);
+        pc.printf("*");
+    }
+}
diff -r 000000000000 -r 88d87b1c1f8b mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Dec 18 19:44:49 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e