Quicksand micro-electronics
/
QW-Ambient-Light
This program demonstrates ambient light sensing on the QW Shields.
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "VCNL4010.h" 00003 00004 DigitalOut LED_0 (PB_6); 00005 DigitalOut LED_1 (PA_7); 00006 DigitalOut LED_2 (PA_6); 00007 DigitalOut LED_3 (PA_5); 00008 00009 //Virtual serial port over USB 00010 Serial pc(USBTX, USBRX); 00011 Serial modem(PA_9, PA_10); 00012 00013 // configure VCNL4010 00014 VCNL40x0 VCNL40x0_Device (PB_9, PB_8, VCNL40x0_ADDRESS); // Define SDA, SCL pin and I2C address 00015 00016 00017 int main() { 00018 00019 LED_0 = 1; 00020 LED_1 = 1; 00021 LED_2 = 1; 00022 LED_3 = 1; 00023 00024 unsigned char ID=0; 00025 unsigned int AmbiValue=0; 00026 00027 // print information on screen 00028 pc.printf("\n\n VCNL4010 Proximity/Ambient Light Sensor"); 00029 pc.printf("\n Read Ambillight on demand in endless loop"); 00030 00031 VCNL40x0_Device.ReadID (&ID); // Read VCNL40x0 product ID revision register 00032 pc.printf("\n\n Product ID Revision Register: %d", ID); 00033 00034 wait_ms(3000); // wait 3s (only for display) 00035 00036 while(1) { 00037 VCNL40x0_Device.ReadAmbiOnDemand (&AmbiValue); // read ambi value on demand 00038 pc.printf("Ambient light: %5.0i cts \tIlluminance: %7.2f lx\r", AmbiValue, AmbiValue/4.0); 00039 if(AmbiValue < 5000) LED_3 = 0; 00040 else LED_3 = 1; 00041 if(AmbiValue < 4000) LED_2 = 0; 00042 else LED_2 = 1; 00043 if(AmbiValue < 3000) LED_1 = 0; 00044 else LED_1 = 1; 00045 if(AmbiValue < 2000) LED_0 = 0; 00046 else LED_0 = 1; 00047 } 00048 }
Generated on Wed Jul 20 2022 23:25:36 by 1.7.2