Advertisement
pleasedontcode

Button Setup rev_01

Jan 17th, 2024
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 Setup
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-17 06:55:53
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* LED sensor */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Arduino.h>
  25. #include "EasyButton.h"
  26.  
  27. /****** SYSTEM REQUIREMENTS *****/
  28.  
  29. /****** SYSTEM REQUIREMENT 1 *****/
  30. /* LED sensor */
  31.  
  32. /****** END SYSTEM REQUIREMENTS *****/
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37.  
  38. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  39.  
  40. const uint8_t START_PUSHBUTTON_PIN = 2; // Replace with the actual pin number
  41.  
  42. /****** DECLARATION OF OBJECTS AND VARIABLES *****/
  43. EasyButton Start_PushButton(START_PUSHBUTTON_PIN);
  44.  
  45. void buttonPressed() {
  46.   // Code for buttonPressed()
  47. }
  48.  
  49. void sequenceElapsed() {
  50.   // Code for sequenceElapsed()
  51. }
  52.  
  53. void setup(void)
  54. {
  55.   // put your setup code here, to run once:
  56.  
  57.   pinMode(START_PUSHBUTTON_PIN, INPUT_PULLUP);
  58.  
  59.   Start_PushButton.begin();
  60.  
  61.   Start_PushButton.onPressed(buttonPressed);
  62.  
  63.   Start_PushButton.onPressedFor(500, sequenceElapsed);
  64. }
  65.  
  66. void loop(void)
  67. {
  68.   // put your main code here, to run repeatedly:
  69.   //
  70.   // Example code provided below
  71.   // Replace it with your own logic
  72.  
  73.   if (Start_PushButton.isPressed()) {
  74.     // Button is currently pressed
  75.     // Add your code here
  76.   }
  77.  
  78.   if (Start_PushButton.isReleased()) {
  79.     // Button is currently released
  80.     // Add your code here
  81.   }
  82.  
  83.   if (Start_PushButton.pressedFor(1000)) {
  84.     // Button has been pressed for a duration of 1 second (1000ms)
  85.     // Add your code here
  86.   }
  87.  
  88.   if (Start_PushButton.wasPressed()) {
  89.     // Button was pressed at the last read
  90.     // Add your code here
  91.   }
  92.  
  93.   if (Start_PushButton.wasReleased()) {
  94.     // Button was released at the last read
  95.     // Add your code here
  96.   }
  97.  
  98.   if (Start_PushButton.releasedFor(2000)) {
  99.     // Button has been released for a duration of 2 seconds (2000ms)
  100.     // Add your code here
  101.   }
  102.  
  103.   Start_PushButton.update();
  104.  
  105. }
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement