Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Debounced OTA
- - Source Code NOT compiled for: Arduino Opta WiFi
- - Source Code created on: 2025-10-05 11:38:35
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Detect a debounced push-button event on A0 using */
- /* EasyButton; the input uses INPUT_PULLUP, so a */
- /* pressed state is LOW and should trigger the system */
- /* logic. Integrate flash over the air. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h>
- #include <POTA.h>
- #if __has_include("secrets.h")
- #include "secrets.h"
- #define SECRETS_AVAILABLE 1
- #else
- #define SECRETS_AVAILABLE 0
- #endif
- POTA ota;
- /** Pin definitions **/
- const uint8_t button_PushButton_PIN_A0 = A0;
- // Instance of EasyButton for the debounced push-button on A0
- EasyButton button(button_PushButton_PIN_A0);
- /** Prototypes **/
- void onButtonPressed();
- void performOTAIfConfigured();
- void setup(void);
- void loop(void);
- void setup(void)
- {
- // Initialize serial for debugging
- Serial.begin(115200);
- // Small delay to ensure serial is ready
- delay(100);
- Serial.println("POTA EasyButton debounced button on A0 - OTA integration test");
- // Use INPUT_PULLUP for the push-button as required by the system requirements
- pinMode(button_PushButton_PIN_A0, INPUT_PULLUP);
- // Initialize the button handling
- button.begin();
- button.onPressed(onButtonPressed);
- #if SECRETS_AVAILABLE
- Serial.println("Secrets detected. Initializing OTA may occur on button press.");
- ota.begin(WIFI_SSID, WIFI_PASSWORD, DEVICE_TYPE, FIRMWARE_VERSION, AUTH_TOKEN, SERVER_SECRET);
- #endif
- }
- void loop(void)
- {
- // Regularly update the button state (debounce handled internally by EasyButton)
- button.read();
- #if SECRETS_AVAILABLE
- // Optional: allow OTA background processing if the library supports it
- ota.checkAndPerformOTA();
- #endif
- }
- void onButtonPressed()
- {
- Serial.println("Button pressed (A0) - debounced.");
- performOTAIfConfigured();
- }
- void performOTAIfConfigured()
- {
- #if SECRETS_AVAILABLE
- Serial.println("Starting OTA check (POTA) via OTA library...");
- ota.checkAndPerformOTA();
- #else
- Serial.println("OTA not configured. Include secrets.h to enable OTA.");
- #endif
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment