//7 задание
bool autoMode = true;
bool lastButtonState = HIGH;
unsigned long lastDebounceTime = 0;
const int DEBOUNCE_DELAY = 50;
void setup() {
pinMode(2, INPUT_PULLUP);
pinMode(11, OUTPUT);
}
void loop() {
bool reading = digitalRead(2);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > DEBOUNCE_DELAY) {
if (reading != lastButtonState && reading == LOW) {
autoMode = !autoMode;
}
}
lastButtonState = reading;
int lightLevel = analogRead(A0);
if (autoMode) {
int brightness = map(lightLevel, 0, 1023, 255, 0);
brightness = constrain(brightness, 0, 255);
analogWrite(11, brightness);
} else {
analogWrite(11, 255);
}
delay(100);
}