I am a quite beginner in electronics and programming.. I bought the adafruit motor shield and connected successfully an unipolar stepper motor with 5 wires. Now I want to control the motor with a potentiometer (attached it on Analog Pin = 1) and read as well how many steps the motor is driving. I did'n find any tutorial about how to use the AFmotor Library to set the analog input to write on my M3 an M4 pins.. How do I navigate the library in a way to control the motor direction and velocity (steps number) so I can drive it from my potentiometer? I am working on kind of objects which should rotate with different amount of steps depending on the potentiometer input.
p.s.
i did find a similar code, but here they don't use the motor shield..
[Edit - moderator - use the 'code' button when submitting code]
- Code: Select all
// program a unipolar stepper motor to be controlled by a potentiometer
// a stepper motor is the best choice for controlling motor speed with the greatest accuracy
// its accuracy is based on the number of ticks per rotation, like a watch motor
int motorPin1 = 2;
int motorPin2 = 3;
int motorPin3 = 4;
int motorPin4 = 5;
int analogPin = 1;
int delayTime = 50;
int val; // reads the input pin; val is a number coming in thats btwn 0 and 1023
void setup() {
Serial.begin(9600);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
}
void loop() {
int val = analogRead(analogPin); // read the input pin; val is a number coming in thats btwn 0 and 1023
Serial.println(val); // makes sure that potentiometer is working
delayTime = (val /3) + 15 ; // factors in time before the motor makes another step in speed
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, HIGH);
delay(delayTime);
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(delayTime);
}
I would be very happy if you could help me on this one..
thanks and best regards,
valentina

