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 Detection
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-09-20 14:35:15
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The system shall utilize two push buttons */
- /* connected to digital pins D2 and D3, using the */
- /* EasyButton library for handling button presses */
- /* with pull-up resistors enabled. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Mybut_PushButton_PIN_D2 = 2; // Pin for button 1
- const uint8_t Mybut_PushButton_PIN_D3 = 3; // Pin for button 2
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create EasyButton instances for each button with pull-up resistors enabled
- EasyButton button1(Mybut_PushButton_PIN_D2, 35, true); // Instance for button on pin D2
- EasyButton button2(Mybut_PushButton_PIN_D3, 35, true); // Instance for button on pin D3
- // Function to be called when button1 is pressed
- void onButton1Pressed() {
- Serial.println("Button1 pressed");
- }
- // Function to be called when button2 is pressed
- void onButton2Pressed() {
- Serial.println("Button2 pressed");
- }
- void setup(void)
- {
- // Initialize serial communication for debugging
- Serial.begin(115200);
- // Print a welcome message
- Serial.println();
- Serial.println(">>> EasyButton example <<<");
- // Initialize the button instances
- button1.begin(); // Initialize button1
- button2.begin(); // Initialize button2
- // Set up the button press event handlers
- button1.onPressed(onButton1Pressed); // Set the handler for button1
- button2.onPressed(onButton2Pressed); // Set the handler for button2
- // No need to set pin modes for buttons since EasyButton handles it
- }
- void loop(void)
- {
- // Read the button states
- button1.read(); // Read the state of button1
- button2.read(); // Read the state of button2
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement