Arduino Subject 3.0 Collab Game Challenge Part 1 - Stepper Motor Rotating Base with Buttons

  Рет қаралды 37

Waiduino

Waiduino

Күн бұрын

Пікірлер: 1
@Waiduino
@Waiduino Жыл бұрын
#include #include const int stepsPerRevolution = 2048; // Change this value based on your stepper motor // Define the pins for the stepper motor const int motorPin1 = 9; const int motorPin2 = 10; const int motorPin3 = 11; const int motorPin4 = 12; long number; // Corrected data type // Define the pins for the buttons const int buttonPinCW = 6; // Button for clockwise rotation const int buttonPinCCW = 7; // Button for counterclockwise rotation // Define the step delay time (in milliseconds) const int stepDelayTime = 5; AccelStepper stepper(AccelStepper::FULL4WIRE, motorPin1, motorPin3, motorPin2, motorPin4); const int servoPin = 3; const int buttonPinClockwise = 5; const int buttonPinCounterclockwise = 4; void setup() { pinMode(buttonPinCCW, INPUT_PULLUP); // Enable internal pull-up resistor pinMode(buttonPinCW, INPUT_PULLUP); // Enable internal pull-up resistor pinMode(buttonPinClockwise, INPUT_PULLUP); pinMode(buttonPinCounterclockwise, INPUT_PULLUP); stepper.setMaxSpeed(500); // Adjust the speed as needed (steps per second) stepper.setAcceleration(200); // Adjust the acceleration as needed (steps per second squared) } void loop() { int buttonStatusCCW = digitalRead(buttonPinCCW); int buttonStatusCW = digitalRead(buttonPinCW); int buttonStatusClockwise = digitalRead(buttonPinClockwise); int buttonStatusCounterclockwise = digitalRead(buttonPinCounterclockwise); // Stepper Control if (buttonStatusCW == LOW) { rotateClockwise(); } else if (buttonStatusCCW == LOW) { rotateCounterclockwise(); } else { stepper.stop(); // Stop the motor if no buttons are pressed } } void rotateClockwise() { stepper.setSpeed(500); // Set the speed for clockwise rotation (steps per second) stepper.move(1); // Move the motor one step (clockwise) stepper.runSpeedToPosition(); // Run the motor to the target position delay(stepDelayTime); } void rotateCounterclockwise() { stepper.setSpeed(500); // Set the speed for counterclockwise rotation (steps per second) stepper.move(-1); // Move the motor one step (counterclockwise) stepper.runSpeedToPosition(); // Run the motor to the target position delay(stepDelayTime); }
Stop Wasting Money on New Batteries! Restore Old AA Batteries Today!
18:17
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
Can my Son make a flip flop flashing circuit?
4:40
Project AA
Рет қаралды 92
Everything’s Gonna Be Fine!
7:59
TechLinked
Рет қаралды 262 М.
8 SIMPLE INVENTIONS
7:12
DIY INVENTOR
Рет қаралды 18