pleasedontcode

# Button Toggle rev_01

Mar 3rd, 2026
38
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 Toggle
  13.     - Version: 001
  14.     - Source Code NOT compiled for: Arduino UNO Q
  15.     - Source Code created on: 2026-03-03 16:03:14
  16.  
  17. ********* Pleasedontcode.com **********/
  18.  
  19. /****** SYSTEM REQUIREMENTS *****/
  20. /****** SYSTEM REQUIREMENT 1 *****/
  21.     /* When Button1 is pressed, turn on LED1. When */
  22.     /* Button1 is released, turn off LED1. */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void onButton1Pressed(void);
  35. void onButton1Released(void);
  36.  
  37. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  38. const uint8_t Button1_PushButton_PIN_A0 = A0;
  39.  
  40. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  41. const uint8_t LED1_LED_PIN_A1 = A1;
  42.  
  43. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  44. // Create an instance of EasyButton for Button1
  45. // Parameters: pin number, debounce time (ms), enable pull-up, active low
  46. EasyButton button1(Button1_PushButton_PIN_A0, 35, true, true);
  47.  
  48. // Callback function triggered when Button1 is pressed
  49. void onButton1Pressed(void)
  50. {
  51.     // Turn on LED1 when button is pressed
  52.     digitalWrite(LED1_LED_PIN_A1, HIGH);
  53. }
  54.  
  55. // Callback function triggered when Button1 is released
  56. void onButton1Released(void)
  57. {
  58.     // Turn off LED1 when button is released
  59.     digitalWrite(LED1_LED_PIN_A1, LOW);
  60. }
  61.  
  62. void setup(void)
  63. {
  64.     // Configure Button1 as input with pull-up
  65.     pinMode(Button1_PushButton_PIN_A0, INPUT_PULLUP);
  66.  
  67.     // Configure LED1 as output
  68.     pinMode(LED1_LED_PIN_A1, OUTPUT);
  69.  
  70.     // Ensure LED1 is off at startup
  71.     digitalWrite(LED1_LED_PIN_A1, LOW);
  72.  
  73.     // Initialize the EasyButton instance
  74.     button1.begin();
  75.  
  76.     // Register callback function for when button is pressed
  77.     button1.onPressed(onButton1Pressed);
  78.  
  79.     // Register callback function for when button is released
  80.     button1.onReleased(onButton1Released);
  81. }
  82.  
  83. void loop(void)
  84. {
  85.     // Continuously read the button status to detect press and release events
  86.     button1.read();
  87. }
  88.  
  89. /* END CODE */
  90.  
Advertisement
Add Comment
Please, Sign In to add comment