// This example reads the level of ambient light from a photoresistor. // The photoresistor is connected to analog input pin 1. // The more light is detected, the more leds light up. #define pinPhoto 1 // analog input pin with photoresistor int p; void setup() { for (p=0; p<8; p++) { // set digital pins 0-7 as outputs pinMode(p, OUTPUT); digitalWrite(p, LOW); // and set them "off" } } void loop() { int v = analogRead(pinPhoto); // store analog input in variable v [0-1023] for (p=0; p<8; p++) { // for each connected led if (v > 128 * p) { // switch it "on/off", depending on v digitalWrite(p, HIGH); } else { digitalWrite(p, LOW); } } }