Advertisement
pleasedontcode

Button LED rev_06

Mar 4th, 2024
103
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 23:10:11
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Once the push button linked to pin D2 is pressed, */
  21.     /* the LED connected to pin D3 should instantly light */
  22.     /* up and stay illuminated for 0.5 seconds before */
  23.     /* automatically switching off. The LED will remain */
  24.     /* off until the push button is released. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Arduino.h>
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t przycisk_PushButton_PIN_D2 = 2;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t lampka_LED_PIN_D3 = 3;
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. /***** used to store raw data *****/
  43. bool lampka_LED_PIN_D3_rawData = LOW;
  44.  
  45. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  46. /***** used to store data after characteristic curve transformation *****/
  47. float lampka_LED_PIN_D3_phyData = 0.0;
  48.  
  49. void setup(void)
  50. {
  51.   pinMode(przycisk_PushButton_PIN_D2, INPUT_PULLUP);
  52.   pinMode(lampka_LED_PIN_D3, OUTPUT);
  53. }
  54.  
  55. void loop(void)
  56. {
  57.   // Check if the push button is pressed
  58.   if (digitalRead(przycisk_PushButton_PIN_D2) == LOW)
  59.   {
  60.     // Turn on the LED
  61.     digitalWrite(lampka_LED_PIN_D3, HIGH);
  62.     delay(500); // Wait for 0.5 seconds
  63.     digitalWrite(lampka_LED_PIN_D3, LOW); // Turn off the LED
  64.     while (digitalRead(przycisk_PushButton_PIN_D2) == LOW)
  65.     {
  66.       // Wait until the push button is released
  67.     }
  68.   }
  69. }
  70.  
  71. void updateOutputs(void)
  72. {
  73.   // No need to update outputs in this case
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement