Advertisement
pleasedontcode

Button LED rev_01

Mar 11th, 2024
72
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 Nano
  14.     - Source Code created on: 2024-03-11 21:29:48
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* if klik_PushButton pressed for greater tan 100 on */
  21.     /* 500 millisecond and klik2_PushBUtton pressed */
  22.     /* greater than 3 times on 500 millisecond */
  23.     /* digitalwrite pinled high */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32. void updateOutputs(void);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t klik_PushButton_PIN_D2 = 2;
  36. const uint8_t klik2_PushButton_PIN_D3 = 3;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t pinled_LED_PIN_D4 = 4;
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. /***** used to store raw data *****/
  43. bool pinled_LED_PIN_D4_rawData = 0;
  44.  
  45. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  46. /***** used to store data after characteristic curve transformation *****/
  47. float pinled_LED_PIN_D4_phyData = 0.0;
  48.  
  49. // Instances of button objects
  50. EasyButton klik_PushButton(klik_PushButton_PIN_D2);
  51. EasyButton klik2_PushButton(klik2_PushButton_PIN_D3);
  52.  
  53. void setup(void)
  54. {
  55.     // put your setup code here, to run once:
  56.    
  57.     pinMode(klik_PushButton_PIN_D2, INPUT_PULLUP);
  58.     pinMode(klik2_PushButton_PIN_D3, INPUT_PULLUP);
  59.    
  60.     pinMode(pinled_LED_PIN_D4, OUTPUT);
  61.    
  62.     // Initialize the buttons
  63.     klik_PushButton.begin();
  64.     klik2_PushButton.begin();
  65. }
  66.  
  67. void loop(void)
  68. {
  69.     // put your main code here, to run repeatedly:
  70.    
  71.     updateOutputs(); // Refresh output data
  72.  
  73.     // Continuously read the status of the buttons
  74.     klik_PushButton.read();
  75.     klik2_PushButton.read();
  76.    
  77.     // Check if the buttons are pressed for a certain duration
  78.     if (klik_PushButton.pressedFor(500) && klik2_PushButton.pressedFor(500))
  79.     {
  80.         digitalWrite(pinled_LED_PIN_D4, HIGH);
  81.     }
  82.     else
  83.     {
  84.         digitalWrite(pinled_LED_PIN_D4, LOW);
  85.     }
  86. }
  87.  
  88. void updateOutputs(void)
  89. {
  90.     digitalWrite(pinled_LED_PIN_D4, pinled_LED_PIN_D4_rawData);
  91. }
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement