test program for VCNL4100 proximity and ambient light sensor

Dependencies:   VCNL4100 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers test_VCNL4100.cpp Source File

test_VCNL4100.cpp

00001 #include "mbed.h"
00002 #include "MSS.h"
00003 #include "VCNL4100.h"
00004 
00005 #define MSU_VCNL4100_I2C_ADDRESS 0x60
00006 VCNL4100 *vcnl4100 = 0 ;
00007 
00008 DigitalOut myled(LED1);
00009 
00010 int main() {
00011     uint8_t psData = 0x00 ;
00012     uint16_t alsData = 0x00 ;
00013     vcnl4100 = new VCNL4100(PIN_SDA, PIN_SCL, MSU_VCNL4100_I2C_ADDRESS) ;
00014     
00015     printf("=== test VCNL4100 for %s (%s)\n", BOARD_NAME, __DATE__) ;
00016     printf("Proximity, Ambient Light\n") ;
00017     
00018     vcnl4100->setAlsConf(0x00) ;
00019     vcnl4100->setPsConf12(0x0000) ;
00020     vcnl4100->setSpo(0xA0) ;
00021     
00022     while(1) {
00023         psData = vcnl4100->getPsData() ;
00024         alsData = vcnl4100->getAlsData() ;
00025         printf("0x%02X, 0x%04X\n", psData, alsData) ;
00026         wait(1);
00027     }
00028 }