Advertisement
pleasedontcode

EasyButton LED rev_01

May 12th, 2024
555
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: EasyButton LED
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-05-12 13:23:36
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Turns on and off a light emitting diode(LED), when */
  21.     /* pressing a digital button through api calls */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <EasyButton.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void updateOutputs(void);
  31.  
  32. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  33. const uint8_t LED_PIN_D4 = 4;
  34. const uint8_t BUTTON_PIN = 2; // Assuming the button is connected to pin 2
  35.  
  36. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  37. bool LED_PIN_D4_rawData = false;
  38.  
  39. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  40. float LED_PIN_D4_phyData = 0.0;
  41.  
  42. // Define the EasyButton object for the button
  43. EasyButton button(BUTTON_PIN);
  44.  
  45. void setup(void)
  46. {
  47.     // put your setup code here, to run once:
  48.     pinMode(LED_PIN_D4, OUTPUT);
  49.  
  50.     // Initialize the button
  51.     button.begin();
  52. }
  53.  
  54. void loop(void)
  55. {
  56.     // put your main code here, to run repeatedly:
  57.     button.update(); // Update the button state
  58.  
  59.     // Check if the button is pressed
  60.     if (button.read())
  61.     {
  62.         // Toggle the LED state
  63.         LED_PIN_D4_rawData = !LED_PIN_D4_rawData;
  64.         updateOutputs(); // Update the LED state
  65.     }
  66. }
  67.  
  68. void updateOutputs(void)
  69. {
  70.     digitalWrite(LED_PIN_D4, LED_PIN_D4_rawData);
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement