Advertisement
pleasedontcode

LED Blink rev_01

Oct 22nd, 2024
138
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 Blink
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-10-22 19:14:18
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* po naciśnieciu mrugaj */
  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 switch_PushButton_PIN_D4 = 4; // Button pin
  32. const uint8_t led_PIN = 13; // LED pin (usually built-in on many boards)
  33.  
  34. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  35. // Instance of the button, initialized with the pin number and default parameters
  36. EasyButton button(switch_PushButton_PIN_D4); // Using the constructor of EasyButton
  37.  
  38. void setup(void)
  39. {
  40.     // put your setup code here, to run once:
  41.     Serial.begin(115200); // Initialize Serial communication for debugging
  42.     Serial.println(">>> EasyButton example <<<");
  43.  
  44.     // Initialize the button
  45.     button.begin(); // Set up the button
  46.     button.onPressed([]() { // Lambda function to handle button press
  47.         Serial.println("Button pressed");
  48.         // Blink the LED when the button is pressed
  49.         for (int i = 0; i < 5; i++) { // Blink 5 times
  50.             digitalWrite(led_PIN, HIGH); // Turn on LED
  51.             delay(100); // Keep LED on for 100 milliseconds
  52.             digitalWrite(led_PIN, LOW); // Turn off LED
  53.             delay(100); // Keep LED off for 100 milliseconds
  54.         }
  55.     });
  56.  
  57.     pinMode(switch_PushButton_PIN_D4, INPUT_PULLUP); // Set the button pin as input with pull-up resistor
  58.     pinMode(led_PIN, OUTPUT); // Set the LED pin as output
  59. }
  60.  
  61. void loop(void)
  62. {
  63.     // put your main code here, to run repeatedly:
  64.     button.read(); // Continuously read the button state
  65. }
  66.  
  67. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement