Created
October 3, 2013 16:23
-
-
Save h4ck4life/6812646 to your computer and use it in GitHub Desktop.
Light Sensor + LED chaser. Read more here:
http://alif.my/2013/10/project-3-light-sensor-led-chaser/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int photoRPin = 0; | |
int minLight; | |
int maxLight; | |
int lightLevel; | |
int adjustedLightLevel; | |
void setup(){ | |
//Setup the starting light level limits | |
lightLevel=analogRead(photoRPin); | |
minLight=lightLevel-20; | |
maxLight=lightLevel; | |
pinMode(12, OUTPUT); | |
pinMode(11, OUTPUT); | |
pinMode(10, OUTPUT); | |
pinMode(9, OUTPUT); | |
pinMode(8, OUTPUT); | |
} | |
void loop(){ | |
//auto-adjust the minimum and maximum limits in real time | |
lightLevel=analogRead(photoRPin); | |
Serial.println(lightLevel); | |
if(lightLevel < 20) { playLED(); } else { stopLED(); } | |
//slow down the transmission for effective Serial communication. | |
delay(50); | |
} | |
void playLED() { | |
digitalWrite(12,HIGH); | |
delay(100); | |
digitalWrite(12,LOW); | |
delay(25); | |
digitalWrite(11,HIGH); | |
delay(100); | |
digitalWrite(11,LOW); | |
delay(25); | |
digitalWrite(10,HIGH); | |
delay(100); | |
digitalWrite(10,LOW); | |
delay(25); | |
digitalWrite(9,HIGH); | |
delay(100); | |
digitalWrite(9,LOW); | |
delay(25); | |
digitalWrite(8, HIGH); | |
delay(100); | |
digitalWrite(8, LOW); | |
delay(25); | |
} | |
void stopLED() { | |
digitalWrite(12,LOW); | |
digitalWrite(11,LOW); | |
digitalWrite(10,LOW); | |
digitalWrite(9,LOW); | |
digitalWrite(8, LOW); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment