Advertisement
pleasedontcode

Button Control rev_02

Apr 25th, 2024
73
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 Control
  13.     - Source Code NOT compiled for: Arduino Nano
  14.     - Source Code created on: 2024-04-25 11:41:27
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Ensure LED diode turns on for 50ms after pressing */
  21.     /* the EasyButton. It should turn off after 50ms, */
  22.     /* even if the button is still pressed. Allow */
  23.     /* reactivation only after a 2s delay. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27.  
  28. #include <EasyButton.h>
  29.  
  30. EasyButton button(Przycisk_PushButton_PIN_D2); // Initialize EasyButton with pin 2
  31.  
  32. unsigned long lastDebounceTime = 0;
  33. unsigned long debounceDelay = 50;
  34. unsigned long reactivateDelay = 2000;
  35. bool ledState = LOW;
  36. bool buttonState = LOW;
  37.  
  38. void setup(void)
  39. {
  40.     // put your setup code here, to run once:
  41.     pinMode(Przycisk_PushButton_PIN_D2, INPUT_PULLUP);
  42.     pinMode(Zawor_LED_PIN_D3, OUTPUT);
  43.  
  44.     button.begin(); // Initialize EasyButton
  45.  
  46. }
  47.  
  48. void loop(void)
  49. {
  50.     // put your main code here, to run repeatedly:
  51.     button.read(); // Read the state of the button
  52.  
  53.     if (button.isPressed()) {
  54.         if (millis() - lastDebounceTime > debounceDelay) {
  55.             lastDebounceTime = millis();
  56.             ledState = HIGH;
  57.             digitalWrite(Zawor_LED_PIN_D3, ledState);
  58.             delay(50);
  59.             ledState = LOW;
  60.             digitalWrite(Zawor_LED_PIN_D3, ledState);
  61.             delay(reactivateDelay);
  62.         }
  63.     }
  64. }
  65.  
  66. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement