Advertisement
pleasedontcode

Button Control rev_02

Mar 4th, 2024
138
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 compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-04 22:52:54
  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 <Arduino.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup();
  29. void loop();
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t przycisk_PushButton_PIN_D2 = 2;
  33.  
  34. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  35. const uint8_t lampka_LED_PIN_D3 = 3;
  36.  
  37. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  38. bool lampka_LED_PIN_D3_rawData = false;
  39.  
  40. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  41. float lampka_LED_PIN_D3_phyData = 0.0;
  42.  
  43. void setup()
  44. {
  45.     pinMode(przycisk_PushButton_PIN_D2, INPUT_PULLUP);
  46.     pinMode(lampka_LED_PIN_D3, OUTPUT);
  47. }
  48.  
  49. void loop()
  50. {
  51.     // put your main code here, to run repeatedly:
  52.    
  53.     if (digitalRead(przycisk_PushButton_PIN_D2) == LOW)
  54.     {
  55.         digitalWrite(lampka_LED_PIN_D3, HIGH); // turn on the LED
  56.         delay(500); // wait for 0.5 seconds
  57.         digitalWrite(lampka_LED_PIN_D3, LOW); // turn off the LED
  58.     }
  59.    
  60.     // the LED will turn off even when the button is still active
  61.    
  62.     // other code if needed
  63.    
  64.     delay(10); // small delay to avoid blocking the loop
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement