Advertisement
pleasedontcode

Speed Control rev_01

Oct 21st, 2024
84
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: Speed Control
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-10-21 10:55:22
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Forward=A0  Reverse=A1  Dec=A2  Inc=A3  Speed=0 */
  21.     /* Inc is 3.2 volts when it changes to 1.5 volts for */
  22.     /* 1 second like denounce switch speed increment by 1 */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t A0_PushButton_PIN_D2      = 2; // Forward button
  34. const uint8_t A0_PushButton_PIN_D3      = 3; // Reverse button
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37. // Instance of the button for pin D2 (Forward)
  38. EasyButton buttonD2(A0_PushButton_PIN_D2);
  39. // Instance of the button for pin D3 (Reverse)
  40. EasyButton buttonD3(A0_PushButton_PIN_D3);
  41.  
  42. // Variable to track speed increment
  43. int speedIncrement = 0;
  44.  
  45. // Callback function to be called when the button on D2 is pressed for the given duration.
  46. void onPressedForDurationD2()
  47. {
  48.   // Increment speed by 1
  49.   speedIncrement += 1;
  50.   // Code to be executed when the button on D2 is pressed for the given duration.
  51. }
  52.  
  53. // Callback function to be called when the button on D3 is pressed for the given duration.
  54. void onPressedForDurationD3()
  55. {
  56.   // Decrement speed by 1
  57.   speedIncrement -= 1;
  58.   // Code to be executed when the button on D3 is pressed for the given duration.
  59. }
  60.  
  61. void setup(void)
  62. {
  63.     // Initialize the buttons.
  64.     buttonD2.begin();
  65.     buttonD3.begin();
  66.    
  67.     // Add the callback function to be called when the button on D2 is pressed for at least the given time.
  68.     buttonD2.onPressedFor(1000, onPressedForDurationD2); // 1 second for speed increment
  69.    
  70.     // Add the callback function to be called when the button on D3 is pressed for at least the given time.
  71.     buttonD3.onPressedFor(1000, onPressedForDurationD3); // 1 second for speed decrement
  72.    
  73.     // Set the pin modes for the buttons.
  74.     pinMode(A0_PushButton_PIN_D2, INPUT_PULLUP);
  75.     pinMode(A0_PushButton_PIN_D3, INPUT_PULLUP);
  76. }
  77.  
  78. void loop(void)
  79. {
  80.     // Continuously read the status of the buttons.
  81.     buttonD2.read();
  82.     buttonD3.read();
  83.    
  84.     // Here you can add code to use the speedIncrement variable as needed
  85. }
  86.  
  87. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement