#include <Stepper.h>
const int switchPin = 2; // Pin for the slide switch
const int ledPin = 3; // Pin for the LED
const int stepsPerRevolution = 200; // Adjust for your motor
// Initialize the stepper library
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
void setup() {
pinMode(switchPin, INPUT_PULLUP); // Use internal pull-up resistor for the switch
pinMode(ledPin, OUTPUT); // Set LED pin as output
myStepper.setSpeed(50); // Set the speed of the stepper motor
}
void loop() {
int switchState = digitalRead(switchPin); // Read the state of the switch
if (switchState == LOW) { // Switch is "on"
digitalWrite(ledPin, HIGH); // Turn on the LED
myStepper.step(stepsPerRevolution / 100); // Rotate the stepper motor a small step
} else { // Switch is "off"
digitalWrite(ledPin, LOW); // Turn off the LED
// Motor stops as no new step commands are sent
}
delay(10); // Small delay to debounce the switch
}