|
// Light controller
// by BARRAGAN <http://barraganstudio.com>
int resistorPin = 0; // slider variable connected to analog pin 0
int value = 0; // variable to read the value from the analog pin
void setup()
{
int i;
for(i = 0; i<8; i++)
{
pinMode(i, OUTPUT); // initializes digital pins 0 to 7 as outputs
}
}
void turn_all_off() // function that turns off all the lights
{ // connected on digital pins 0 to 7
int i;
for(i = 0; i < 8; i++)
{
digitalWrite(i, LOW);
}
}
void loop()
{
turn_all_off(); // turns off all lights
value = analogRead(resistorPin); // reads the value of the variable resistor
// connected to analog pin 0.
// posible values are betwwen 0 and 1024
// where 0 corresponds to 0 volts and 1024 to 5 volts
if(value >= 0) // turns on as many lights according to the value read
digitalWrite(0, HIGH);
if(value >= 128)
digitalWrite(1, HIGH);
if(value >= 256)
digitalWrite(2, HIGH);
if(value >= 384)
digitalWrite(3, HIGH);
if(value >= 512)
digitalWrite(4, HIGH);
if(value >= 640)
digitalWrite(5, HIGH);
if(value >= 768)
digitalWrite(6, HIGH);
if(value >= 896)
digitalWrite(7, HIGH);
delay(100); // waits 100 milli seconds for next reading
}
|