CONTROL DE POSICION DE MOTOR CON ENCODER
Solution:
Solution:
- /*CONTROL DE POSICION DE MOTOR CON ENCODER */
- //Pines
- int Pbutton=2;
- int encoder=3;
- int motor=4;
- int LED=13;
- int a=0; //entrada
- int b=0; //salida
- int interruptor;
- int enc;
- int conta=0;
- void setup ()
- {
- Serial.begin(9600);
- //DeclaraciĆ³n de entradas y salidas
- pinMode(Pbutton,INPUT);
- pinMode(encoder,INPUT);
- pinMode(LED,OUTPUT);
- pinMode (motor,OUTPUT);
- digitalWrite(LED,LOW);
- }
- void loop ()
- {
- boton_on=digitalRead(Pbutton); //Lee posicion Push button
- if(interruptor==HIGH)
- {
- digitalWrite(LED,HIGH);
- digitalWrite(motor,HIGH);
- }
- //funcion encoder
- {
- enc=digitalRead(encoder);
- if(enc==1)
- {
- a=1;
- }
- else{i=0;}
- }
- if(a==1&&b==0)
- {
- conta++;
- Serial.println(contador);
- }
- if(enc==1)
- {
- b=1;
- }
- else{b=0;}
- //fin funcion encoder
- if(conta>=48)
- {
- digitalWrite(LED,LOW);
- digitalWrite(motor,LOW);
- delay (2000);
- conta=0;
- }
- }