pleasedontcode

Debounced Button rev_10

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