int ldr1 = 13;
int led1 = 16;
int led2 = 17;
int led3 = 5;
int led4 = 18;
int value1 = 0;
int value2 = 0;
void setup() {
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
void loop() {
delay(100);
value1 = analogRead(ldr1);
Serial.print("value1:");
Serial.print(value1);
value2 = map(value1, 500, 3000, 0, 4);
Serial.print(" value2:");
Serial.println(value2);
if (value2 == 4) {
digitalWrite(led1, 0);
digitalWrite(led2, 0);
digitalWrite(led3, 0);
digitalWrite(led4, 0);
} else if (value2 == 3) {
digitalWrite(led1, 1);
digitalWrite(led2, 0);
digitalWrite(led3, 0);
digitalWrite(led4, 0);
} else if (value2 == 2) {
digitalWrite(led1, 1);
digitalWrite(led2, 1);
digitalWrite(led3, 0);
digitalWrite(led4, 0);
} else if (value2 == 1) {
digitalWrite(led1, 1);
digitalWrite(led2, 1);
digitalWrite(led3, 1);
digitalWrite(led4, 0);
} else if (value2 == 0) {
digitalWrite(led1, 1);
digitalWrite(led2, 1);
digitalWrite(led3, 1);
digitalWrite(led4, 1);
}
}