pleasedontcode

**Smart Control** rev_02

Mar 15th, 2026
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 19.72 KB | None | 0 0
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **Smart Control**
  13.     - Version: 002
  14.     - Source Code NOT compiled for: ESP32S3 Dev Module
  15.     - Source Code created on: 2026-03-15 10:51:11
  16.  
  17. ********* Pleasedontcode.com **********/
  18.  
  19. /****** SYSTEM REQUIREMENTS *****/
  20. /****** SYSTEM REQUIREMENT 1 *****/
  21.     /* Blink LED1 with 1000ms interval (1 second on, 1 */
  22.     /* second off). LED connected to GPIO pin. */
  23. /****** SYSTEM REQUIREMENT 2 *****/
  24.     /* [POTA] Include POTA.h and secrets.h. Init POTA in */
  25.     /* setup() with WiFi creds from secrets.h. Call */
  26.     /* pota.loop() in loop(). */
  27. /****** SYSTEM REQUIREMENT 3 *****/
  28.     /* [POTA] MANDATORY OTA: call */
  29.     /* pota.checkAndPerformOTA() in setup() after */
  30.     /* begin(). Register pota.onOTAAvailable(cb) where cb */
  31.     /* sets a bool flag. In loop() when flag is true call */
  32.     /* pota.restart(). Without OTA the device cannot */
  33.     /* update remotely. */
  34. /****** END SYSTEM REQUIREMENTS *****/
  35.  
  36.  
  37. /****** DEFINITION OF LIBRARIES *****/
  38. #include <POTA.h>
  39. #include "secrets.h"
  40.  
  41. /****** FUNCTION PROTOTYPES *****/
  42. void setup(void);
  43. void loop(void);
  44. void setupDashboard(void);
  45. void setupCallbacks(void);
  46. void setInitialValues(void);
  47. void updateSensorValues(void);
  48. void updateCharts(void);
  49. void otaAvailableCallback(const char* version);
  50.  
  51. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  52. const uint8_t LED1_LED_PIN_D1 = 1;
  53.  
  54. // Interval definition for LED blink (1000ms = 1 second on, 1 second off)
  55. const unsigned long LED_BLINK_INTERVAL = 1000;
  56.  
  57. // POTA instance for OTA management and dashboard
  58. POTA pota;
  59.  
  60. // Flag to track if OTA is available
  61. bool otaAvailable = false;
  62. unsigned long lastLEDToggle = 0;
  63. unsigned long lastSensorUpdate = 0;
  64. const unsigned long SENSOR_UPDATE_INTERVAL = 3000;  // Update sensors every 3 seconds
  65.  
  66. // Widget IDs structure for dashboard management
  67. struct WidgetIDs {
  68.     // Tabs
  69.     uint8_t tabMonitoring;
  70.     uint8_t tabControl;
  71.     uint8_t tabAnalytics;
  72.    
  73.     // Monitoring Tab - Display cards
  74.     uint8_t headerMonitoring;
  75.     uint8_t ledStatusCard;
  76.     uint8_t ledToggleButton;
  77.     uint8_t blinkRateSlider;
  78.     uint8_t systemHealthCard;
  79.     uint8_t statusIndicator;
  80.    
  81.     // Control Tab - Control widgets
  82.     uint8_t headerControl;
  83.     uint8_t ledManualToggle;
  84.     uint8_t blinkFrequencySlider;
  85.     uint8_t ledModeDropdown;
  86.     uint8_t brightnessSlider;
  87.     uint8_t configSeparator;
  88.     uint8_t deviceNameInput;
  89.     uint8_t saveConfigButton;
  90.     uint8_t restartButton;
  91.    
  92.     // Analytics Tab - Charts and trends
  93.     uint8_t headerAnalytics;
  94.     uint8_t ledActivityChart;
  95.     uint8_t uptimeCard;
  96.     uint8_t onOffStatusCard;
  97.     uint8_t systemLogsCard;
  98. } widgets;
  99.  
  100. // System state structure
  101. struct SystemState {
  102.     bool ledActive = false;
  103.     int blinkInterval = 1000;
  104.     int ledBrightness = 100;
  105.     int ledMode = 0;  // 0=Manual, 1=Auto, 2=Blink
  106.     String deviceName = "LED_Blink_Device";
  107.     float uptime = 0.0;  // in seconds
  108.     int toggleCount = 0;
  109.     unsigned long systemStartTime = 0;
  110.    
  111.     // Chart data for activity history
  112.     int activityHistory[12];  // Last 12 measurements
  113.     const char* timeLabels[12] = {
  114.         "00:00", "02:00", "04:00", "06:00", "08:00", "10:00",
  115.         "12:00", "14:00", "16:00", "18:00", "20:00", "22:00"
  116.     };
  117. } systemState;
  118.  
  119. // OTA Callback function - sets flag when OTA is available
  120. void otaAvailableCallback(const char* version) {
  121.     Serial.print("đŸ“Ļ OTA Available! Version: ");
  122.     Serial.println(version);
  123.     otaAvailable = true;  // Set flag to trigger restart in loop
  124. }
  125.  
  126. // Setup dashboard with all widgets and configurations
  127. void setupDashboard() {
  128.     Serial.println("🎨 Setting up LED Control Dashboard...");
  129.    
  130.     // Initialize activity history
  131.     for (int i = 0; i < 12; i++) {
  132.         systemState.activityHistory[i] = random(20, 80);
  133.     }
  134.    
  135.     // ──────────────────────────────────────────────────────────
  136.     // TABS
  137.     // ──────────────────────────────────────────────────────────
  138.     widgets.tabMonitoring = pota.dashboard.addWidget(TAB, "📊 Monitoring");
  139.     widgets.tabControl = pota.dashboard.addWidget(TAB, "âš™ī¸ Control");
  140.     widgets.tabAnalytics = pota.dashboard.addWidget(TAB, "📈 Analytics");
  141.    
  142.     // ──────────────────────────────────────────────────────────
  143.     // TAB 1: MONITORING - Real-time status and controls
  144.     // ──────────────────────────────────────────────────────────
  145.     widgets.headerMonitoring = pota.dashboard.addWidget(SEPARATOR_CARD,
  146.         "💡 LED Status & Quick Control",
  147.         widgets.tabMonitoring,
  148.         "Real-time monitoring of LED status. Quick toggle for immediate control");
  149.    
  150.     // Display current LED status as temperature card (repurposed for visual impact)
  151.     widgets.ledStatusCard = pota.dashboard.addWidget(GENERIC_CARD, "LED Status", widgets.tabMonitoring);
  152.    
  153.     // Quick toggle button for LED on/off
  154.     widgets.ledToggleButton = pota.dashboard.addWidget(TOGGLE_BUTTON_CARD, "LED Power", widgets.tabMonitoring);
  155.    
  156.     // Blink interval control with 100ms precision
  157.     widgets.blinkRateSlider = pota.dashboard.addWidget(SLIDER_CARD, "Blink Interval (ms)", widgets.tabMonitoring, "", 100, 300, 3000);
  158.    
  159.     // System health indicator
  160.     widgets.systemHealthCard = pota.dashboard.addWidget(FEEDBACK_CARD, "System Health", widgets.tabMonitoring);
  161.    
  162.     // Status indicator button (read-only visual)
  163.     widgets.statusIndicator = pota.dashboard.addWidget(INDICATOR_BUTTON_CARD, "Connection Status", widgets.tabMonitoring);
  164.    
  165.     // ──────────────────────────────────────────────────────────
  166.     // TAB 2: CONTROL - Manual LED control and configuration
  167.     // ──────────────────────────────────────────────────────────
  168.     widgets.headerControl = pota.dashboard.addWidget(SEPARATOR_CARD,
  169.         "🔧 LED Control Panel",
  170.         widgets.tabControl,
  171.         "Manual LED control with mode selection, brightness adjustment, and device configuration");
  172.    
  173.     // Manual LED toggle
  174.     widgets.ledManualToggle = pota.dashboard.addWidget(TOGGLE_BUTTON_CARD, "Manual LED Toggle", widgets.tabControl);
  175.    
  176.     // Blink frequency fine-tuning with 50ms precision
  177.     widgets.blinkFrequencySlider = pota.dashboard.addWidget(SLIDER_CARD, "Blink Frequency (ms)", widgets.tabControl, "", 50, 100, 5000);
  178.    
  179.     // LED operating mode selector
  180.     widgets.ledModeDropdown = pota.dashboard.addWidget(DROPDOWN_CARD, "LED Mode", widgets.tabControl, "Manual,Auto,Blink,Pulse");
  181.    
  182.     // LED brightness control (PWM simulation) with 5% steps
  183.     widgets.brightnessSlider = pota.dashboard.addWidget(SLIDER_CARD, "Brightness (%)", widgets.tabControl, "", 5, 0, 100);
  184.    
  185.     // Configuration section separator
  186.     widgets.configSeparator = pota.dashboard.addWidget(SEPARATOR_CARD,
  187.         "âš™ī¸ Device Configuration",
  188.         widgets.tabControl,
  189.         "Configure device name and settings");
  190.    
  191.     // Device name configuration input
  192.     widgets.deviceNameInput = pota.dashboard.addWidget(TEXT_INPUT_CARD, "Device Name", widgets.tabControl);
  193.    
  194.     // Save configuration button
  195.     widgets.saveConfigButton = pota.dashboard.addWidget(PUSH_BUTTON_CARD, "Save Configuration", widgets.tabControl);
  196.    
  197.     // Restart device button with confirmation
  198.     widgets.restartButton = pota.dashboard.addWidget(ACTION_BUTTON_CARD, "Restart Device", widgets.tabControl, "Are you sure?");
  199.    
  200.     // ──────────────────────────────────────────────────────────
  201.     // TAB 3: ANALYTICS - Historical data and trends
  202.     // ──────────────────────────────────────────────────────────
  203.     widgets.headerAnalytics = pota.dashboard.addWidget(SEPARATOR_CARD,
  204.         "📊 System Analytics",
  205.         widgets.tabAnalytics,
  206.         "Historical LED activity, uptime tracking, and system performance metrics");
  207.    
  208.     // LED activity history chart (line chart showing on/off cycles)
  209.     widgets.ledActivityChart = pota.dashboard.addWidget(LINE_CHART, "LED Activity (24h)", widgets.tabAnalytics);
  210.    
  211.     // Uptime display in hours
  212.     widgets.uptimeCard = pota.dashboard.addWidget(ENERGY_CARD, "System Uptime (hours)", widgets.tabAnalytics);
  213.    
  214.     // Current on/off status progress
  215.     widgets.onOffStatusCard = pota.dashboard.addWidget(PROGRESS_CARD, "LED ON Time (%)", widgets.tabAnalytics, "", 1, 0, 100);
  216.    
  217.     // System logs / status message display
  218.     widgets.systemLogsCard = pota.dashboard.addWidget(GENERIC_CARD, "Last Event", widgets.tabAnalytics);
  219.    
  220.     Serial.println("✅ All dashboard widgets created!");
  221.    
  222.     // Set initial values for all widgets
  223.     setInitialValues();
  224.    
  225.     // Setup callbacks for widget interactions
  226.     setupCallbacks();
  227. }
  228.  
  229. // Initialize dashboard widgets with default values
  230. void setInitialValues() {
  231.     Serial.println("📝 Setting initial widget values...");
  232.    
  233.     // Monitoring Tab initial values
  234.     pota.dashboard.setValue(widgets.ledStatusCard, "LED OFF");
  235.     pota.dashboard.setValue(widgets.ledToggleButton, systemState.ledActive);
  236.     pota.dashboard.setValue(widgets.blinkRateSlider, systemState.blinkInterval);
  237.     pota.dashboard.setValue(widgets.systemHealthCard, STATUS_SUCCESS);
  238.     pota.dashboard.setValue(widgets.statusIndicator, STATUS_SUCCESS);
  239.    
  240.     // Control Tab initial values
  241.     pota.dashboard.setValue(widgets.ledManualToggle, systemState.ledActive);
  242.     pota.dashboard.setValue(widgets.blinkFrequencySlider, systemState.blinkInterval);
  243.     pota.dashboard.setValue(widgets.ledModeDropdown, "Manual");
  244.     pota.dashboard.setValue(widgets.brightnessSlider, systemState.ledBrightness);
  245.     pota.dashboard.setValue(widgets.deviceNameInput, systemState.deviceName);
  246.    
  247.     // Analytics Tab initial values
  248.     pota.dashboard.setValue(widgets.uptimeCard, 0.0);
  249.     pota.dashboard.setValue(widgets.onOffStatusCard, 50);
  250.     pota.dashboard.setValue(widgets.systemLogsCard, "System initialized");
  251.    
  252.     // Initialize activity chart
  253.     pota.dashboard.setX(widgets.ledActivityChart, systemState.timeLabels, 12);
  254.     pota.dashboard.setY(widgets.ledActivityChart, systemState.activityHistory, 12);
  255.    
  256.     Serial.println("✅ Initial values set!");
  257. }
  258.  
  259. // Register callbacks for all dashboard widget interactions
  260. void setupCallbacks() {
  261.     Serial.println("🔗 Setting up widget callbacks...");
  262.    
  263.     // ──── MONITORING TAB CALLBACKS ────
  264.    
  265.     // LED Toggle callback - Toggle LED on/off
  266.     pota.dashboard.onUpdate(widgets.ledToggleButton, [](WidgetData data) {
  267.         systemState.ledActive = data.getBool();
  268.         digitalWrite(LED1_LED_PIN_D1, systemState.ledActive ? HIGH : LOW);
  269.        
  270.         Serial.print("💡 LED Toggle: ");
  271.         Serial.println(systemState.ledActive ? "ON" : "OFF");
  272.        
  273.         // Update status display
  274.         pota.dashboard.setValue(widgets.ledStatusCard, systemState.ledActive ? "LED ON" : "LED OFF");
  275.         pota.dashboard.setValue(widgets.ledManualToggle, systemState.ledActive);
  276.        
  277.         systemState.toggleCount++;
  278.     });
  279.    
  280.     // Blink rate slider callback - Adjust blink interval
  281.     pota.dashboard.onUpdate(widgets.blinkRateSlider, [](WidgetData data) {
  282.         systemState.blinkInterval = data.getInt();
  283.        
  284.         Serial.print("âąī¸ Blink Interval: ");
  285.         Serial.print(systemState.blinkInterval);
  286.         Serial.println(" ms");
  287.        
  288.         pota.dashboard.setValue(widgets.blinkFrequencySlider, systemState.blinkInterval);
  289.     });
  290.    
  291.     // ──── CONTROL TAB CALLBACKS ────
  292.    
  293.     // Manual toggle from control tab
  294.     pota.dashboard.onUpdate(widgets.ledManualToggle, [](WidgetData data) {
  295.         systemState.ledActive = data.getBool();
  296.         digitalWrite(LED1_LED_PIN_D1, systemState.ledActive ? HIGH : LOW);
  297.        
  298.         Serial.print("🔘 Manual Toggle: ");
  299.         Serial.println(systemState.ledActive ? "ON" : "OFF");
  300.        
  301.         // Sync with monitoring tab
  302.         pota.dashboard.setValue(widgets.ledToggleButton, systemState.ledActive);
  303.         pota.dashboard.setValue(widgets.ledStatusCard, systemState.ledActive ? "LED ON" : "LED OFF");
  304.        
  305.         systemState.toggleCount++;
  306.     });
  307.    
  308.     // Blink frequency slider callback
  309.     pota.dashboard.onUpdate(widgets.blinkFrequencySlider, [](WidgetData data) {
  310.         systemState.blinkInterval = data.getInt();
  311.        
  312.         Serial.print("đŸŽšī¸ Blink Frequency: ");
  313.         Serial.print(systemState.blinkInterval);
  314.         Serial.println(" ms");
  315.        
  316.         pota.dashboard.setValue(widgets.blinkRateSlider, systemState.blinkInterval);
  317.     });
  318.    
  319.     // LED Mode dropdown callback
  320.     pota.dashboard.onUpdate(widgets.ledModeDropdown, [](WidgetData data) {
  321.         String mode = data.getString();
  322.        
  323.         Serial.print("📋 LED Mode: ");
  324.         Serial.println(mode);
  325.        
  326.         if (mode == "Manual") {
  327.             systemState.ledMode = 0;
  328.         } else if (mode == "Auto") {
  329.             systemState.ledMode = 1;
  330.         } else if (mode == "Blink") {
  331.             systemState.ledMode = 2;
  332.         } else if (mode == "Pulse") {
  333.             systemState.ledMode = 3;
  334.         }
  335.     });
  336.    
  337.     // Brightness slider callback
  338.     pota.dashboard.onUpdate(widgets.brightnessSlider, [](WidgetData data) {
  339.         systemState.ledBrightness = data.getInt();
  340.        
  341.         Serial.print("🔆 Brightness: ");
  342.         Serial.print(systemState.ledBrightness);
  343.         Serial.println("%");
  344.        
  345.         // If LED is active, apply brightness (PWM simulation)
  346.         if (systemState.ledActive) {
  347.             analogWrite(LED1_LED_PIN_D1, (systemState.ledBrightness * 255) / 100);
  348.         }
  349.     });
  350.    
  351.     // Save configuration button callback
  352.     pota.dashboard.onUpdate(widgets.saveConfigButton, [](WidgetData data) {
  353.         Serial.println("💾 Configuration saved!");
  354.         Serial.print("   Device Name: ");
  355.         Serial.println(systemState.deviceName);
  356.         Serial.print("   Blink Interval: ");
  357.         Serial.print(systemState.blinkInterval);
  358.         Serial.println(" ms");
  359.         Serial.print("   Brightness: ");
  360.         Serial.print(systemState.ledBrightness);
  361.         Serial.println("%");
  362.        
  363.         pota.dashboard.setValue(widgets.systemHealthCard, STATUS_SUCCESS);
  364.     });
  365.    
  366.     // Device name input callback
  367.     pota.dashboard.onUpdate(widgets.deviceNameInput, [](WidgetData data) {
  368.         systemState.deviceName = data.getString();
  369.        
  370.         Serial.print("📛 Device Name Updated: ");
  371.         Serial.println(systemState.deviceName);
  372.     });
  373.    
  374.     // Restart button callback with confirmation
  375.     pota.dashboard.onUpdate(widgets.restartButton, [](WidgetData data) {
  376.         Serial.println("🔄 Restart button pressed!");
  377.         Serial.println("   Device will restart in 2 seconds...");
  378.        
  379.         pota.dashboard.setValue(widgets.systemLogsCard, "Device restarting...");
  380.         pota.dashboard.setValue(widgets.systemHealthCard, STATUS_INFO);
  381.        
  382.         delay(2000);
  383.         ESP.restart();
  384.     });
  385.    
  386.     Serial.println("✅ All callbacks registered!");
  387. }
  388.  
  389. // Update sensor values and chart data
  390. void updateSensorValues() {
  391.     if (millis() - lastSensorUpdate < SENSOR_UPDATE_INTERVAL) {
  392.         return;
  393.     }
  394.     lastSensorUpdate = millis();
  395.    
  396.     // Calculate uptime in hours
  397.     systemState.uptime = (millis() - systemState.systemStartTime) / 3600000.0;
  398.    
  399.     // Update uptime display
  400.     pota.dashboard.setValue(widgets.uptimeCard, systemState.uptime);
  401.    
  402.     // Update LED ON time percentage (simulated)
  403.     int onTimePercent = systemState.ledActive ? 75 : 25;
  404.     pota.dashboard.setValue(widgets.onOffStatusCard, onTimePercent);
  405.    
  406.     // Update activity history for chart
  407.     for (int i = 0; i < 11; i++) {
  408.         systemState.activityHistory[i] = systemState.activityHistory[i + 1];
  409.     }
  410.     systemState.activityHistory[11] = onTimePercent;
  411.    
  412.     // Update chart
  413.     updateCharts();
  414.    
  415.     // Update status message
  416.     String statusMsg = "LED: " + String(systemState.ledActive ? "ON" : "OFF");
  417.     statusMsg += " | Toggles: " + String(systemState.toggleCount);
  418.     pota.dashboard.setValue(widgets.systemLogsCard, statusMsg);
  419.    
  420.     Serial.print("📊 Uptime: ");
  421.     Serial.print(systemState.uptime, 1);
  422.     Serial.print("h | Toggles: ");
  423.     Serial.println(systemState.toggleCount);
  424. }
  425.  
  426. // Update chart data
  427. void updateCharts() {
  428.     // Update LED activity chart with current activity history
  429.     pota.dashboard.setX(widgets.ledActivityChart, systemState.timeLabels, 12);
  430.     pota.dashboard.setY(widgets.ledActivityChart, systemState.activityHistory, 12);
  431. }
  432.  
  433. // Arduino setup function - Initialize hardware and POTA
  434. void setup(void) {
  435.     Serial.begin(115200);
  436.     delay(2000);
  437.    
  438.     // Initialize LED pin as OUTPUT
  439.     pinMode(LED1_LED_PIN_D1, OUTPUT);
  440.     digitalWrite(LED1_LED_PIN_D1, LOW);
  441.    
  442.     Serial.println("\n╔════════════════════════════════════════╗");
  443.     Serial.println("║         LED_Blink with POTA OTA       ║");
  444.     Serial.println("║        Dashboard Integration          â•‘");
  445.     Serial.println("╚════════════════════════════════════════╝\n");
  446.    
  447.     Serial.println("🔧 Initializing POTA...");
  448.    
  449.     // Initialize POTA with WiFi credentials from secrets.h
  450.     POTAError err = pota.begin(
  451.         DEVICE_TYPE,           // Device type from secrets.h
  452.         FIRMWARE_VERSION,      // Firmware version from secrets.h
  453.         AUTH_TOKEN,            // Authentication token from secrets.h
  454.         SERVER_SECRET,         // Server secret from secrets.h
  455.         WIFI_SSID,             // WiFi SSID from secrets.h
  456.         WIFI_PASSWORD          // WiFi password from secrets.h
  457.     );
  458.    
  459.     if (err != POTAError::SUCCESS) {
  460.         Serial.print("❌ POTA initialization failed: ");
  461.         Serial.println(POTA::errorToString(err));
  462.         return;
  463.     }
  464.    
  465.     Serial.println("✅ POTA initialized successfully!");
  466.    
  467.     // MANDATORY OTA: Check for available OTA updates after begin()
  468.     Serial.println("🔍 Checking for OTA updates...");
  469.     POTAError otaErr = pota.checkAndPerformOTA();
  470.    
  471.     if (otaErr == POTAError::NO_UPDATE_AVAILABLE) {
  472.         Serial.println("â„šī¸ No OTA update available - running latest version");
  473.     } else if (otaErr != POTAError::SUCCESS) {
  474.         Serial.print("âš ī¸ OTA check result: ");
  475.         Serial.println(POTA::errorToString(otaErr));
  476.     }
  477.    
  478.     // Register OTA available callback - callback sets otaAvailable flag
  479.     pota.onOTAAvailable(otaAvailableCallback);
  480.    
  481.     // Register dashboard setup callback
  482.     pota.dashboard.setWidgetConfigCallback(setupDashboard);
  483.    
  484.     // Record system start time
  485.     systemState.systemStartTime = millis();
  486.    
  487.     Serial.println("✅ Setup complete!");
  488.     Serial.println("🌐 Connect to POTA dashboard for remote control\n");
  489. }
  490.  
  491. // Arduino loop function - Main program execution
  492. void loop(void) {
  493.     // Call POTA loop for WiFi, OTA, and dashboard management
  494.     pota.loop();
  495.    
  496.     // MANDATORY OTA: Check if OTA is available and restart
  497.     if (otaAvailable) {
  498.         Serial.println("🔄 OTA available - initiating restart...");
  499.         pota.restart();
  500.         // After restart, the device will download and install the update
  501.         otaAvailable = false;
  502.     }
  503.    
  504.     // LED blinking logic based on mode and interval
  505.     if (systemState.ledMode == 2 && systemState.ledActive) {
  506.         // Blink mode: Toggle LED on/off
  507.         if (millis() - lastLEDToggle >= systemState.blinkInterval) {
  508.             lastLEDToggle = millis();
  509.             systemState.ledActive = !systemState.ledActive;
  510.             digitalWrite(LED1_LED_PIN_D1, systemState.ledActive ? HIGH : LOW);
  511.         }
  512.     } else if (systemState.ledMode == 0) {
  513.         // Manual mode: LED controlled by toggle buttons (no automatic changes)
  514.         digitalWrite(LED1_LED_PIN_D1, systemState.ledActive ? HIGH : LOW);
  515.     } else if (systemState.ledMode == 1) {
  516.         // Auto mode: LED blinks continuously at specified interval
  517.         if (millis() - lastLEDToggle >= systemState.blinkInterval) {
  518.             lastLEDToggle = millis();
  519.             digitalWrite(LED1_LED_PIN_D1, digitalRead(LED1_LED_PIN_D1) ? LOW : HIGH);
  520.         }
  521.     } else if (systemState.ledMode == 3) {
  522.         // Pulse mode: Simulate PWM pulse effect
  523.         if (systemState.ledActive) {
  524.             analogWrite(LED1_LED_PIN_D1, (systemState.ledBrightness * 255) / 100);
  525.         } else {
  526.             digitalWrite(LED1_LED_PIN_D1, LOW);
  527.         }
  528.     }
  529.    
  530.     // Update sensor values and dashboard periodically
  531.     updateSensorValues();
  532. }
  533.  
  534. /* END CODE */
  535.  
Advertisement
Add Comment
Please, Sign In to add comment