Advertisement
pleasedontcode

Button Control rev_01

May 27th, 2024
537
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 NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-05-27 15:11:12
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* There are 3 special buttons. This includes a */
  21.     /* record button, a play button, and a stop button. */
  22.     /* and there are 2 additional buttons to turn on the */
  23.     /* LED. These 2 will light up 2 different LEDs each. */
  24.     /* When the button is pressed, the LED lights up. But */
  25.     /* when */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <EasyButton.h>
  30. #include <Bounce2.h>
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void updateOutputs();
  36.  
  37. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  38. const uint8_t but_LED_PIN_D2 = 2;
  39. const uint8_t led1_PIN = 3;
  40. const uint8_t led2_PIN = 4;
  41. const uint8_t record_BUTTON_PIN = 5;
  42. const uint8_t play_BUTTON_PIN = 6;
  43. const uint8_t stop_BUTTON_PIN = 7;
  44.  
  45. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  46. /***** used to store raw data *****/
  47. bool but_LED_PIN_D2_rawData = 0;
  48.  
  49. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  50. /***** used to store data after characteristic curve transformation *****/
  51. float but_LED_PIN_D2_phyData = 0.0;
  52.  
  53. /***** INSTANTIATE BUTTON OBJECTS *****/
  54. EasyButton recordButton(record_BUTTON_PIN);
  55. EasyButton playButton(play_BUTTON_PIN);
  56. EasyButton stopButton(stop_BUTTON_PIN);
  57. Bounce ledButton1 = Bounce();
  58. Bounce ledButton2 = Bounce();
  59.  
  60. void setup(void)
  61. {
  62.     // put your setup code here, to run once:
  63.     pinMode(but_LED_PIN_D2, OUTPUT);
  64.     pinMode(led1_PIN, OUTPUT);
  65.     pinMode(led2_PIN, OUTPUT);
  66.  
  67.     // Initialize buttons
  68.     recordButton.begin();
  69.     playButton.begin();
  70.     stopButton.begin();
  71.     ledButton1.attach(but_LED_PIN_D2, INPUT_PULLUP);
  72.     ledButton1.interval(25); // debounce interval in milliseconds
  73.     ledButton2.attach(but_LED_PIN_D2, INPUT_PULLUP);
  74.     ledButton2.interval(25); // debounce interval in milliseconds
  75.  
  76.     // Set up button callbacks
  77.     recordButton.onPressed([]() {
  78.         // Code to handle record button press
  79.     });
  80.  
  81.     playButton.onPressed([]() {
  82.         // Code to handle play button press
  83.     });
  84.  
  85.     stopButton.onPressed([]() {
  86.         // Code to handle stop button press
  87.     });
  88. }
  89.  
  90. void loop(void)
  91. {
  92.     // put your main code here, to run repeatedly:
  93.     recordButton.read();
  94.     playButton.read();
  95.     stopButton.read();
  96.     ledButton1.update();
  97.     ledButton2.update();
  98.  
  99.     if (ledButton1.fell()) {
  100.         digitalWrite(led1_PIN, HIGH);
  101.     }
  102.  
  103.     if (ledButton2.fell()) {
  104.         digitalWrite(led2_PIN, HIGH);
  105.     }
  106.  
  107.     updateOutputs(); // Refresh output data
  108. }
  109.  
  110. void updateOutputs()
  111. {
  112.     digitalWrite(but_LED_PIN_D2, but_LED_PIN_D2_rawData);
  113. }
  114.  
  115. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement