Advertisement
pleasedontcode

Button LED rev_192

Jan 14th, 2024
61
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 LED
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-01-14 16:10:11
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* if button is pressed so set out to 128. */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Arduino.h>
  25. #include <EasyButton.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t butt_PushButton_PIN_D4 = 4;
  33. const uint8_t dit_PIN_D13 = 13;
  34. const uint8_t ditpullup_PIN_D14 = 14;
  35. const uint8_t ditpulldown_PIN_D16 = 16;
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. EasyButton butt_PushButton(butt_PushButton_PIN_D4);
  39.  
  40. void setup(void)
  41. {
  42.   // Set the pinMode for the output pin
  43.   pinMode(dit_PIN_D13, OUTPUT);
  44.  
  45.   // Set the initial output value to LOW
  46.   digitalWrite(dit_PIN_D13, LOW);
  47.  
  48.   // Initialize the button
  49.   butt_PushButton.begin();
  50. }
  51.  
  52. void loop(void)
  53. {
  54.   // Read the button state
  55.   bool buttonPressed = butt_PushButton.read();
  56.  
  57.   // Check if the button is pressed
  58.   if (buttonPressed) {
  59.     // Set the output to 128
  60.     digitalWrite(dit_PIN_D13, 128);
  61.   } else {
  62.     // Set the output to LOW
  63.     digitalWrite(dit_PIN_D13, LOW);
  64.   }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement