Advertisement
pleasedontcode

**LED Toggle** rev_01

Feb 24th, 2025
155
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 Toggle**
  13.     - Source Code NOT compiled for: ESP8266 NodeMCU V1.0
  14.     - Source Code created on: 2025-02-25 02:42:11
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* turns on and turn off the LED when the button is */
  21.     /* pushed */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /* START CODE */
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32. void updateOutputs(void);
  33. void buttonPressed(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t button_PushButton_PIN_D1      = 1;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t led_LED_PIN_D2        = 2;
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. /***** used to store raw data *****/
  43. bool    led_LED_PIN_D2_rawData      = 0;
  44.  
  45. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  46. /***** used to store data after characteristic curve transformation *****/
  47. float   led_LED_PIN_D2_phyData      = 0.0;
  48.  
  49. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  50. EasyButton button(button_PushButton_PIN_D1); // Instantiate EasyButton object
  51.  
  52. void setup(void)
  53. {
  54.     // put your setup code here, to run once:
  55.     pinMode(led_LED_PIN_D2, OUTPUT);
  56.     button.begin(); // Initialize the button
  57.     button.onPressed(buttonPressed); // Attach the button pressed event
  58. }
  59.  
  60. void loop(void)
  61. {
  62.     // put your main code here, to run repeatedly:
  63.     button.read(); // Read the button state
  64.     updateOutputs(); // Refresh output data
  65. }
  66.  
  67. void updateOutputs()
  68. {
  69.     digitalWrite(led_LED_PIN_D2, led_LED_PIN_D2_rawData);
  70. }
  71.  
  72. void buttonPressed()
  73. {
  74.     // Toggle the LED state
  75.     led_LED_PIN_D2_rawData = !led_LED_PIN_D2_rawData;
  76. }
  77.  
  78. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement