// PG UP = Blinds up
// PG DN = Blinds Down
#include <Stepper.h>
const int stepsPerRevolution = 200;
const int dirPin = 2;
const int stepPin = 3;
const int enablePin = 8;
const int potPin = A0;
int currentStep = 0;
void setup() {
pinMode(dirPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, LOW);
Serial.begin(9600);
Serial.println("Stepper Motor with Potentiometer Control");
}
void loop() {
int potValue = analogRead(potPin);
int targetStep = map(potValue, 0, 1023, -200, 200);
targetStep *= 5;
int stepsToMove = targetStep - currentStep;
if (stepsToMove > 0) {
digitalWrite(dirPin, HIGH);
} else {
digitalWrite(dirPin, LOW);
stepsToMove = -stepsToMove;
}
for(int i = 0; i < stepsToMove; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
}
currentStep = targetStep;
delay(100);
}