Advertisement
pleasedontcode

"LED Toggle" rev_01

May 29th, 2024
667
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: ESP32 DevKit V1
  14.     - Source Code created on: 2024-05-29 11:23:17
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* blinking led when preesed button and stops */
  21.     /* blinking when pressed button */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <EasyButton.h>  // https://github.com/evert-arias/EasyButton
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void onButtonPressed();
  31. void updateOutputs();
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t Button1_PushButton_PIN_D4 = 4;
  35.  
  36. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  37. const uint8_t visualFeedbackLED_LED_PIN_D13 = 13;
  38.  
  39. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  40. /***** used to store raw data *****/
  41. bool visualFeedbackLED_LED_PIN_D13_rawData = false;
  42.  
  43. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  44. /***** used to store data after characteristic curve transformation *****/
  45. float visualFeedbackLED_LED_PIN_D13_phyData = 0.0;
  46.  
  47. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  48. EasyButton button(Button1_PushButton_PIN_D4);  // Initialize EasyButton instance
  49.  
  50. void setup(void)
  51. {
  52.   // put your setup code here, to run once:
  53.   Serial.begin(115200);
  54.   Serial.println();
  55.   Serial.println(">>> EasyButton pressed example <<<");
  56.  
  57.   pinMode(Button1_PushButton_PIN_D4, INPUT_PULLUP);
  58.   pinMode(visualFeedbackLED_LED_PIN_D13, OUTPUT);
  59.  
  60.   button.begin();
  61.   button.onPressed(onButtonPressed);
  62. }
  63.  
  64. void loop(void)
  65. {
  66.   // put your main code here, to run repeatedly:
  67.   button.read();  // Continuously read the status of the button
  68.   updateOutputs();  // Refresh output data
  69. }
  70.  
  71. void onButtonPressed()
  72. {
  73.   Serial.println("Button pressed");
  74.   visualFeedbackLED_LED_PIN_D13_rawData = !visualFeedbackLED_LED_PIN_D13_rawData;  // Toggle LED state
  75. }
  76.  
  77. void updateOutputs()
  78. {
  79.   if (visualFeedbackLED_LED_PIN_D13_rawData) {
  80.     // Blinking LED when button is pressed
  81.     digitalWrite(visualFeedbackLED_LED_PIN_D13, HIGH);
  82.     delay(500);
  83.     digitalWrite(visualFeedbackLED_LED_PIN_D13, LOW);
  84.     delay(500);
  85.   } else {
  86.     // Turn off LED when button is not pressed
  87.     digitalWrite(visualFeedbackLED_LED_PIN_D13, LOW);
  88.   }
  89. }
  90.  
  91. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement