Advertisement
pleasedontcode

Button Control rev_01

Dec 30th, 2023
103
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 Control
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-30 14:41:16
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* when buton is press led on */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Arduino.h>
  25. #include <EasyButton.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t menu_PushButton_PIN_D2 = 2;
  33. const uint8_t up_PushButton_PIN_D3 = 3;
  34. const uint8_t dn_PushButton_PIN_D4 = 4;
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37. EasyButton menuButton(menu_PushButton_PIN_D2);
  38. EasyButton upButton(up_PushButton_PIN_D3);
  39. EasyButton downButton(dn_PushButton_PIN_D4);
  40.  
  41. void setup(void)
  42. {
  43.   // put your setup code here, to run once:
  44.  
  45.   pinMode(menu_PushButton_PIN_D2, INPUT_PULLUP);
  46.   pinMode(up_PushButton_PIN_D3, INPUT_PULLUP);
  47.   pinMode(dn_PushButton_PIN_D4, INPUT_PULLUP);
  48.  
  49.   // Initialize EasyButton instances
  50.   menuButton.begin();
  51.   upButton.begin();
  52.   downButton.begin();
  53.  
  54.   // Set LED pin as output
  55.   pinMode(LED_BUILTIN, OUTPUT);
  56. }
  57.  
  58. void loop(void)
  59. {
  60.   // put your main code here, to run repeatedly:
  61.  
  62.   // Read button states
  63.   menuButton.read();
  64.   upButton.read();
  65.   downButton.read();
  66.  
  67.   /****** SYSTEM REQUIREMENTS *****/
  68.   /****** SYSTEM REQUIREMENT 1 *****/
  69.     /* when button is pressed, turn on LED */
  70.   if (menuButton.isPressed()) {
  71.     digitalWrite(LED_BUILTIN, HIGH);
  72.   }
  73.   else {
  74.     digitalWrite(LED_BUILTIN, LOW);
  75.   }
  76.   /****** END SYSTEM REQUIREMENTS *****/
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement