Advertisement
pleasedontcode

"Button Handling" rev_01

Jun 29th, 2024
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Button Handling"
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2024-06-29 10:09:06
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Create an Arduino project utilizing the PCA9685 */
  21.     /* and EasyButton libraries to manage push buttons on */
  22.     /* pins D2, D3, D4, D5, and D6. Configure pins with */
  23.     /* INPUT_PULLUP and implement a loop function to */
  24.     /* detect and respond to button presses. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <EasyButton.h>  // https://github.com/evert-arias/EasyButton
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t PushButton_PIN_D2 = 2;
  36. const uint8_t PushButton_PIN_D3 = 3;
  37. const uint8_t PushButton_PIN_D4 = 4;
  38. const uint8_t Home_PushButton_PIN_D5 = 5;
  39. const uint8_t Home_PushButton_PIN_D6 = 6;
  40.  
  41. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  42. EasyButton button1(PushButton_PIN_D2);
  43. EasyButton button2(PushButton_PIN_D3);
  44. EasyButton button3(PushButton_PIN_D4);
  45. EasyButton button4(Home_PushButton_PIN_D5);
  46. EasyButton button5(Home_PushButton_PIN_D6);
  47.  
  48. /****** CALLBACK FUNCTIONS *****/
  49. void onButton1Pressed() {
  50.   Serial.println("Button 1 pressed");
  51. }
  52.  
  53. void onButton2Pressed() {
  54.   Serial.println("Button 2 pressed");
  55. }
  56.  
  57. void onButton3Pressed() {
  58.   Serial.println("Button 3 pressed");
  59. }
  60.  
  61. void onButton4Pressed() {
  62.   Serial.println("Button 4 pressed");
  63. }
  64.  
  65. void onButton5Pressed() {
  66.   Serial.println("Button 5 pressed");
  67. }
  68.  
  69. void setup(void) {
  70.   // Initialize Serial for debugging purposes
  71.   Serial.begin(115200);
  72.  
  73.   Serial.println();
  74.   Serial.println(">>> EasyButton multiple buttons example <<<");
  75.  
  76.   // Initialize buttons
  77.   button1.begin();
  78.   button2.begin();
  79.   button3.begin();
  80.   button4.begin();
  81.   button5.begin();
  82.  
  83.   // Attach callback functions
  84.   button1.onPressed(onButton1Pressed);
  85.   button2.onPressed(onButton2Pressed);
  86.   button3.onPressed(onButton3Pressed);
  87.   button4.onPressed(onButton4Pressed);
  88.   button5.onPressed(onButton5Pressed);
  89. }
  90.  
  91. void loop(void) {
  92.   // Continuously read the status of the buttons
  93.   button1.read();
  94.   button2.read();
  95.   button3.read();
  96.   button4.read();
  97.   button5.read();
  98. }
  99.  
  100. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement