Advertisement
pleasedontcode

Button Control rev_01

Mar 18th, 2024
49
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-18 09:13:35
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* arduino uno with connected cnc shield.  2 nema 17 */
  21.     /* stepper motors, 4 buttons, 1 stepper motor limiter */
  22.     /* and 4 ws2812 address diodes are attached to them */
  23.     /* the algorithm is as follows:  1. when the device */
  24.     /* is turned on. motor A moves to the limit switch */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <EasyButton.h>    //https://github.com/evert-arias/EasyButton
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t EndStop_PushButton_PIN_D2    = 2;
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  38. EasyButton button(EndStop_PushButton_PIN_D2); // Initialize the EasyButton object with the button pin
  39.  
  40. void setup(void)
  41. {
  42.   // put your setup code here, to run once:
  43.  
  44.   pinMode(EndStop_PushButton_PIN_D2, INPUT_PULLUP);
  45.  
  46.   // Initialize the button
  47.   button.begin();
  48.  
  49.   // Move motor A to the limit switch when the device is turned on
  50.   // code goes here...
  51. }
  52.  
  53. void loop(void)
  54. {
  55.   // put your main code here, to run repeatedly:
  56.  
  57.   // Check if the button is pressed
  58.   if (button.read()) {
  59.     // Perform the desired action when the button is pressed
  60.     // For example, moving motor A to the limit switch
  61.     // code goes here...
  62.   }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement