Advertisement
pleasedontcode

Button Control rev_01

Mar 11th, 2024
37
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: 2024-03-11 11:24:38
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* I want to use two relays for the left and right of */
  21.     /* a tilt motor. Inside this motor, there is a 10 */
  22.     /* kOhm potentiometer, which changes the position of */
  23.     /* this motor according to the command that is being */
  24.     /* executed. I will divide the right side of this */
  25.     /* engin */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <EasyButton.h>    //https://github.com/evert-arias/EasyButton
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t Btn1_PushButton_PIN_D2 = 2;
  37. const uint8_t Btn2_PushButton_PIN_D3 = 3;
  38.  
  39. /***** DEFINITION OF ANALOG INPUT PINS *****/
  40. const uint8_t Pot_Potentiometer_Vout_PIN_A0 = A0;
  41.  
  42. /****** DEFINITION OF LIBRARY CLASS INSTANCES*****/
  43. EasyButton Btn1_PushButton(Btn1_PushButton_PIN_D2);
  44. EasyButton Btn2_PushButton(Btn2_PushButton_PIN_D3);
  45.  
  46. void setup(void)
  47. {
  48.     // put your setup code here, to run once:
  49.  
  50.     pinMode(Btn1_PushButton_PIN_D2, INPUT_PULLUP);
  51.     pinMode(Btn2_PushButton_PIN_D3, INPUT_PULLUP);
  52.     pinMode(Pot_Potentiometer_Vout_PIN_A0, INPUT);
  53.  
  54. }
  55.  
  56.  
  57. void loop(void)
  58. {
  59.     // put your main code here, to run repeatedly:
  60.  
  61.     // Check the state of Btn1_PushButton
  62.     Btn1_PushButton.read();
  63.     if (Btn1_PushButton.isPressed())
  64.     {
  65.         // Perform the left tilt motor action
  66.     }
  67.  
  68.     // Check the state of Btn2_PushButton
  69.     Btn2_PushButton.read();
  70.     if (Btn2_PushButton.isPressed())
  71.     {
  72.         // Perform the right tilt motor action
  73.     }
  74.  
  75.     // Read the value of the potentiometer
  76.     int potValue = analogRead(Pot_Potentiometer_Vout_PIN_A0);
  77.     // Perform actions based on the potentiometer value
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement