hello , i was doing a project and did a bit of copy-paste . i wanted to control 2 stepper motor with 2 different potentiometer and 2 switches for clockwise and counter clockwise. the main job of potentiometer is to slow down and ramp up the speed ,but i guess i did some mistake and the potentiometer aren't functioning..any help would be great !!!!
const int desiredValue = 15;
const int dir = 1;
int Pin1 = 10;//IN1
int Pin2 = 11;//IN2
int Pin3 = 12;//IN3
int Pin4 = 13;//IN4
int Pin5 = 5;//IN1
int Pin6 = 6;//IN2
int Pin7 = 7;//IN3
int Pin8 = 8;//IN4
int switchCW =2;
int switchCCW =3;
int potPin1 = A0;
int potPin2 = A1;
int vcc2 = 4;
int vcc3 = 9;
int pole1[] ={0,0,0,0, 0,1,1,1, 0};
int pole2[] ={0,0,0,1, 1,1,0,0, 0};
int pole3[] ={0,1,1,1, 0,0,0,0, 0};
int pole4[] ={1,1,0,0, 0,0,0,1, 0};
int pole5[] ={0,0,0,0, 0,1,1,1, 0};
int pole6[] ={0,0,0,1, 1,1,0,0, 0};
int pole7[] ={0,1,1,1, 0,0,0,0, 0};
int pole8[ ] ={1,1,0,0, 0,0,0,1, 0};
int poleStep = 0;
int dirStatus = 3;
int calcDelayfromTime(int t);
void driveStepper(int c);
int N = calcDelayfromTime(desiredValue);
void setup()
{
pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
pinMode(Pin4, OUTPUT);
pinMode(vcc2, OUTPUT);
digitalWrite(vcc2, HIGH);
pinMode(Pin5, OUTPUT);
pinMode(Pin6, OUTPUT);
pinMode(Pin7, OUTPUT);
pinMode(Pin8, OUTPUT);
pinMode(vcc3, OUTPUT);
digitalWrite(vcc3, HIGH);
Serial.begin(9600);
Serial.println("Robojax Stepper Control");
Serial.print("Max time per rev set: ");
Serial.print(desiredValue);
Serial.print(" loop delay: ");
Serial.println(N);
pinMode(switchCW,INPUT_PULLUP);
pinMode(switchCCW,INPUT_PULLUP);
delay(4000);
}// setup
void loop()
{
if(digitalRead(switchCCW) == LOW)
{
dirStatus =1;
}else if(digitalRead(switchCW) == LOW)
{
dirStatus = 2;
}else
{
dirStatus =3;
}
if(dirStatus ==1){
poleStep++;
driveStepper(poleStep);
}else if(dirStatus ==2){
poleStep--;
driveStepper(poleStep);
}else{
driveStepper(8);
}
if(poleStep>7){
poleStep=0;
}
if(poleStep<0){
poleStep=7;
}
int potValue1 =analogRead(potPin1);
int speed1 = map(potValue1, 0 , 1023, 1,N);
int potValue2 =analogRead(potPin2);
int speed2 = map(potValue2, 0 , 1023, 1,N);
delay(100);
}//loop
int calcDelayfromTime(int t){
return ((t-5)/4)+1;
}
void driveStepper(int c)
{
digitalWrite(Pin1, pole1[c]);
digitalWrite(Pin2, pole2[c]);
digitalWrite(Pin3, pole3[c]);
digitalWrite(Pin4, pole4[c]);
digitalWrite(Pin5, pole5[c]);
digitalWrite(Pin6, pole6[c]);
digitalWrite(Pin7, pole7[c]);
digitalWrite(Pin8, pole8[c]);
}