![](/media/cache/profiles/010d18a1aeff169f741b6fe97fdd6a1d.jpg.50x50_q85.jpg)
figuring this out...
main.cpp@0:498ee64f952a, 2014-05-28 (annotated)
- Committer:
- ghostaudio
- Date:
- Wed May 28 13:48:19 2014 +0000
- Revision:
- 0:498ee64f952a
- Child:
- 2:ada8ecd122e4
howthe hell does this work then; ;
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 MUX 0x60 // 11100000 |
ghostaudio | 0:498ee64f952a | 5 | #define BAUD 115200 |
ghostaudio | 0:498ee64f952a | 6 | |
ghostaudio | 0:498ee64f952a | 7 | //const char chan0 = 0001; |
ghostaudio | 0:498ee64f952a | 8 | //const char chan1 = 0010; |
ghostaudio | 0:498ee64f952a | 9 | //const char chan2 = 0100; |
ghostaudio | 0:498ee64f952a | 10 | //const char chan3 = 1000; |
ghostaudio | 0:498ee64f952a | 11 | //const char all = 1111; |
ghostaudio | 0:498ee64f952a | 12 | |
ghostaudio | 0:498ee64f952a | 13 | // unsigned char chan[] = {0001,0010,0100,1000,1111}; |
ghostaudio | 0:498ee64f952a | 14 | unsigned int sensors[4]; |
ghostaudio | 0:498ee64f952a | 15 | |
ghostaudio | 0:498ee64f952a | 16 | I2C i2c(p28, p27); |
ghostaudio | 0:498ee64f952a | 17 | VCNL40x0 VCNL40x0_Device (p28, p27, VCNL40x0_ADDRESS); // Define SDA, SCL pin and I2C address |
ghostaudio | 0:498ee64f952a | 18 | DigitalOut mled0(LED1); // LED #1 |
ghostaudio | 0:498ee64f952a | 19 | Serial pc(USBTX, USBRX); // Tx, Rx USB transmission |
ghostaudio | 0:498ee64f952a | 20 | |
ghostaudio | 0:498ee64f952a | 21 | |
ghostaudio | 0:498ee64f952a | 22 | int main() { |
ghostaudio | 0:498ee64f952a | 23 | |
ghostaudio | 0:498ee64f952a | 24 | unsigned int sensors[4]; |
ghostaudio | 0:498ee64f952a | 25 | char chan[] = {0001,0010,0100,1000,1111}; |
ghostaudio | 0:498ee64f952a | 26 | pc.baud(BAUD); // set USB speed (virtual COM port) |
ghostaudio | 0:498ee64f952a | 27 | |
ghostaudio | 0:498ee64f952a | 28 | for (int i = 0; i < 4; i++){ |
ghostaudio | 0:498ee64f952a | 29 | |
ghostaudio | 0:498ee64f952a | 30 | i2c.write(MUX,chan0, 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 | 0:498ee64f952a | 36 | |
ghostaudio | 0:498ee64f952a | 37 | i2c.write(MUX,chan[i]); |
ghostaudio | 0:498ee64f952a | 38 | |
ghostaudio | 0:498ee64f952a | 39 | mled0 = 1; // LED on |
ghostaudio | 0:498ee64f952a | 40 | VCNL40x0_Device.ReadProxiOnDemand (&sensors[i]); // read prox value on demand |
ghostaudio | 0:498ee64f952a | 41 | mled0 = 0; // LED off |
ghostaudio | 0:498ee64f952a | 42 | } |
ghostaudio | 0:498ee64f952a | 43 | for (int i = 0; i < 4; i++){ |
ghostaudio | 0:498ee64f952a | 44 | pc.printf("\r %i ", sensors[i]); |
ghostaudio | 0:498ee64f952a | 45 | } |
ghostaudio | 0:498ee64f952a | 46 | pc.printf("\r \n "); |
ghostaudio | 0:498ee64f952a | 47 | } |
ghostaudio | 0:498ee64f952a | 48 | } |