/********* 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 Button
- Source Code NOT compiled for: Arduino Opta WiFi
- Source Code created on: 2025-10-05 12:05:27
********* 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 //https://github.com/evert-arias/EasyButton
#ifdef OTA_ENABLED
#include //https://github.com/pleasedontcode/POTA
#endif
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void onButtonPressed(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t button_PushButton_PIN_A0 = A0;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
EasyButton button(button_PushButton_PIN_A0);
#ifdef OTA_ENABLED
POTA ota; // OTA manager (requires credentials configured in secrets.h)
volatile bool ota_trigger_requested = false;
bool ota_initialized = false;
#endif
void onButtonPressed(void)
{
Serial.println("Button pressed"); // Debounced press detected by EasyButton
#ifdef OTA_ENABLED
ota_trigger_requested = true;
#endif
}
void setup(void)
{
// put your setup code here, to run once:
Serial.begin(115200);
// Ensure the input pin uses internal pull-up (pressed is LOW)
pinMode(button_PushButton_PIN_A0, INPUT_PULLUP);
// Initialize EasyButton
button.begin();
button.onPressed(onButtonPressed);
#ifdef OTA_ENABLED
// Optional OTA initialization
// Uncomment and fill credentials to enable OTA updates
// Example (requires secrets.h):
// ota.begin(WIFI_SSID, WIFI_PASSWORD, DEVICE_TYPE, FIRMWARE_VERSION, AUTH_TOKEN, SERVER_SECRET);
// ota_initialized = true;
#endif
}
void loop(void)
{
// Update button state
button.read();
#ifdef OTA_ENABLED
if (ota_trigger_requested)
{
ota_trigger_requested = false;
Serial.println("OTA update requested via button.");
// If OTA is properly configured, perform OTA check/start here.
// This sample intentionally avoids hard-coding credentials.
// Users should configure OTA by uncommenting initialization above
// and calling: ota.checkAndPerformOTA();
}
#endif
// Other non-blocking tasks can be placed here
}
/* END CODE */