Advertisement
pleasedontcode

"Button Detection" rev_01

Jun 22nd, 2024
603
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 Uno
  14.     - Source Code created on: 2024-06-22 07:54:36
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop a flight management system using */
  21.     /* EasyButton library to handle button inputs. The */
  22.     /* system should initialize a push button on pin D2 */
  23.     /* and manage its states to trigger specific flight */
  24.     /* operations. */
  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. void onPressed();  // Callback function for button press
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t pushbutton_PIN_D2 = 2;
  37.  
  38. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  39. EasyButton button(pushbutton_PIN_D2);  // Initialize EasyButton object
  40.  
  41. void onPressed()
  42. {
  43.   Serial.println("Button pressed");  // Print message when button is pressed
  44. }
  45.  
  46. void setup(void)
  47. {
  48.   // put your setup code here, to run once:
  49.   Serial.begin(115200);  // Initialize serial communication
  50.   Serial.println();
  51.   Serial.println(">>> EasyButton pressed example <<<");
  52.  
  53.   button.begin();  // Initialize the button
  54.   button.onPressed(onPressed);  // Attach the callback function
  55. }
  56.  
  57. void loop(void)
  58. {
  59.   // put your main code here, to run repeatedly:
  60.   button.read();  // Read the button state
  61. }
  62.  
  63. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement