Advertisement
pleasedontcode

Toggle Button rev_01

May 3rd, 2024
542
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: Toggle Button
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-05-03 07:29:03
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* turn on when the push button is on */
  21. /****** SYSTEM REQUIREMENT 2 *****/
  22.     /* turn on when the push button is on */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <EasyButton.h>
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31. void updateOutputs(void);
  32.  
  33. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  34. const uint8_t LED_LED_PIN_D4 = 4;
  35. const uint8_t PUSH_BUTTON_PIN = 2; // Define the push button pin
  36.  
  37. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  38. bool LED_LED_PIN_D4_rawData = false;
  39.  
  40. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  41. float LED_LED_PIN_D4_phyData = 0.0;
  42.  
  43. // Create an EasyButton object for the push button
  44. EasyButton pushButton(PUSH_BUTTON_PIN);
  45.  
  46. void setup(void)
  47. {
  48.     // put your setup code here, to run once:
  49.     pinMode(LED_LED_PIN_D4, OUTPUT);
  50.  
  51.     // Initialize the push button
  52.     pushButton.begin();
  53. }
  54.  
  55. void loop(void)
  56. {
  57.     // put your main code here, to run repeatedly:
  58.     updateOutputs(); // Refresh output data
  59.  
  60.     // Update the push button state
  61.     pushButton.update();
  62.  
  63.     // Check if the push button is pressed
  64.     if (pushButton.read())
  65.     {
  66.         // Toggle the LED state when the push button is pressed
  67.         LED_LED_PIN_D4_rawData = !LED_LED_PIN_D4_rawData;
  68.     }
  69. }
  70.  
  71. void updateOutputs(void)
  72. {
  73.     digitalWrite(LED_LED_PIN_D4, LED_LED_PIN_D4_rawData);
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement