Advertisement
pleasedontcode

Button Motor rev_01

Mar 6th, 2024
76
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 Motor
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-06 10:44:47
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Rotate right and left depends on the button click */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <EasyButton.h>    //https://github.com/evert-arias/EasyButton
  25. #include <L298NX2.h>    //https://github.com/AndreaLombardo/L298N
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void rotateRight();
  31. void rotateLeft();
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t button_PushButton_PIN_D2 = 2;
  35. const uint8_t button_PushButton_PIN_D3 = 3;
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. EasyButton button_PushButton_D2(button_PushButton_PIN_D2);
  39. EasyButton button_PushButton_D3(button_PushButton_PIN_D3);
  40. L298NX2 motor(9, 8, 7, 6); // Update the pin configurations according to your setup
  41.  
  42. void setup(void)
  43. {
  44.     // put your setup code here, to run once:
  45.  
  46.     pinMode(button_PushButton_PIN_D2, INPUT_PULLUP);
  47.     pinMode(button_PushButton_PIN_D3, INPUT_PULLUP);
  48.  
  49.     button_PushButton_D2.begin();
  50.     button_PushButton_D3.begin();
  51.  
  52.     // Register callback functions for button presses
  53.     button_PushButton_D2.onPressed(rotateRight);
  54.     button_PushButton_D3.onPressed(rotateLeft);
  55. }
  56.  
  57. void loop(void)
  58. {
  59.     // put your main code here, to run repeatedly:
  60.  
  61.     button_PushButton_D2.read();
  62.     button_PushButton_D3.read();
  63.  
  64.     // Add your code logic based on the button state here
  65. }
  66.  
  67. void rotateRight()
  68. {
  69.     // Add code to rotate right here
  70. }
  71.  
  72. void rotateLeft()
  73. {
  74.     // Add code to rotate left here
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement