Advertisement
pleasedontcode

Button LED rev_04

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 22:59:25
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* after activating a button led turns on and turns */
  21.     /* off after 0,5s and stays off until the button is */
  22.     /* deactivated */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Arduino.h>
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31. void updateOutputs(void);
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t przycisk_PushButton_PIN_D2 = 2;
  35.  
  36. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  37. const uint8_t lampka_LED_PIN_D3 = 3;
  38.  
  39. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  40. bool lampka_LED_PIN_D3_rawData = 0;
  41.  
  42. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  43. float lampka_LED_PIN_D3_phyData = 0.0;
  44.  
  45. void setup(void)
  46. {
  47.   // put your setup code here, to run once:
  48.   pinMode(przycisk_PushButton_PIN_D2, INPUT_PULLUP);
  49.   pinMode(lampka_LED_PIN_D3, OUTPUT);
  50. }
  51.  
  52. void loop(void)
  53. {
  54.   // put your main code here, to run repeatedly:
  55.   bool buttonState = digitalRead(przycisk_PushButton_PIN_D2);
  56.  
  57.   if (buttonState == LOW)
  58.   {
  59.     lampka_LED_PIN_D3_rawData = 1;
  60.     updateOutputs(); // Turn on the LED
  61.     delay(500);
  62.   }
  63.   else
  64.   {
  65.     lampka_LED_PIN_D3_rawData = 0;
  66.     updateOutputs(); // Turn off the LED
  67.   }
  68. }
  69.  
  70. void updateOutputs()
  71. {
  72.   digitalWrite(lampka_LED_PIN_D3, lampka_LED_PIN_D3_rawData);
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement