Night light example program utilizing Grove Seed Light Sensor

Dependencies:   mbed

main.cpp

Committer:
clively6
Date:
2016-03-16
Revision:
0:176019ee8c91

File content as of revision 0:176019ee8c91:

/*Graduated Night light with Seed Grove Ambient Light sensor
Casey Lively
March 2016*/

//Read in ambient light sensor with mbed LPC1768
#include "mbed.h"

AnalogIn sensor(p20);//
BusOut lights(LED1, LED2, LED3, LED4);

int main() {
    float val;
    float threshold = .03; //User specified for night-light mode. Set to .03 for light measurement mode
    while(1) {
        val = sensor.read();
        
        //Uncomment the line below for debugging.
       // printf("Sensor reading: %2.2f - %2.2f\r\n", val, (float)(1023-val)*10/val); //print through debug serial connection
        
        if(val <= threshold)
            lights = 15; //set all bus lines to 1
        else
            lights = 0; //set all bus lines to 0
        
       
        wait(0.1);
    }//end while(1)
}//end Main