Advertisement
pleasedontcode

Button LED rev_01

Mar 4th, 2024
102
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: Button LED
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-04 22:51:19
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* led turns on for 0,5s after activating a button */
  21.     /* and turns off even when the button is still active */
  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 onPressedForDuration();
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t przycisk_PushButton_PIN_D2 = 2;
  34.  
  35. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  36. const uint8_t lampka_LED_PIN_D3 = 3;
  37.  
  38. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  39. /***** used to store raw data *****/
  40. bool lampka_LED_PIN_D3_rawData = 0;
  41.  
  42. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  43. /***** used to store data after characteristic curve transformation *****/
  44. float lampka_LED_PIN_D3_phyData = 0.0;
  45.  
  46. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  47. EasyButton button(przycisk_PushButton_PIN_D2);
  48.  
  49. void setup(void)
  50. {
  51.   // put your setup code here, to run once:
  52.   pinMode(przycisk_PushButton_PIN_D2, INPUT_PULLUP);
  53.   pinMode(lampka_LED_PIN_D3, OUTPUT);
  54.  
  55.   button.begin();
  56.   button.onPressedFor(2000, onPressedForDuration);
  57. }
  58.  
  59. void loop(void)
  60. {
  61.   // put your main code here, to run repeatedly:
  62.   button.read(); // Continuously read the status of the button
  63.   updateOutputs(); // Refresh output data
  64. }
  65.  
  66. void updateOutputs()
  67. {
  68.   digitalWrite(lampka_LED_PIN_D3, lampka_LED_PIN_D3_rawData);
  69. }
  70.  
  71. void onPressedForDuration()
  72. {
  73.   // Code to be executed when the button is pressed for the given duration.
  74.   digitalWrite(lampka_LED_PIN_D3, HIGH); // Turn on the LED
  75.   delay(500); // Keep the LED on for 0.5 seconds
  76.   digitalWrite(lampka_LED_PIN_D3, LOW); // Turn off the LED
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement