Casey Lively
/
Nightlight_Seed_Grove_light_sensor
Night light example program utilizing Grove Seed Light Sensor
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /*Graduated Night light with Seed Grove Ambient Light sensor 00002 Casey Lively 00003 March 2016*/ 00004 00005 //Read in ambient light sensor with mbed LPC1768 00006 #include "mbed.h" 00007 00008 AnalogIn sensor(p20);// 00009 BusOut lights(LED1, LED2, LED3, LED4); 00010 00011 int main() { 00012 float val; 00013 float threshold = .03; //User specified for night-light mode. Set to .03 for light measurement mode 00014 while(1) { 00015 val = sensor.read(); 00016 00017 //Uncomment the line below for debugging. 00018 // printf("Sensor reading: %2.2f - %2.2f\r\n", val, (float)(1023-val)*10/val); //print through debug serial connection 00019 00020 if(val <= threshold) 00021 lights = 15; //set all bus lines to 1 00022 else 00023 lights = 0; //set all bus lines to 0 00024 00025 00026 wait(0.1); 00027 }//end while(1) 00028 }//end Main
Generated on Fri Jul 15 2022 21:18:52 by 1.7.2