Найдите все строки с ошибками (ошибки компиляции и/или логические и/или синтаксические) в приведенном коде системы умного освещения с датчиками движения и освещенности. В ответе укажите строки по возрастанию
01: #include
02: #include
03: #include
04:
05: #define PIR_PIN 2
06: #define LDR_PIN A0
07: #define LED_STRIP_PIN 5
08: #define BUTTON_PIN 4
09:
10: const char* ssid = "SmartHome";
11: const char* password = "12345678";
12:
13: WebServer server(80);
14:
15: int lightLevel = 0;
16: bool motionDetected = false;
17: bool autoMode = true;
18: int brightness = 255;
19: unsigned long lastMotionTime = 0;
20: const unsigned long motionTimeout = 30000;
21:
22: void setup() {
23: Serial.begin(115200);
24:
25: pinMode(PIR_PIN, INPUT);
26: pinMode(LDR_PIN, INPUT);
27: pinMode(LED_STRIP_PIN, OUTPUT);
28: pinMode(BUTTON_PIN, INPUT_PULLUP);
29:
30: WiFi.begin(ssid, password);
31: while (WiFi.status() != WL_CONNECTED) {
32: delay(1000);
33: Serial.print(".");
34: }
35:
36: Serial.println("WiFi connected");
37: Serial.print("IP: ");
38: Serial.println(WiFi.localIP());
39:
40: server.on("/", handleRoot);
41: server.on("/api/status", handleStatus);
42: server.on("/api/control", HTTP_POST, handleControl);
43: server.begin();
44: }
45:
46: void loop() {
47: server.handleClient();
48:
49: readSensors();
50: handleButton();
51:
52: if (autoMode) {
53: autoControl();
54: }
55:
56: delay(100);
57: }
58:
59: void readSensors() {
60: motionDetected = digitalRead(PIR_PIN);
61: lightLevel = analogRead(LDR_PIN);
62:
63: if (motionDetected) {
64: lastMotionTime = millis();
65: }
66: }
67:
68: void autoControl() {
69: bool shouldTurnOn = false;
70:
71: if (motionDetected && lightLevel < 500) {
72: shouldTurnOn = true;
73: }
74:
75: if (millis() - lastMotionTime > motionTimeout && lightLevel > 500) {
76: shouldTurnOn = true;
77: }
78:
79: if (shouldTurnOn) {
80: analogWrite(LED_STRIP_PIN, brightness);
81: } else {
82: analogWrite(LED_STRIP_PIN, 0);
83: }
84: }
85:
86: void handleButton() {
87: static bool lastButtonState = HIGH;
88: bool currentButtonState = digitalRead(BUTTON_PIN);
89:
90: if (lastButtonState == HIGH && currentButtonState == LOW) {
91: autoMode = !autoMode;
92: Serial.println(autoMode ? "Auto mode ON" : "Auto mode OFF");
93: }
94:
95: lastButtonState = currentButtonState;
96: }
97:
98: void handleRoot() {
99: server.send(200, "text/html", "Smart Lighting System
");
100: }
Ответ нейросети
21 октября 2025 15:19
Понравился ответ?
Задай свой вопрос
Напиши любую задачу или вопрос, а нейросеть её решит



