Lights up to 4 LEDs based on ambient light levels. Uses Grove Seeed Light Sensor

Dependencies:   mbed

Fork of Seeed_Grove_Shield_Light_Sensor by Seeed

Files at this revision

API Documentation at this revision

Comitter:
clively6
Date:
Wed Mar 16 17:38:22 2016 +0000
Parent:
2:76004e9cf0cc
Commit message:
test

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 76004e9cf0cc -r 15c1934a8316 main.cpp
--- a/main.cpp	Sat Aug 16 00:20:04 2014 +0000
+++ b/main.cpp	Wed Mar 16 17:38:22 2016 +0000
@@ -1,32 +1,45 @@
-/* Copyright (c) 2010-2011 mbed.org, MIT License
-*
-* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
-* and associated documentation files (the "Software"), to deal in the Software without
-* restriction, including without limitation the rights to use, copy, modify, merge, publish,
-* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
-* Software is furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice shall be included in all copies or
-* substantial portions of the Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
-* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
 
+/*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(A1);
-DigitalOut myled(LED1);
+AnalogIn sensor(p20);//
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(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();
         printf("Sensor reading: %2.2f - %2.2f\r\n", val, (float)(1023-val)*10/val);
-        myled = !myled;
-        wait(0.5);
-    }
-}
+        
+        if(val <= threshold)
+             led4 = 1;
+        else
+            led4 = 0;
+        
+        if(val <= 0.1)
+            led3 = 1;
+        else
+            led3 = 0;
+            
+        if(val <= 0.35)
+            led2 = 1;
+        else
+            led2 = 0;
+            
+        if(val <= 0.55)
+            led1 = 1;
+        else
+            led1 = 0;
+        
+       
+        wait(0.1);
+    }//end while(1)
+}//end Main