pleasedontcode

Pushbutton Update rev_09

Oct 5th, 2025
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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: Pushbutton Update
  13.     - Source Code NOT compiled for: Arduino Opta WiFi
  14.     - Source Code created on: 2025-10-05 15:03:02
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Detect a debounced push-button event on A0 using */
  21.     /* EasyButton; the input uses INPUT_PULLUP, so a */
  22.     /* pressed state is LOW and should trigger the system */
  23.     /* logic. Integrate flash over the air. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <EasyButton.h>  // https://github.com/evert-arias/EasyButton
  31. #include <POTA.h>         // https://github.com/pleasedontcode/POTA
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36. void buttonPressedOTA();
  37.  
  38. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  39. const uint8_t button_PushButton_PIN_A0 = A0;
  40.  
  41. /****** DEFINITION OF LIBRARIES CLASS INSTANCES******/
  42. EasyButton button(button_PushButton_PIN_A0);
  43. POTA ota;
  44.  
  45. /*
  46.   Callback invoked when the button is pressed.
  47.   Triggers a POTA OTA check/perform.
  48. */
  49. void buttonPressedOTA()
  50. {
  51.   Serial.println("A0 button pressed - attempting OTA");
  52.   // Attempt OTA update using POTA
  53.   POTAError err = ota.checkAndPerformOTA();
  54.   if (err == POTAError::NO_UPDATE_AVAILABLE)
  55.   {
  56.     Serial.println("OTA: No update available");
  57.   }
  58.   else if (err != POTAError::SUCCESS)
  59.   {
  60.     Serial.print("OTA error: ");
  61.     Serial.println(ota.errorToString(err));
  62.   }
  63.   else
  64.   {
  65.     Serial.println("OTA update started or completed");
  66.   }
  67. }
  68.  
  69. void setup(void)
  70. {
  71.   Serial.begin(115200);
  72.   Serial.println();
  73.   Serial.println("POTA OTA on A0 button (debounced) example");
  74.  
  75.   // Configure the input with internal pull-up to match system requirement
  76.   pinMode(button_PushButton_PIN_A0, INPUT_PULLUP);
  77.  
  78.   // Initialize the button debouncer
  79.   button.begin();
  80.  
  81.   // Attach press event
  82.   button.onPressed(buttonPressedOTA);
  83. }
  84.  
  85. void loop(void)
  86. {
  87.   // Update button state (debouncing handled by library)
  88.   button.read();
  89.   // You may add small delay here if desired
  90. }
  91.  
  92. /* END CODE */
  93.  
Advertisement
Add Comment
Please, Sign In to add comment