pleasedontcode

Debounced OTA rev_04

Oct 5th, 2025
77
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 OTA
  13.     - Source Code NOT compiled for: Arduino Opta WiFi
  14.     - Source Code created on: 2025-10-05 11:38:35
  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>
  31. #include <POTA.h>
  32.  
  33. #if __has_include("secrets.h")
  34. #include "secrets.h"
  35. #define SECRETS_AVAILABLE 1
  36. #else
  37. #define SECRETS_AVAILABLE 0
  38. #endif
  39.  
  40. POTA ota;
  41.  
  42. /** Pin definitions **/
  43. const uint8_t button_PushButton_PIN_A0 = A0;
  44.  
  45. // Instance of EasyButton for the debounced push-button on A0
  46. EasyButton button(button_PushButton_PIN_A0);
  47.  
  48. /** Prototypes **/
  49. void onButtonPressed();
  50. void performOTAIfConfigured();
  51.  
  52. void setup(void);
  53. void loop(void);
  54.  
  55. void setup(void)
  56. {
  57.   // Initialize serial for debugging
  58.   Serial.begin(115200);
  59.   // Small delay to ensure serial is ready
  60.   delay(100);
  61.  
  62.   Serial.println("POTA EasyButton debounced button on A0 - OTA integration test");
  63.  
  64.   // Use INPUT_PULLUP for the push-button as required by the system requirements
  65.   pinMode(button_PushButton_PIN_A0, INPUT_PULLUP);
  66.  
  67.   // Initialize the button handling
  68.   button.begin();
  69.   button.onPressed(onButtonPressed);
  70.  
  71. #if SECRETS_AVAILABLE
  72.   Serial.println("Secrets detected. Initializing OTA may occur on button press.");
  73.   ota.begin(WIFI_SSID, WIFI_PASSWORD, DEVICE_TYPE, FIRMWARE_VERSION, AUTH_TOKEN, SERVER_SECRET);
  74. #endif
  75. }
  76.  
  77. void loop(void)
  78. {
  79.   // Regularly update the button state (debounce handled internally by EasyButton)
  80.   button.read();
  81.  
  82. #if SECRETS_AVAILABLE
  83.   // Optional: allow OTA background processing if the library supports it
  84.   ota.checkAndPerformOTA();
  85. #endif
  86. }
  87.  
  88. void onButtonPressed()
  89. {
  90.   Serial.println("Button pressed (A0) - debounced.");
  91.   performOTAIfConfigured();
  92. }
  93.  
  94. void performOTAIfConfigured()
  95. {
  96. #if SECRETS_AVAILABLE
  97.   Serial.println("Starting OTA check (POTA) via OTA library...");
  98.   ota.checkAndPerformOTA();
  99. #else
  100.   Serial.println("OTA not configured. Include secrets.h to enable OTA.");
  101. #endif
  102. }
  103.  
  104. /* END CODE */
  105.  
Advertisement
Add Comment
Please, Sign In to add comment