Control Code with I/O and ADC working

Dependencies:   MODSERIAL mbed

Revision:
5:0f38a0bd4f86
Parent:
1:0182b86f9bd4
Child:
6:c980535393ed
--- a/MCP23008/MCP23008.cpp	Tue Feb 13 20:30:59 2018 +0000
+++ b/MCP23008/MCP23008.cpp	Thu Mar 01 21:13:55 2018 +0000
@@ -11,6 +11,7 @@
     /* MCP23008 registers */
     const uint8_t IODIR             = 0x00;
     const uint8_t GPIO              = 0x09;
+    const uint8_t PULLUP            = 0x06;
     
     //Channel addresses
     const uint8_t CHNL_0     = 0x01;
@@ -30,6 +31,7 @@
 
 void MCP23008::writeOutput(int chn1, int chn2, int chn3, int chn4){
     char data[2];
+    char data2[2];
     uint8_t val = 0x00;
     
     //Create mask for all bits that should be on
@@ -40,8 +42,12 @@
         
     data[0] = GPIO;  //register address
     data[1] = val;   //GPIO bit map
+    data2[0] = PULLUP;
+    data2[1] = 0x00;
 
-    i2c.write((addrI2C<<1)|(I2C_WRITE), data, 2); 
+    i2c.write((addrI2C<<1)|(I2C_WRITE), data, 2);
+    i2c.write((addrI2C<<1)|(I2C_WRITE), data2, 2);
+    wait(0.1);
 }
 
 void MCP23008::init(){
@@ -51,6 +57,7 @@
     io_setup[1] = 0x00; //turn all pins to outputs
     
     i2c.write((addrI2C<<1)|(I2C_WRITE), io_setup, 2);
+    wait(0.1);
     
     //Set all outputs to off
     GPIO_Pin_Status = 0x00;