From 46049d2c8dd7004e08c18e4eb73a2acc538466b6 Mon Sep 17 00:00:00 2001 From: Alexandre B Date: Tue, 16 Jul 2024 18:25:03 -0400 Subject: [PATCH] Update main.cpp --- ESP32-C3-sm_I2C/src/main.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ESP32-C3-sm_I2C/src/main.cpp b/ESP32-C3-sm_I2C/src/main.cpp index 65656b323..1d13075ea 100644 --- a/ESP32-C3-sm_I2C/src/main.cpp +++ b/ESP32-C3-sm_I2C/src/main.cpp @@ -32,12 +32,18 @@ void TaskStatusLEDCode (void* parameters) { } void TaskLightsAutoCode(void* parameters) { + TickType_t delay = pdMS_TO_TICKS(1000); // Variable for storing delay interval. for (;;) { - if (light_sensor_reading > 1000) + // If lights are dark, then turn lights ON and increase delay interval + if (light_sensor_reading > 1000) { digitalWrite(LIGHTS_PIN, HIGH); - else + delay = pdMS_TO_TICKS(10000); + } + // If lights are bright, then turn lights OFF and decrease delay interval + else { digitalWrite(LIGHTS_PIN, LOW); - vTaskDelay(pdMS_TO_TICKS(5000)); + vTaskDelay(pdMS_TO_TICKS(5000)); + } } }