A test program for VCNL4020
Dependencies: VCNL4020 mbed vt100
main.cpp@1:0891311fabe5, 2017-04-29 (annotated)
- Committer:
- Rhyme
- Date:
- Sat Apr 29 07:10:01 2017 +0000
- Revision:
- 1:0891311fabe5
- Parent:
- 0:7502cb61069c
Format changed to be compatible with CSV
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 0:7502cb61069c | 1 | #include "mbed.h" |
Rhyme | 0:7502cb61069c | 2 | #include "VCNL4020.h" |
Rhyme | 0:7502cb61069c | 3 | #include "MSS.h" |
Rhyme | 0:7502cb61069c | 4 | #include "vt100.h" |
Rhyme | 0:7502cb61069c | 5 | |
Rhyme | 0:7502cb61069c | 6 | #ifndef MSU_VCNL4020_I2C_ADDRESS |
Rhyme | 0:7502cb61069c | 7 | #define MSU_VCNL4020_I2C_ADDRESS 0x13 |
Rhyme | 0:7502cb61069c | 8 | #endif |
Rhyme | 0:7502cb61069c | 9 | |
Rhyme | 0:7502cb61069c | 10 | VCNL4020 *vcnl4020 = 0 ; |
Rhyme | 0:7502cb61069c | 11 | |
Rhyme | 0:7502cb61069c | 12 | vt100 *tty = 0 ; |
Rhyme | 0:7502cb61069c | 13 | |
Rhyme | 0:7502cb61069c | 14 | int main() { |
Rhyme | 0:7502cb61069c | 15 | uint16_t als, prox ; |
Rhyme | 0:7502cb61069c | 16 | |
Rhyme | 0:7502cb61069c | 17 | tty = new vt100() ; |
Rhyme | 0:7502cb61069c | 18 | tty->cls() ; |
Rhyme | 0:7502cb61069c | 19 | |
Rhyme | 0:7502cb61069c | 20 | vcnl4020 = new VCNL4020(PIN_SDA, PIN_SCL, MSU_VCNL4020_I2C_ADDRESS) ; |
Rhyme | 0:7502cb61069c | 21 | vcnl4020->setIrLedCurrent(1) ; /* 10mA for LED */ |
Rhyme | 0:7502cb61069c | 22 | vcnl4020->disableAlsPeriodic() ; |
Rhyme | 0:7502cb61069c | 23 | vcnl4020->disableProxPeriodic() ; |
Rhyme | 0:7502cb61069c | 24 | vcnl4020->disableSelfTimed() ; |
Rhyme | 0:7502cb61069c | 25 | |
Rhyme | 0:7502cb61069c | 26 | printf("=== test VCNL4020 (%s) %s ===\n", BOARD_NAME, __DATE__) ; |
Rhyme | 0:7502cb61069c | 27 | printf("Product ID = %d, Revision = %d\n", |
Rhyme | 0:7502cb61069c | 28 | vcnl4020->getProdID(), |
Rhyme | 0:7502cb61069c | 29 | vcnl4020->getRevID()) ; |
Rhyme | 1:0891311fabe5 | 30 | printf("Ambient Light, Proximity\n") ; |
Rhyme | 0:7502cb61069c | 31 | |
Rhyme | 0:7502cb61069c | 32 | while(1) { |
Rhyme | 0:7502cb61069c | 33 | vcnl4020->trigBothOd() ; /* trigger both ALS and PROX */ |
Rhyme | 0:7502cb61069c | 34 | while(vcnl4020->alsDataReady() == 0) { |
Rhyme | 0:7502cb61069c | 35 | /* wait for ambient light data ready */ |
Rhyme | 0:7502cb61069c | 36 | } |
Rhyme | 0:7502cb61069c | 37 | als = vcnl4020->getAls() ; |
Rhyme | 0:7502cb61069c | 38 | while(vcnl4020->proxDataReady() == 0) { |
Rhyme | 0:7502cb61069c | 39 | /* wait for proximate data ready */ |
Rhyme | 0:7502cb61069c | 40 | } |
Rhyme | 0:7502cb61069c | 41 | prox = vcnl4020->getProx() ; |
Rhyme | 1:0891311fabe5 | 42 | printf("%6d, %6d\n", als, prox) ; |
Rhyme | 0:7502cb61069c | 43 | |
Rhyme | 0:7502cb61069c | 44 | wait(1) ; |
Rhyme | 0:7502cb61069c | 45 | } |
Rhyme | 0:7502cb61069c | 46 | } |