Advertisement
pleasedontcode

Button Control rev_05

Mar 4th, 2024
95
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 23:06:51
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* When the push button is activated, the LED */
  21.     /* connected to pin D3 turns on immediately and */
  22.     /* remains on for 0.5 seconds before turning off. The */
  23.     /* LED stays off until the push button is */
  24.     /* deactivated. */
  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 pushButton_PIN_D2 = 2;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t LED_PIN_D3 = 3;
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. bool LED_PIN_D3_rawData = LOW;
  43.  
  44. void setup(void)
  45. {
  46.   // Set the push button pin as input with internal pull-up resistor
  47.   pinMode(pushButton_PIN_D2, INPUT_PULLUP);
  48.  
  49.   // Set the LED pin as output
  50.   pinMode(LED_PIN_D3, OUTPUT);
  51. }
  52.  
  53. void loop(void)
  54. {
  55.   // Check if the push button is activated
  56.   if (digitalRead(pushButton_PIN_D2) == LOW) {
  57.     // Activate the LED
  58.     LED_PIN_D3_rawData = HIGH;
  59.    
  60.     // Delay for 0.5 seconds
  61.     delay(500);
  62.    
  63.     // Deactivate the LED
  64.     LED_PIN_D3_rawData = LOW;
  65.   }
  66.  
  67.   // Refresh output data
  68.   updateOutputs();
  69. }
  70.  
  71. void updateOutputs()
  72. {
  73.   // Update the LED state
  74.   digitalWrite(LED_PIN_D3, LED_PIN_D3_rawData);
  75. }
  76.  
  77. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement