A test program for VCNL4020
Dependencies: VCNL4020 mbed vt100
Diff: main.cpp
- Revision:
- 0:7502cb61069c
- Child:
- 1:0891311fabe5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Mar 29 04:42:32 2017 +0000 @@ -0,0 +1,45 @@ +#include "mbed.h" +#include "VCNL4020.h" +#include "MSS.h" +#include "vt100.h" + +#ifndef MSU_VCNL4020_I2C_ADDRESS +#define MSU_VCNL4020_I2C_ADDRESS 0x13 +#endif + +VCNL4020 *vcnl4020 = 0 ; + +vt100 *tty = 0 ; + +int main() { + uint16_t als, prox ; + + tty = new vt100() ; + tty->cls() ; + + vcnl4020 = new VCNL4020(PIN_SDA, PIN_SCL, MSU_VCNL4020_I2C_ADDRESS) ; + vcnl4020->setIrLedCurrent(1) ; /* 10mA for LED */ + vcnl4020->disableAlsPeriodic() ; + vcnl4020->disableProxPeriodic() ; + vcnl4020->disableSelfTimed() ; + + printf("=== test VCNL4020 (%s) %s ===\n", BOARD_NAME, __DATE__) ; + printf("Product ID = %d, Revision = %d\n", + vcnl4020->getProdID(), + vcnl4020->getRevID()) ; + + while(1) { + vcnl4020->trigBothOd() ; /* trigger both ALS and PROX */ + while(vcnl4020->alsDataReady() == 0) { + /* wait for ambient light data ready */ + } + als = vcnl4020->getAls() ; + while(vcnl4020->proxDataReady() == 0) { + /* wait for proximate data ready */ + } + prox = vcnl4020->getProx() ; + printf("VCNL4020 Ambient Light: %d Proximity: %d\n", als, prox) ; + + wait(1) ; + } +} \ No newline at end of file