const int LDR_PIN = A0;
const int LED_COUNT = 8;
int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
void setup() {
// put your setup code here, to run once:
for(int i=0; i<LED_COUNT; i++){
pinMode(ledPins[i], OUTPUT);
}
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int sensorValue = analogRead(LDR_PIN);
int brightness = map(sensorValue, 0 , 1015, 0, LED_COUNT);
for(int i=0; i<LED_COUNT; i++){
if(i<brightness){
digitalWrite(ledPins[i], HIGH);
} else {
digitalWrite(ledPins[i], LOW);
}
}
Serial.println(sensorValue);
delay(100);
}