Advertisement
pleasedontcode

LED Control rev_01

Oct 29th, 2024
108
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.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-10-29 10:29:04
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* when push button turn on else turn off */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29.  
  30. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  31. const uint8_t pushbutonled_PushButton_PIN_D4        = 4; // Pin for the push button
  32. const uint8_t led_PIN = 13; // Pin for the LED (change as needed)
  33.  
  34. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  35. // Initialize the EasyButton object with the defined pin.
  36. // The default debounce time and pullup settings will be used.
  37. EasyButton button(pushbutonled_PushButton_PIN_D4);
  38.  
  39. void onPressed()
  40. {
  41.     Serial.println("Button pressed"); // Callback function to be called when the button is pressed.
  42.     digitalWrite(led_PIN, HIGH); // Turn on the LED when the button is pressed.
  43. }
  44.  
  45. void onReleased()
  46. {
  47.     Serial.println("Button released"); // Callback function to be called when the button is released.
  48.     digitalWrite(led_PIN, LOW); // Turn off the LED when the button is released.
  49. }
  50.  
  51. void setup(void)
  52. {
  53.     // Initialize Serial for debugging purposes.
  54.     Serial.begin(115200);
  55.     Serial.println();
  56.     Serial.println(">>> EasyButton pressed example <<<");
  57.  
  58.     // Set the LED pin as OUTPUT.
  59.     pinMode(led_PIN, OUTPUT);
  60.  
  61.     // Initialize the button.
  62.     button.begin();
  63.     // Add the callback functions to be called when the button is pressed and released.
  64.     button.onPressed(onPressed);
  65.     button.onReleased(onReleased);
  66. }
  67.  
  68. void loop(void)
  69. {
  70.     // Continuously read the status of the button.
  71.     button.read();
  72. }
  73.  
  74. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement