/************************************************
Created by Giorgio MilellaLight Sensitive Lamp version 1.03 LEDs1 Light SensorSeptember, 30 2010
************************************************/
int LED_0 = 11;//declare LED pin
int LED_1 = 10;//declare LED pin
int LED_2 = 9;//declare LED pin
int LSR = 0;//Declare Sensor pin
int valLED_0 = 255; //Set Dim to maximum
int valLED_1 = 1; //Set Dim to 1
int valLED_2 = 1; //Set Dim to 1
int i = 0; //declare counter and set it to 0
void setup(){
pinMode(LED_0, OUTPUT); //Declare LED pin as output
pinMode(LED_1, OUTPUT); //Declare LED pin as output
pinMode(LED_2, OUTPUT); //Declare LED pin as output
pinMode (LSR, INPUT); //Declare Sensor pin as input
Serial.begin(9600); //Serial begin
}
void loop(){
int senVal = analogRead(LSR);//read value from pin 0(sensor)
i += 1; //starts counter
if (i < 255) {
valLED_0 -= 1;//decrease LED value
valLED_1 += 1;//increase LED value
valLED_2 = 1;//set LED value to 1
} else if (i < 508) {
valLED_0 = 1; //set LED value to 1
valLED_1 -= 1; //decrease LED value
valLED_2 += 1;//increase LED value
} else if (i < 761) {
valLED_0 += 1;//increase LED value
valLED_1 = 1; //set LED value to 1
valLED_2 -= 1;//decrease LED value
} else {
i = 1;
}
analogWrite(LED_0, valLED_0);//Set LED value
analogWrite(LED_1, valLED_1); //Set LED value
analogWrite(LED_2, valLED_2);//Set LED value
int wait = map (senVal, 0, 1023, 1, 100) ;//map sensor
delay(wait); //set delay to mapped value
Serial.println(senVal);//print sensor value
}
Comments
You can follow this conversation by subscribing to the comment feed for this post.