Advertisement
pleasedontcode

Button Handler rev_01

May 6th, 2024
702
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 Handler
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-05-06 18:52:18
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* volume controller for Windows with 3 buttons */
  21.     /* (previous track, start/pause track, next track) */
  22.     /* and 4 potenciometers (master volume, volume of */
  23.     /* opera.exe, volume of discord.exe and other apps) */
  24. /****** SYSTEM REQUIREMENT 2 *****/
  25.     /* volume controller for Windows with 3 buttons */
  26.     /* (previous track, start/pause track, next track) */
  27.     /* and 4 potenciometers (master volume, volume of */
  28.     /* opera.exe) */
  29. /****** END SYSTEM REQUIREMENTS *****/
  30.  
  31. /****** DEFINITION OF LIBRARIES *****/
  32. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37.  
  38. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  39. const uint8_t BUTTON_ONE_PIN = 2;
  40. const uint8_t BUTTON_TWO_PIN = 4;
  41.  
  42. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  43. EasyButton button1(BUTTON_ONE_PIN);
  44. EasyButton button2(BUTTON_TWO_PIN);
  45.  
  46. void onButton1Pressed() {
  47.   Serial.println("Button1 pressed");
  48. }
  49.  
  50. void onButton2Pressed() {
  51.   Serial.println("Button2 pressed");
  52. }
  53.  
  54. void setup(void)
  55. {
  56.   // put your setup code here, to run once:
  57.   pinMode(BUTTON_ONE_PIN, INPUT_PULLUP);
  58.   pinMode(BUTTON_TWO_PIN, INPUT_PULLUP);
  59.  
  60.   Serial.begin(115200);
  61.   Serial.println();
  62.   Serial.println(">>> EasyButton multiple buttons example <<<");
  63.  
  64.   button1.begin();
  65.   button2.begin();
  66.   button1.onPressed(onButton1Pressed);
  67.   button2.onPressed(onButton2Pressed);
  68. }
  69.  
  70. void loop(void)
  71. {
  72.   // put your main code here, to run repeatedly:
  73.   button1.read();
  74.   button2.read();
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement