Advertisement
pleasedontcode

Button-controlled LEDs rev_01

Dec 6th, 2023
94
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-controlled LEDs
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-07 03:27:58
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Led my project */
  21. /****** SYSTEM REQUIREMENT 2 *****/
  22.     /* Led my project */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Arduino.h>
  27. #include <EasyButton.h>
  28.  
  29. /****** SYSTEM REQUIREMENTS *****/
  30. /****** SYSTEM REQUIREMENT 1 *****/
  31. const uint8_t Led_Pin_1 = 3; // Replace with the actual pin number for LED 1
  32. /****** SYSTEM REQUIREMENT 2 *****/
  33. const uint8_t Led_Pin_2 = 4; // Replace with the actual pin number for LED 2
  34.  
  35. /****** FUNCTION PROTOTYPES *****/
  36. void setup(void);
  37. void loop(void);
  38.  
  39. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  40. EasyButton button(2); // Replace with the actual pin number for the button
  41.  
  42. void setup(void)
  43. {
  44.   pinMode(Led_Pin_1, OUTPUT);
  45.   pinMode(Led_Pin_2, OUTPUT);
  46.  
  47.   button.begin();
  48. }
  49.  
  50. void loop(void)
  51. {
  52.   button.read();
  53.  
  54.   // Check button state
  55.   if (button.isPressed()) {
  56.     digitalWrite(Led_Pin_1, HIGH); // Turn on LED 1
  57.   } else {
  58.     digitalWrite(Led_Pin_1, LOW); // Turn off LED 1
  59.   }
  60.  
  61.   // Check button state and duration pressed
  62.   if (button.pressedFor(1000)) {
  63.     digitalWrite(Led_Pin_2, HIGH); // Turn on LED 2
  64.   } else {
  65.     digitalWrite(Led_Pin_2, LOW); // Turn off LED 2
  66.   }
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement