Advertisement
pleasedontcode

Button Toggle rev_02

Apr 8th, 2024
59
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 Toggle
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-08 18:29:26
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* I have a push button to digital pin 4 and a led on */
  21.     /* pin 8. Pin 8 high turns on the light.    When the */
  22.     /* button is pressed once I want to turn light on. */
  23.     /* Holding the button will start running it and let */
  24.     /* it run as long as pr */
  25. /****** SYSTEM REQUIREMENT 2 *****/
  26.     /* Button press:  1x on  2x on for 30 sec  3x on for */
  27.     /* 30, pause 10, on for 30  If on 1 press turns off */
  28. /****** END SYSTEM REQUIREMENTS *****/
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36. void onSequenceMatched(void);
  37. void updateOutputs(void);
  38.  
  39. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  40. const uint8_t startButton_PushButton_PIN_D4 = 4;
  41.  
  42. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  43. const uint8_t ledLight_LED_PIN_D8 = 8;
  44.  
  45. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  46. /***** used to store raw data *****/
  47. bool ledLight_LED_PIN_D8_rawData = 0;
  48.  
  49. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  50. /***** used to store data after characteristic curve transformation *****/
  51. float ledLight_LED_PIN_D8_phyData = 0.0;
  52.  
  53. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  54. EasyButton startButton(startButton_PushButton_PIN_D4); // Provide the pin argument in the constructor
  55.  
  56. void setup(void)
  57. {
  58.     // put your setup code here, to run once:
  59.  
  60.     pinMode(ledLight_LED_PIN_D8, OUTPUT);
  61.  
  62.     startButton.onSequence(3, 30000, onSequenceMatched); // 3 sequences, each lasting for 30 seconds
  63.     startButton.begin(); // Call the begin() function without any arguments
  64. }
  65.  
  66. void loop(void)
  67. {
  68.     // put your main code here, to run repeatedly:
  69.     startButton.read();
  70.     updateOutputs(); // Refresh output data
  71. }
  72.  
  73. void onSequenceMatched(void)
  74. {
  75.     // Button pressed
  76.     ledLight_LED_PIN_D8_rawData = !ledLight_LED_PIN_D8_rawData;
  77. }
  78.  
  79. void updateOutputs(void)
  80. {
  81.     digitalWrite(ledLight_LED_PIN_D8, ledLight_LED_PIN_D8_rawData);
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement