Hola buenas noches,quisiera pedirles su ayuda y es si podrían ayudarme a re-programar este código de un motor normal para un motor paso a paso
int inicio;int esdan=0; int cuent=0;
int selector=A1;
int velmotor;int omeg;
int cont=0;int cont2=0;int cont3=0;
int sensor2=3;int sensor=2;
int led;
void setup() {
Serial.begin(9600);
attachInterrupt(0,sensor1,FALLING);
pinMode(A0,INPUT);pinMode(A1,INPUT);pinMode(A2,INPUT);
pinMode(A3,OUTPUT);pinMode(A4,OUTPUT);pinMode(A5,OUTPUT);
pinMode(11,OUTPUT);pinMode(10,OUTPUT);
pinMode(2,INPUT);pinMode(3,INPUT);pinMode(4,OUTPUT);pinMode(5,OUTPUT);
pinMode(6,OUTPUT);pinMode(7,OUTPUT);pinMode(8,OUTPUT);pinMode(9,OUTPUT);
pinMode(13,OUTPUT);pinMode(12,OUTPUT);
digitalWrite(A3,0);
}
void parar(){
if(digitalRead(A2)==HIGH && esdan==1){inicio=1-inicio;esdan=1-esdan;delay(50);}
}
void sensor1(){
cuent=cuent+1;
Serial.print(cuent/5);Serial.println(" revoluciones");
//if(digitalRead(sensor2)==HIGH){Serial.print("derecha");}
// else{if(digitalRead(sensor2)==LOW){Serial.print("izquiera");}}
Serial.print(omeg); Serial.println(" RPM");
}
void loop() {
if(digitalRead(A2)==HIGH && esdan==0){
inicio=1-inicio;esdan=1-esdan;delay(50);}
if(inicio==1){
velmotor=analogRead(A0);
omeg=map(velmotor,0,1023,0,200); //0 a 200 rpm
velmotor=map(velmotor,0,1023,0,255);
if(digitalRead(selector)==HIGH){
analogWrite(11,velmotor);
analogWrite(10,LOW);
Serial.println(omeg);
digitalWrite(A3,HIGH);
parar();
}
else{
analogWrite(11,LOW);
analogWrite(10,velmotor);
Serial.println(omeg);
digitalWrite(A3,LOW);
parar();
}
if(omeg>=0 && omeg<10){cont=omeg;cont2=0;cont3=0;}
if(omeg>=10 && omeg<20){cont=omeg-10;cont2=1;cont3=0;}
if(omeg>=20 && omeg<30){cont=omeg-20;cont2=2;cont3=0;}
if(omeg>=30 && omeg<40){cont=omeg-30;cont2=3;cont3=0;}
if(omeg>=40 && omeg<50){cont=omeg-40;cont2=4;cont3=0;}
if(omeg>=50 && omeg<60){cont=omeg-50;cont2=5;cont3=0;}
if(omeg>=60 && omeg<70){cont=omeg-60;cont2=6;cont3=0;}
if(omeg>=70 && omeg<80){cont=omeg-70;cont2=7;cont3=0;}
if(omeg>=80 && omeg<90){cont=omeg-80;cont2=8;cont3=0;}
if(omeg>=90 && omeg<100){cont=omeg-90;cont2=9;cont3=0;}
if(omeg>=100 && omeg<110){cont=omeg-100;cont2=0;cont3=1;}
if(omeg>=110 && omeg<120){cont=omeg-110;cont2=1;cont3=1;}
if(omeg>=120 && omeg<130){cont=omeg-120;cont2=2;cont3=1;}
if(omeg>=130 && omeg<140){cont=omeg-130;cont2=3;cont3=1;}
if(omeg>=140 && omeg<150){cont=omeg-140;cont2=4;cont3=1;}
if(omeg>=150 && omeg<160){cont=omeg-150;cont2=5;cont3=1;}
if(omeg>=160 && omeg<170){cont=omeg-160;cont2=6;cont3=1;}
if(omeg>=170 && omeg<180){cont=omeg-170;cont2=7;cont3=1;}
if(omeg>=180 && omeg<190){cont=omeg-180;cont2=8;cont3=1;}
if(omeg>=190 && omeg<200){cont=omeg-190;cont2=9;cont3=1;}
if(omeg>=200 && omeg<210){cont=omeg-200;cont2=0;cont3=2;}
num(); num2(); num3();
}
else{
analogWrite(11,0);
analogWrite(10,0);
digitalWrite(A3,0);
cont=0;cont2=0;cont3=0;
num(); num2(); num3();
}
}
void num(){
switch(cont){
case 0:digitalWrite(7,LOW);digitalWrite(6,LOW);digitalWrite(5,LOW);digitalWrite(4,LOW);break;
case 1:digitalWrite(7,HIGH);digitalWrite(6,LOW);digitalWrite(5,LOW);digitalWrite(4,LOW);break;
case 2:digitalWrite(7,LOW);digitalWrite(6,HIGH);digitalWrite(5,LOW);digitalWrite(4,LOW);break;
case 3:digitalWrite(7,HIGH);digitalWrite(6,HIGH);digitalWrite(5,LOW);digitalWrite(4,LOW);break;
case 4:digitalWrite(7,LOW);digitalWrite(6,LOW);digitalWrite(5,HIGH);digitalWrite(4,LOW);break;
case 5:digitalWrite(7,HIGH);digitalWrite(6,LOW);digitalWrite(5,HIGH);digitalWrite(4,LOW);break;
case 6:digitalWrite(7,LOW);digitalWrite(6,HIGH);digitalWrite(5,HIGH);digitalWrite(4,LOW);break;
case 7:digitalWrite(7,HIGH);digitalWrite(6,HIGH);digitalWrite(5,HIGH);digitalWrite(4,LOW);break;
case 8:digitalWrite(7,LOW);digitalWrite(6,LOW);digitalWrite(5,LOW);digitalWrite(4,HIGH);break;
case 9:digitalWrite(7,HIGH);digitalWrite(6,LOW);digitalWrite(5,LOW);digitalWrite(4,HIGH);break;
}
}
void num2(){
switch(cont2){
case 0:digitalWrite(8,LOW);digitalWrite(9,LOW);digitalWrite(10,LOW);digitalWrite(11,LOW);break;
case 1:digitalWrite(8,HIGH);digitalWrite(9,LOW);digitalWrite(10,LOW);digitalWrite(11,LOW);break;
case 2:digitalWrite(8,LOW);digitalWrite(9,HIGH);digitalWrite(10,LOW);digitalWrite(11,LOW);break;
case 3:digitalWrite(8,HIGH);digitalWrite(9,HIGH);digitalWrite(10,LOW);digitalWrite(11,LOW);break;
case 4:digitalWrite(8,LOW);digitalWrite(9,LOW);digitalWrite(10,HIGH);digitalWrite(11,LOW);break;
case 5:digitalWrite(8,HIGH);digitalWrite(9,LOW);digitalWrite(10,HIGH);digitalWrite(11,LOW);break;
case 6:digitalWrite(8,LOW);digitalWrite(9,HIGH);digitalWrite(10,HIGH);digitalWrite(11,LOW);break;
case 7:digitalWrite(8,HIGH);digitalWrite(9,HIGH);digitalWrite(10,HIGH);digitalWrite(11,LOW);break;
case 8:digitalWrite(8,LOW);digitalWrite(9,LOW);digitalWrite(10,LOW);digitalWrite(11,HIGH);break;
case 9:digitalWrite(8,HIGH);digitalWrite(9,LOW);digitalWrite(10,LOW);digitalWrite(11,HIGH);break;
}
}
void num3(){
switch(cont3){
case 0:digitalWrite(A4,LOW);digitalWrite(A5,LOW);break;
case 1:digitalWrite(A4,HIGH);digitalWrite(A5,LOW);break;
case 2:digitalWrite(A4,LOW);digitalWrite(A5,HIGH);break;
case 3:digitalWrite(A4,HIGH);digitalWrite(A5,HIGH);break;
}
}
Si alguno puede le agradecería bastante