Advertisement
pleasedontcode

Button Handler rev_01

Sep 22nd, 2024
73
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 Handler
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-09-22 23:32:47
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Implemente um sistema de controle de botões usando */
  21.     /* a biblioteca EasyButton para gerenciar três botões */
  22.     /* de pressão nos pinos digitais D2, D3 e D4, */
  23.     /* garantindo um tratamento de entrada confiável para */
  24.     /* interações do usuário no projeto Arduino. */
  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 atirador_PushButton_PIN_D2        = 2;
  36. const uint8_t atirador_PushButton_PIN_D3        = 3;
  37. const uint8_t atirador_PushButton_PIN_D4        = 4;
  38.  
  39. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  40. // Instantiate EasyButton objects for each button
  41. EasyButton button1(atirador_PushButton_PIN_D2);
  42. EasyButton button2(atirador_PushButton_PIN_D3);
  43. EasyButton button3(atirador_PushButton_PIN_D4);
  44.  
  45. // Function prototypes for button press events
  46. void onButton1Pressed();
  47. void onButton2Pressed();
  48. void onButton3Pressed();
  49.  
  50. /****** SETUP FUNCTION *****/
  51. void setup(void)
  52. {
  53.     // Start the serial communication
  54.     Serial.begin(115200);
  55.  
  56.     // Print a message to the Serial Monitor
  57.     Serial.println();
  58.     Serial.println(">>> EasyButton multiple buttons example <<<");
  59.  
  60.     // Initialize buttons
  61.     button1.begin();
  62.     button2.begin();
  63.     button3.begin();
  64.  
  65.     // Attach event handlers for button presses
  66.     button1.onPressed(onButton1Pressed);
  67.     button2.onPressed(onButton2Pressed);
  68.     button3.onPressed(onButton3Pressed);
  69. }
  70.  
  71. /****** LOOP FUNCTION *****/
  72. void loop(void)
  73. {
  74.     // Read the state of each button
  75.     button1.read();
  76.     button2.read();
  77.     button3.read();
  78. }
  79.  
  80. /****** BUTTON PRESS HANDLERS *****/
  81. // Function to handle button 1 press
  82. void onButton1Pressed() {
  83.     Serial.println("Button 1 pressed");
  84. }
  85.  
  86. // Function to handle button 2 press
  87. void onButton2Pressed() {
  88.     Serial.println("Button 2 pressed");
  89. }
  90.  
  91. // Function to handle button 3 press
  92. void onButton3Pressed() {
  93.     Serial.println("Button 3 pressed");
  94. }
  95.  
  96. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement