|
// Light Equalizer
// by Ana Lucía Martínez Arias
int distance=0;
int i=0;
void turn_all_off() // function to turn off all the lights
{
int i;
for(i=0; i<10; i++) //LEDS connected to digital pins 0 to 9
{
digitalWrite(i, LOW);
}
}
void setup(){
Serial.begin(9600); // sets the serial port to 9600
for (i=0; i<10; i++){
pinMode(i, OUTPUT);
}
pinMode(48,OUTPUT);
digitalWrite(48,HIGH);
}
void loop(){
turn_all_off(); // turns all lights off
distance = analogRead(0); // sensor connected to analog pin 0
Serial.println(distance, DEC); // prints the value read from the sensor
if((distance>50)){
digitalWrite(0, HIGH); // sets the current light on
}
if((distance>100)){
digitalWrite(1, HIGH); // sets the current light on
}
if((distance>150)){
digitalWrite(2, HIGH); // sets the current light on
}
if((distance>200)){
digitalWrite(3, HIGH); // sets the current light on
}
if((distance>250)){
digitalWrite(4, HIGH); // sets the current light on
}
if((distance>300)){
digitalWrite(5, HIGH); // sets the current light on
}
if((distance>350)){
digitalWrite(6, HIGH); // sets the current light on
}
if((distance>400)){
digitalWrite(7, HIGH); // sets the current light on
}
if((distance>450)){
digitalWrite(8, HIGH); // sets the current light on
}
if((distance>500)){
digitalWrite(9, HIGH); // sets the current light on
}
delay(50);
}
|