Advertisement
pleasedontcode

"LED Activation" rev_01

May 23rd, 2024
658
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: "LED Activation"
  13.     - Source Code NOT compiled for: Arduino Nano
  14.     - Source Code created on: 2024-05-23 14:53:10
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* If the button is pressed 3 times, let the LED */
  21.     /* light up */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <EasyButton.h>  //https://github.com/evert-arias/EasyButton
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void onSequenceMatched(void);  // Function prototype for sequence matched callback
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t Button_PushButton_PIN_D2 = 2;
  34. const uint8_t LED_PIN = 13;  // Define the LED pin
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37. EasyButton button(Button_PushButton_PIN_D2);  // Initialize EasyButton object with the pin number
  38.  
  39. void onSequenceMatched()
  40. {
  41.   Serial.println("Button pressed 3 times");  // Callback function to be called when the button sequence is matched
  42.   digitalWrite(LED_PIN, HIGH);  // Turn on the LED
  43. }
  44.  
  45. void setup(void)
  46. {
  47.   // put your setup code here, to run once:
  48.   Serial.begin(115200);  // Initialize serial communication at 115200 baud rate
  49.   Serial.println();
  50.   Serial.println(">>> EasyButton sequence example <<<");
  51.  
  52.   button.begin();  // Initialize the button
  53.   button.onSequence(3, 2000, onSequenceMatched);  // Set up the sequence detection: 3 presses within 2000ms
  54.  
  55.   pinMode(Button_PushButton_PIN_D2, INPUT_PULLUP);  // Set the button pin as input with pull-up resistor
  56.   pinMode(LED_PIN, OUTPUT);  // Set the LED pin as output
  57.   digitalWrite(LED_PIN, LOW);  // Ensure the LED is off initially
  58. }
  59.  
  60. void loop(void)
  61. {
  62.   // put your main code here, to run repeatedly:
  63.   button.read();  // Read the button state
  64. }
  65.  
  66. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement