![](/media/cache/profiles/010d18a1aeff169f741b6fe97fdd6a1d.jpg.50x50_q85.jpg)
figuring this out...
main.cpp@2:ada8ecd122e4, 2014-05-28 (annotated)
- Committer:
- ghostaudio
- Date:
- Wed May 28 14:59:12 2014 +0000
- Revision:
- 2:ada8ecd122e4
- Parent:
- 0:498ee64f952a
getting closer;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ghostaudio | 0:498ee64f952a | 1 | #include "mbed.h" |
ghostaudio | 0:498ee64f952a | 2 | #include "VCNL40x0.h" |
ghostaudio | 0:498ee64f952a | 3 | |
ghostaudio | 0:498ee64f952a | 4 | #define BAUD 115200 |
ghostaudio | 0:498ee64f952a | 5 | |
ghostaudio | 0:498ee64f952a | 6 | //const char chan0 = 0001; |
ghostaudio | 0:498ee64f952a | 7 | //const char chan1 = 0010; |
ghostaudio | 0:498ee64f952a | 8 | //const char chan2 = 0100; |
ghostaudio | 0:498ee64f952a | 9 | //const char chan3 = 1000; |
ghostaudio | 0:498ee64f952a | 10 | //const char all = 1111; |
ghostaudio | 0:498ee64f952a | 11 | |
ghostaudio | 2:ada8ecd122e4 | 12 | const int MUX = 0x60; // 11100000 |
ghostaudio | 0:498ee64f952a | 13 | unsigned int sensors[4]; |
ghostaudio | 0:498ee64f952a | 14 | |
ghostaudio | 0:498ee64f952a | 15 | I2C i2c(p28, p27); |
ghostaudio | 0:498ee64f952a | 16 | VCNL40x0 VCNL40x0_Device (p28, p27, VCNL40x0_ADDRESS); // Define SDA, SCL pin and I2C address |
ghostaudio | 0:498ee64f952a | 17 | DigitalOut mled0(LED1); // LED #1 |
ghostaudio | 0:498ee64f952a | 18 | Serial pc(USBTX, USBRX); // Tx, Rx USB transmission |
ghostaudio | 0:498ee64f952a | 19 | |
ghostaudio | 0:498ee64f952a | 20 | int main() { |
ghostaudio | 0:498ee64f952a | 21 | |
ghostaudio | 0:498ee64f952a | 22 | unsigned int sensors[4]; |
ghostaudio | 2:ada8ecd122e4 | 23 | char chan[] = {0x01,0x02,0x04,0x08}; |
ghostaudio | 0:498ee64f952a | 24 | pc.baud(BAUD); // set USB speed (virtual COM port) |
ghostaudio | 0:498ee64f952a | 25 | |
ghostaudio | 0:498ee64f952a | 26 | for (int i = 0; i < 4; i++){ |
ghostaudio | 2:ada8ecd122e4 | 27 | char port[2]; |
ghostaudio | 2:ada8ecd122e4 | 28 | port[0] = 0; |
ghostaudio | 2:ada8ecd122e4 | 29 | port[1] = chan[i]; |
ghostaudio | 2:ada8ecd122e4 | 30 | i2c.write(MUX,port, 2); |
ghostaudio | 0:498ee64f952a | 31 | VCNL40x0_Device.SetCurrent (20); // Set current to 200mA |
ghostaudio | 0:498ee64f952a | 32 | } |
ghostaudio | 0:498ee64f952a | 33 | |
ghostaudio | 0:498ee64f952a | 34 | while (1) { |
ghostaudio | 0:498ee64f952a | 35 | for (int i = 0; i < 4; i++){ |
ghostaudio | 2:ada8ecd122e4 | 36 | char port[2]; |
ghostaudio | 2:ada8ecd122e4 | 37 | port[0] = 0; |
ghostaudio | 2:ada8ecd122e4 | 38 | port[1] = chan[i]; |
ghostaudio | 2:ada8ecd122e4 | 39 | i2c.write(MUX,port, 2); |
ghostaudio | 0:498ee64f952a | 40 | |
ghostaudio | 0:498ee64f952a | 41 | mled0 = 1; // LED on |
ghostaudio | 0:498ee64f952a | 42 | VCNL40x0_Device.ReadProxiOnDemand (&sensors[i]); // read prox value on demand |
ghostaudio | 0:498ee64f952a | 43 | mled0 = 0; // LED off |
ghostaudio | 0:498ee64f952a | 44 | } |
ghostaudio | 0:498ee64f952a | 45 | for (int i = 0; i < 4; i++){ |
ghostaudio | 0:498ee64f952a | 46 | pc.printf("\r %i ", sensors[i]); |
ghostaudio | 0:498ee64f952a | 47 | } |
ghostaudio | 0:498ee64f952a | 48 | pc.printf("\r \n "); |
ghostaudio | 0:498ee64f952a | 49 | } |
ghostaudio | 0:498ee64f952a | 50 | } |