/********* 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: Pushbutton Update
- Source Code NOT compiled for: Arduino Opta WiFi
- Source Code created on: 2025-10-05 15:03:02
********* 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> // https://github.com/evert-arias/EasyButton
#include <POTA.h> // https://github.com/pleasedontcode/POTA
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void buttonPressedOTA();
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t button_PushButton_PIN_A0 = A0;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES******/
EasyButton button(button_PushButton_PIN_A0);
POTA ota;
/*
Callback invoked when the button is pressed.
Triggers a POTA OTA check/perform.
*/
void buttonPressedOTA()
{
Serial.println("A0 button pressed - attempting OTA");
// Attempt OTA update using POTA
POTAError err = ota.checkAndPerformOTA();
if (err == POTAError::NO_UPDATE_AVAILABLE)
{
Serial.println("OTA: No update available");
}
else if (err != POTAError::SUCCESS)
{
Serial.print("OTA error: ");
Serial.println(ota.errorToString(err));
}
else
{
Serial.println("OTA update started or completed");
}
}
void setup(void)
{
Serial.begin(115200);
Serial.println();
Serial.println("POTA OTA on A0 button (debounced) example");
// Configure the input with internal pull-up to match system requirement
pinMode(button_PushButton_PIN_A0, INPUT_PULLUP);
// Initialize the button debouncer
button.begin();
// Attach press event
button.onPressed(buttonPressedOTA);
}
void loop(void)
{
// Update button state (debouncing handled by library)
button.read();
// You may add small delay here if desired
}
/* END CODE */