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 Mega
- - Source Code created on: 2024-06-29 10:09:06
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Create an Arduino project utilizing the PCA9685 */
- /* and EasyButton libraries to manage push buttons on */
- /* pins D2, D3, D4, D5, and D6. Configure pins with */
- /* INPUT_PULLUP and implement a loop function to */
- /* detect and respond to button presses. */
- /****** 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 PushButton_PIN_D2 = 2;
- const uint8_t PushButton_PIN_D3 = 3;
- const uint8_t PushButton_PIN_D4 = 4;
- const uint8_t Home_PushButton_PIN_D5 = 5;
- const uint8_t Home_PushButton_PIN_D6 = 6;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- EasyButton button1(PushButton_PIN_D2);
- EasyButton button2(PushButton_PIN_D3);
- EasyButton button3(PushButton_PIN_D4);
- EasyButton button4(Home_PushButton_PIN_D5);
- EasyButton button5(Home_PushButton_PIN_D6);
- /****** CALLBACK FUNCTIONS *****/
- void onButton1Pressed() {
- Serial.println("Button 1 pressed");
- }
- void onButton2Pressed() {
- Serial.println("Button 2 pressed");
- }
- void onButton3Pressed() {
- Serial.println("Button 3 pressed");
- }
- void onButton4Pressed() {
- Serial.println("Button 4 pressed");
- }
- void onButton5Pressed() {
- Serial.println("Button 5 pressed");
- }
- void setup(void) {
- // Initialize Serial for debugging purposes
- Serial.begin(115200);
- Serial.println();
- Serial.println(">>> EasyButton multiple buttons example <<<");
- // Initialize buttons
- button1.begin();
- button2.begin();
- button3.begin();
- button4.begin();
- button5.begin();
- // Attach callback functions
- button1.onPressed(onButton1Pressed);
- button2.onPressed(onButton2Pressed);
- button3.onPressed(onButton3Pressed);
- button4.onPressed(onButton4Pressed);
- button5.onPressed(onButton5Pressed);
- }
- void loop(void) {
- // Continuously read the status of the buttons
- button1.read();
- button2.read();
- button3.read();
- button4.read();
- button5.read();
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement