Advertisement
pleasedontcode

Button Toggle rev_01

Dec 7th, 2023
83
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: 2023-12-07 07:06:29
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Turn off or on when i press a button */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Arduino.h>
  25. #include <EasyButton.h>
  26.  
  27. /****** SYSTEM REQUIREMENTS *****/
  28. /****** SYSTEM REQUIREMENT 1 *****/
  29. /* Turn off or on when I press a button */
  30. const uint8_t Test1_PushButton_PIN_D2 = 2;
  31.  
  32. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  33. EasyButton button(Test1_PushButton_PIN_D2);
  34.  
  35. // Function to turn off or on when the button is pressed
  36. void togglePower()
  37. {
  38.   // Code to toggle the power
  39. }
  40.  
  41. void setup(void)
  42. {
  43.   // put your setup code here, to run once:
  44.  
  45.   pinMode(Test1_PushButton_PIN_D2, INPUT_PULLUP);
  46.  
  47.   // Initialize the button object
  48.   button.begin();
  49.  
  50.   // Define and attach callback function when the button is pressed
  51.   button.onPressed([]() {
  52.     togglePower();
  53.   });
  54. }
  55.  
  56. void loop(void)
  57. {
  58.   // put your main code here, to run repeatedly:
  59.  
  60.   // Read the button state
  61.   button.read();
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement