const int PIN_RED = 2;
const int PIN_GREEN = 3;
const int PIN_YELLOW = 4;
const int PIN_PHOTO = A0;
int sensorValue = 0;
int percent = 0;
void setup() {
Serial.begin(9600);
pinMode(PIN_RED, OUTPUT);
pinMode(PIN_GREEN, OUTPUT);
pinMode(PIN_YELLOW, OUTPUT);
}
void loop() {
sensorValue = analogRead(PIN_PHOTO);
percent = map(sensorValue, 0, 1023, 0, 100);
Serial.print("Датчик: ");
Serial.print(sensorValue);
Serial.print(" -> ");
Serial.print(percent);
Serial.println("%");
digitalWrite(PIN_RED, LOW);
digitalWrite(PIN_GREEN, LOW);
digitalWrite(PIN_YELLOW, LOW);
if (percent < 30) {
digitalWrite(PIN_RED, HIGH);
} else if (percent < 60) {
digitalWrite(PIN_GREEN, HIGH);
} else {
digitalWrite(PIN_YELLOW, HIGH);
}
delay(150);
}