pleasedontcode

# LED Control rev_02

Mar 9th, 2026
35
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: # LED Control
  13.     - Version: 002
  14.     - Source Code NOT compiled for: ESP32 DevKit V1
  15.     - Source Code created on: 2026-03-09 18:47:55
  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. // Button1 is connected to GPIO pin 0 (A0 equivalent on ESP32)
  39. const uint8_t Button1_PushButton_PIN_A0 = 0;
  40.  
  41. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  42. // LED1 is connected to GPIO pin 1 (A1 equivalent on ESP32)
  43. const uint8_t LED1_LED_PIN_A1 = 1;
  44.  
  45. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  46. // Create EasyButton instance for Button1
  47. EasyButton button1(Button1_PushButton_PIN_A0);
  48.  
  49. /****** SYSTEM REQUIREMENT 1 *****/
  50. /* When Button1 is pressed, turn on LED1. When */
  51. /* Button1 is released, turn off LED1. */
  52.  
  53. // Callback function to handle Button1 press event
  54. void onButton1Pressed(void)
  55. {
  56.     // Turn on LED1 when button is pressed
  57.     digitalWrite(LED1_LED_PIN_A1, HIGH);
  58. }
  59.  
  60. // Callback function to handle Button1 release event
  61. void onButton1Released(void)
  62. {
  63.     // Turn off LED1 when button is released
  64.     digitalWrite(LED1_LED_PIN_A1, LOW);
  65. }
  66.  
  67. void setup(void)
  68. {
  69.     // put your setup code here, to run once:
  70.  
  71.     // Configure Button1 pin as input with pull-up resistor
  72.     pinMode(Button1_PushButton_PIN_A0, INPUT_PULLUP);
  73.  
  74.     // Configure LED1 pin as output
  75.     pinMode(LED1_LED_PIN_A1, OUTPUT);
  76.  
  77.     // Initialize button1 with default settings
  78.     button1.begin();
  79.    
  80.     // Attach callback functions to button events
  81.     button1.onPressed(onButton1Pressed);
  82.     button1.onReleased(onButton1Released);
  83. }
  84.  
  85.  
  86. void loop(void)
  87. {
  88.     // put your main code here, to run repeatedly:
  89.    
  90.     // Read button state to update internal state machine
  91.     button1.read();
  92. }
  93.  
  94. /* END CODE */
  95.  
Advertisement
Add Comment
Please, Sign In to add comment