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 Handler
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-09-25 21:25:13
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Implement a button control system using EasyButton */
- /* library for two push buttons connected to digital */
- /* pins D2 and D3, ensuring reliable input handling */
- /* and responsiveness in the Arduino environment. */
- /****** 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 Suman_PushButton_PIN_D2 = 2; // Pin for button 1
- const uint8_t Suman_PushButton_PIN_D3 = 3; // Pin for button 2
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Initialize EasyButton objects for each button
- EasyButton button1(Suman_PushButton_PIN_D2); // Instance for button connected to pin D2
- EasyButton button2(Suman_PushButton_PIN_D3); // Instance for button connected to pin D3
- // Function prototypes for button press actions
- void onButton1Pressed(); // Function to be called when button 1 is pressed
- void onButton2Pressed(); // Function to be called when button 2 is pressed
- void setup(void)
- {
- // Start the serial communication
- Serial.begin(115200);
- // Print a message to the serial monitor
- Serial.println();
- Serial.println(">>> EasyButton multiple buttons example <<<");
- // Initialize the buttons
- button1.begin(); // Initialize button 1
- button2.begin(); // Initialize button 2
- // Attach the onPressed event handlers for each button
- button1.onPressed(onButton1Pressed); // Set the function to be called when button 1 is pressed
- button2.onPressed(onButton2Pressed); // Set the function to be called when button 2 is pressed
- }
- void loop(void)
- {
- // Continuously read the state of the buttons
- button1.read(); // Read the state of button 1
- button2.read(); // Read the state of button 2
- }
- // Function to handle button 1 press event
- void onButton1Pressed() {
- Serial.println("Button 1 pressed"); // Print message to serial monitor
- }
- // Function to handle button 2 press event
- void onButton2Pressed() {
- Serial.println("Button 2 pressed"); // Print message to serial monitor
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement