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 Handling
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-06-03 10:57:32
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Develop an Arduino project using EasyButton */
- /* library to manage three push buttons connected to */
- /* pins D2, D3, and D4. The project should initialize */
- /* these pins with INPUT_PULLUP mode and include */
- /* basic setup and loop functions. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> // https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void onButton1Pressed(void);
- void onButton2Pressed(void);
- void onButton3Pressed(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t mani_PushButton_PIN_D2 = 2;
- const uint8_t mani_PushButton_PIN_D3 = 3;
- const uint8_t mani_PushButton_PIN_D4 = 4;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- EasyButton button1(mani_PushButton_PIN_D2); // Initialize EasyButton object for button 1
- EasyButton button2(mani_PushButton_PIN_D3); // Initialize EasyButton object for button 2
- EasyButton button3(mani_PushButton_PIN_D4); // Initialize EasyButton object for button 3
- void setup(void)
- {
- // Initialize serial communication at 115200 baud rate
- Serial.begin(115200);
- Serial.println();
- Serial.println(">>> EasyButton multiple buttons example <<<");
- // Initialize buttons
- button1.begin();
- button2.begin();
- button3.begin();
- // Attach callback functions to be called when buttons are pressed
- button1.onPressed(onButton1Pressed);
- button2.onPressed(onButton2Pressed);
- button3.onPressed(onButton3Pressed);
- }
- void loop(void)
- {
- // Continuously read the button states
- button1.read();
- button2.read();
- button3.read();
- }
- // Callback function for button 1 press
- void onButton1Pressed(void)
- {
- Serial.println("Button1 pressed");
- }
- // Callback function for button 2 press
- void onButton2Pressed(void)
- {
- Serial.println("Button2 pressed");
- }
- // Callback function for button 3 press
- void onButton3Pressed(void)
- {
- Serial.println("Button3 pressed");
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement