Night light example program utilizing Grove Seed Light Sensor

Dependencies:   mbed

Committer:
clively6
Date:
Wed Mar 16 16:28:40 2016 +0000
Revision:
0:176019ee8c91
test;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
clively6 0:176019ee8c91 1 /*Graduated Night light with Seed Grove Ambient Light sensor
clively6 0:176019ee8c91 2 Casey Lively
clively6 0:176019ee8c91 3 March 2016*/
clively6 0:176019ee8c91 4
clively6 0:176019ee8c91 5 //Read in ambient light sensor with mbed LPC1768
clively6 0:176019ee8c91 6 #include "mbed.h"
clively6 0:176019ee8c91 7
clively6 0:176019ee8c91 8 AnalogIn sensor(p20);//
clively6 0:176019ee8c91 9 BusOut lights(LED1, LED2, LED3, LED4);
clively6 0:176019ee8c91 10
clively6 0:176019ee8c91 11 int main() {
clively6 0:176019ee8c91 12 float val;
clively6 0:176019ee8c91 13 float threshold = .03; //User specified for night-light mode. Set to .03 for light measurement mode
clively6 0:176019ee8c91 14 while(1) {
clively6 0:176019ee8c91 15 val = sensor.read();
clively6 0:176019ee8c91 16
clively6 0:176019ee8c91 17 //Uncomment the line below for debugging.
clively6 0:176019ee8c91 18 // printf("Sensor reading: %2.2f - %2.2f\r\n", val, (float)(1023-val)*10/val); //print through debug serial connection
clively6 0:176019ee8c91 19
clively6 0:176019ee8c91 20 if(val <= threshold)
clively6 0:176019ee8c91 21 lights = 15; //set all bus lines to 1
clively6 0:176019ee8c91 22 else
clively6 0:176019ee8c91 23 lights = 0; //set all bus lines to 0
clively6 0:176019ee8c91 24
clively6 0:176019ee8c91 25
clively6 0:176019ee8c91 26 wait(0.1);
clively6 0:176019ee8c91 27 }//end while(1)
clively6 0:176019ee8c91 28 }//end Main