Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **Motor Control**
- - Source Code NOT compiled for: Arduino Mega
- - Source Code created on: 2024-12-02 18:05:23
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* turn on stepper motor 100rpm by pushing start */
- /* button stop stepper motor by pushing stop button */
- /* twice */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton.h
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t start_PushButton_PIN_D2 = 2;
- const uint8_t stop_PushButton_PIN_D3 = 3;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create instances of EasyButton for start and stop buttons
- EasyButton startButton(start_PushButton_PIN_D2);
- EasyButton stopButton(stop_PushButton_PIN_D3);
- // Variable to track the stepper motor state
- bool motorRunning = false;
- int stopPressCount = 0;
- // Function to start the stepper motor
- void startMotor() {
- // Code to turn on the stepper motor at 100 RPM
- Serial.println("Stepper motor started at 100 RPM.");
- motorRunning = true;
- }
- // Function to stop the stepper motor
- void stopMotor() {
- // Code to turn off the stepper motor
- Serial.println("Stepper motor stopped.");
- motorRunning = false;
- }
- // Callback function for start button pressed
- void onStartPressed() {
- if (!motorRunning) {
- startMotor();
- }
- }
- // Callback function for stop button pressed
- void onStopPressed() {
- stopPressCount++;
- if (stopPressCount >= 2) {
- stopMotor();
- stopPressCount = 0; // Reset count after stopping
- }
- }
- void setup(void)
- {
- // put your setup code here, to run once:
- Serial.begin(115200); // Initialize Serial for debugging
- Serial.println("System Initialized.");
- pinMode(start_PushButton_PIN_D2, INPUT_PULLUP);
- pinMode(stop_PushButton_PIN_D3, INPUT_PULLUP);
- // Initialize the buttons
- startButton.begin();
- stopButton.begin();
- // Attach callback functions
- startButton.onPressed(onStartPressed);
- stopButton.onPressed(onStopPressed);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- startButton.read(); // Read the status of the start button
- stopButton.read(); // Read the status of the stop button
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement