Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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: "Button Wake"
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-09-21 20:28:42
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The project shall implement a mailbox notification */
- /* system using a reed switch and a push button, */
- /* leveraging the EasyButton library for efficient */
- /* state management on pin D4. Then enter deep sleep */
- /* until pressed again */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* The project shall implement a mailbox alert */
- /* mechanism using a reed switch and a push button, */
- /* use tillow leveraging the EasyButton library for */
- /* efficient state handling on pin D4, and shall */
- /* enter deep sleep mode until reactivated by the */
- /* button. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> // https://github.com/evert-arias/EasyButton
- #include "esp_sleep.h" // Include ESP32 sleep library
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Reedswitch_PushButton_PIN_D4 = 4;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
- // Create an instance of EasyButton for the pin defined above
- EasyButton button(Reedswitch_PushButton_PIN_D4);
- /****** SETUP FUNCTION *****/
- void setup(void)
- {
- // Initialize Serial for debugging purposes
- Serial.begin(115200);
- Serial.println();
- Serial.println(">>> EasyButton Mailbox Notification System <<<");
- // Initialize the button
- button.begin(); // Initialize the EasyButton instance
- // Add a callback function to be called when the button is pressed
- button.onPressed([]() {
- Serial.println("Button pressed, exiting deep sleep.");
- esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL); // Disable all wakeup sources
- });
- // Set the pin mode for the button (optional if using EasyButton's internal pull-up)
- pinMode(Reedswitch_PushButton_PIN_D4, INPUT_PULLUP);
- // Enter deep sleep mode
- Serial.println("Entering deep sleep mode...");
- esp_deep_sleep_start(); // Start deep sleep
- }
- /****** LOOP FUNCTION *****/
- void loop(void)
- {
- // Continuously read the status of the button
- button.read(); // Read the button state
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement