figuring this out...

Dependencies:   VCNL40x0 mbed

main.cpp

Committer:
ghostaudio
Date:
2014-05-28
Revision:
0:498ee64f952a
Child:
2:ada8ecd122e4

File content as of revision 0:498ee64f952a:

#include "mbed.h"
#include "VCNL40x0.h"

#define MUX 0x60 // 11100000
#define BAUD    115200

//const char chan0 = 0001;
//const char chan1 = 0010;
//const char chan2 = 0100;
//const char chan3 = 1000;
//const char all = 1111;

// unsigned char chan[] = {0001,0010,0100,1000,1111};
unsigned int sensors[4];

I2C i2c(p28, p27);
VCNL40x0 VCNL40x0_Device (p28, p27, VCNL40x0_ADDRESS);      // Define SDA, SCL pin and I2C address
DigitalOut mled0(LED1);                                     // LED #1
Serial pc(USBTX, USBRX);                                    // Tx, Rx USB transmission


int main() {
    
    unsigned int sensors[4];
    char chan[] = {0001,0010,0100,1000,1111};
    pc.baud(BAUD);                                          // set USB speed (virtual COM port)
    
    for (int i = 0; i < 4; i++){
            
            i2c.write(MUX,chan0, 2);
            VCNL40x0_Device.SetCurrent (20);                 // Set current to 200mA
        }
    
    while (1) {
        for (int i = 0; i < 4; i++){
            
            i2c.write(MUX,chan[i]);
            
            mled0 = 1;                                          // LED on
            VCNL40x0_Device.ReadProxiOnDemand (&sensors[i]);    // read prox value on demand
            mled0 = 0;                                          // LED off
        }
        for (int i = 0; i < 4; i++){
        pc.printf("\r %i ", sensors[i]);
        }
    pc.printf("\r \n ");
    }
}