Advertisement
pleasedontcode

LED Toggle rev_01

Oct 11th, 2024
80
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: Arduino Uno
  14.     - Source Code created on: 2024-10-11 11:37:35
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The system shall detect button presses on a push */
  21.     /* button connected to pin D2 and control an LED */
  22.     /* connected to pin D3, using the EasyButton library */
  23.     /* for efficient button handling and state */
  24.     /* management. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs(void); // Function prototype for updating outputs
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t Button_PushButton_PIN_D2      = 2;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t led_LED_PIN_D3        = 3;
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. /***** used to store raw data *****/
  43. bool    led_LED_PIN_D3_rawData      = 0;
  44.  
  45. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  46. /***** used to store data after characteristic curve transformation *****/
  47. float   led_LED_PIN_D3_phyData      = 0.0;
  48.  
  49. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  50. // Initialize the EasyButton object for the push button
  51. EasyButton button(Button_PushButton_PIN_D2);
  52.  
  53. /****** FUNCTION DEFINITIONS *****/
  54. void setup(void)
  55. {
  56.     // Set the button pin as input with pull-up resistor
  57.     pinMode(Button_PushButton_PIN_D2, INPUT_PULLUP);
  58.  
  59.     // Set the LED pin as output
  60.     pinMode(led_LED_PIN_D3, OUTPUT);
  61.  
  62.     // Initialize the button
  63.     button.begin();
  64.     // Attach the onPressed event to the button
  65.     button.onPressed([]() {
  66.         led_LED_PIN_D3_rawData = !led_LED_PIN_D3_rawData; // Toggle the LED state
  67.     });
  68. }
  69.  
  70. void loop(void)
  71. {
  72.     // Read the button state
  73.     button.read(); // Read the button state
  74.     updateOutputs(); // Refresh output data
  75. }
  76.  
  77. void updateOutputs()
  78. {
  79.     // Write the LED state
  80.     digitalWrite(led_LED_PIN_D3, led_LED_PIN_D3_rawData); // Write the LED state
  81. }
  82.  
  83. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement