Advertisement
pleasedontcode

"Button Wake" rev_01

Sep 21st, 2024
101
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: "Button Wake"
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-09-21 20:28:42
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The project shall implement a mailbox notification */
  21.     /* system using a reed switch and a push button, */
  22.     /* leveraging the EasyButton library for efficient */
  23.     /* state management on pin D4. Then enter deep sleep */
  24.     /* until pressed again */
  25. /****** SYSTEM REQUIREMENT 2 *****/
  26.     /* The project shall implement a mailbox alert */
  27.     /* mechanism using a reed switch and a push button, */
  28.     /* use tillow leveraging the EasyButton library for */
  29.     /* efficient state handling on pin D4, and shall */
  30.     /* enter deep sleep mode until reactivated by the */
  31.     /* button. */
  32. /****** END SYSTEM REQUIREMENTS *****/
  33.  
  34. /****** DEFINITION OF LIBRARIES *****/
  35. #include <EasyButton.h> // https://github.com/evert-arias/EasyButton
  36. #include "esp_sleep.h"   // Include ESP32 sleep library
  37.  
  38. /****** FUNCTION PROTOTYPES *****/
  39. void setup(void);
  40. void loop(void);
  41.  
  42. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  43. const uint8_t Reedswitch_PushButton_PIN_D4 = 4;
  44.  
  45. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  46. // Create an instance of EasyButton for the pin defined above
  47. EasyButton button(Reedswitch_PushButton_PIN_D4);
  48.  
  49. /****** SETUP FUNCTION *****/
  50. void setup(void)
  51. {
  52.     // Initialize Serial for debugging purposes
  53.     Serial.begin(115200);
  54.     Serial.println();
  55.     Serial.println(">>> EasyButton Mailbox Notification System <<<");
  56.  
  57.     // Initialize the button
  58.     button.begin(); // Initialize the EasyButton instance
  59.  
  60.     // Add a callback function to be called when the button is pressed
  61.     button.onPressed([]() {
  62.         Serial.println("Button pressed, exiting deep sleep.");
  63.         esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL); // Disable all wakeup sources
  64.     });
  65.  
  66.     // Set the pin mode for the button (optional if using EasyButton's internal pull-up)
  67.     pinMode(Reedswitch_PushButton_PIN_D4, INPUT_PULLUP);
  68.  
  69.     // Enter deep sleep mode
  70.     Serial.println("Entering deep sleep mode...");
  71.     esp_deep_sleep_start(); // Start deep sleep
  72. }
  73.  
  74. /****** LOOP FUNCTION *****/
  75. void loop(void)
  76. {
  77.     // Continuously read the status of the button
  78.     button.read(); // Read the button state
  79. }
  80.  
  81. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement