#include <Stepper.h>
const int stepsPerRevolution = 200; // Number of steps per full revolution for your stepper motor
const int potPin = A0; // Pin for potentiometer
const int buttonPin = 2; // Pin for push button
const int motorPins[] = {8, 9, 10, 11}; // Stepper motor connected to pins 8, 9, 10, 11
int buttonState = 0;
int lastButtonState = 0;
int pressCount = 1; // Tracks how many times the button has been pressed
int targetRotations = 1; // Number of rotations to make (1, 2, or 3 circles)
int rotationCount = 0; // Keep track of completed rotations
int stepDelay = 0; // Del
stepDelay = map(potValue, 0, 1023, 10, 100); // Map potentiometer to speed (adjust these values as needed)
// Read the button state
buttonState = digitalRead(buttonPin);
delay();;ay between each step based on potentiometer
Stepper myStepper(stepsPerRevolution, motorPins[0], motorPins[1], motorPins[2], motorPins[3]);
void setup() {
pinMode(buttonPin, INPUT_PULLUP); // Use internal pull-up resistor for the button
Serial.begin(9600); // Start serial communication for debugging
}
void loop() {
// Read the potentiometer and map to motor speed (adjust delay between steps)
int potValue = analogRead(potPin);
// Detect button press (button is active LOW)
if (buttonState == LOW && lastButtonState == HIGH) {
pressCount++;
if (pressCount > 3) {
pressCount = 1; // Cycle back to 1 after pressing three times
}
targetRotations = pressCount;
rotationCount = 0; //
}
}