Advertisement
pleasedontcode

Button Detection rev_01

Oct 25th, 2024
85
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 Detection
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2024-10-25 20:59:04
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* i have a project that i will use Arduino Mega 2560 */
  21.     /* and i will connect 1 number of Atlas Scientific */
  22.     /* 8:1 serial port extender to the serial 1 (Tx0 Rx0) */
  23.     /* port, and i will connect 8 devises of PZEM004T to */
  24.     /* the 8:1 serial port expander in order to monitor 2 */
  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 multiplexer_PushButton_PIN_D2     = 2;
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. // Initialize the EasyButton object for the button connected to pin D2
  39. EasyButton button1(multiplexer_PushButton_PIN_D2);
  40.  
  41. /****** FUNCTION DEFINITIONS *****/
  42. void onButton1Pressed() {
  43.   Serial.println("Button1 pressed"); // Callback function for button press
  44. }
  45.  
  46. void setup(void)
  47. {
  48.     // Start serial communication for debugging
  49.     Serial.begin(115200);
  50.    
  51.     // Initialize the button pin as INPUT_PULLUP
  52.     pinMode(multiplexer_PushButton_PIN_D2, INPUT_PULLUP);
  53.  
  54.     // Initialize the EasyButton instance
  55.     button1.begin();
  56.    
  57.     // Attach the onPressed callback function to button1
  58.     button1.onPressed(onButton1Pressed);
  59. }
  60.  
  61. void loop(void)
  62. {
  63.     // Continuously read the button state
  64.     button1.read();
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement