Programa

download Programa

of 4

Transcript of Programa

//Sensor Herraduraint sensorHERR = A1;int x,y,z=0,i;int j,k;boolean n=0,s=0;//Motorconst byte Velpin = 3; // terminal de la seal PWM velocidad de 0const byte IN1pin = 4; // terminal a la entrada IN1 control giro derechaconst byte IN2pin = 5; // terminal a la entrada IN2 control giro izquierdaconst byte buttonPin1 = 9; // terminal de la seal del botn derechaconst byte buttonPin2 = 10; // terminal de la seal del botn izquierdaconst byte buttonPin3 = 6;const byte buttonPin4 = 8;const byte buttonPin5 = 12;const byte LedPin = 11;int PWMvalue=10; //velocidad//Sensoresint valHERR;int a=100,b=100;int valQRD;int stateButton4=0,stateButton5=0,stateButton3=0;boolean IN1state;boolean IN2state;//Sensor QRDint sensorQRD = A0;float mu=0;void setup() { //Herradura y QRD Serial.begin(9600); //Motor pinMode(buttonPin1,INPUT);//entrada del boton pinMode(buttonPin2,INPUT);//entrada del boton pinMode(buttonPin3,INPUT); pinMode(buttonPin4,INPUT); pinMode(buttonPin5,INPUT); pinMode(IN1pin,OUTPUT);//salida del pin giro pinMode(IN2pin,OUTPUT);//salida pin de giro pinMode(LedPin,OUTPUT); }void loop() { if(valQRD100) n=0; if(digitalRead(buttonPin4)==LOW) {n=1; } //Motor digitalWrite (IN1pin,IN1state);//configura el pin que controla el giro digitalWrite (IN2pin,IN2state);//configura el pin que controla el giro analogWrite (Velpin,120);//configura la velocidad constante del motor valQRD=analogRead(sensorQRD); //Botones libres if(digitalRead(buttonPin1)==LOW && digitalRead(buttonPin2)==LOW)//el motor inicia apagado { IN1state =LOW; IN2state =LOW; z=0; } if(digitalRead(buttonPin1)==HIGH && digitalRead(buttonPin2)==HIGH)//Para evitar chistes { IN1state=LOW; IN2state=LOW; z=0; } if(digitalRead (buttonPin1)==HIGH && digitalRead(buttonPin2)==LOW)//Sube la superficie relativo al espectador { IN1state =HIGH; IN2state =LOW; } if(digitalRead(buttonPin1)==LOW && digitalRead(buttonPin2)==HIGH)//Baja la superficie relativo al espectador { IN1state =LOW; IN2state =HIGH; } //Calibracion if(digitalRead(buttonPin3)==LOW) {k=0;mu=0;stateButton3=0;stateButton4=0;stateButton5=0;i=0;} //Medicion if( valQRD0) { IN1state =HIGH; IN2state =LOW; valHERR = analogRead(sensorHERR); if(valHERR>800) x=0;else x=1; delay(15); valHERR = analogRead(sensorHERR); delay(1); if(valHERR>800) y=0;else y=1; z=x-y; if(z!=0) i=i+1; //if(valQRD>700 && k>0) //{ mu=tan(i*3.1416/180); Serial.println(mu,3); Serial.println(i); k=0; //} } } if(s==1 && i>0) { IN1state =LOW; IN2state = HIGH; valHERR = analogRead(sensorHERR); if(valHERR>800) x=0;else x=1; delay(15); valHERR = analogRead(sensorHERR); delay(1); if(valHERR>800) y=0;else y=1; z=x-y; if(z!=0) i=i-1; } //Serial.println(i); //Serial.println(z); //Serial.println(valHERR); //Serial.println(k); //Serial.println(valQRD);} if(digitalRead (buttonPin1)==HIGH && digitalRead(buttonPin2)==LOW)//Sube la superficie relativo al espectador { IN1state =HIGH; IN2state =LOW; } if(digitalRead(buttonPin1)==LOW && digitalRead(buttonPin2)==HIGH)//Baja la superficie relativo al espectador { IN1state =LOW; IN2state =HIGH; } //Calibracion if(digitalRead(buttonPin3)==LOW) {k=0;mu=0;stateButton3=0;stateButton4=0;stateButton5=0;i=0;} //Medicion if( valQRD0) { IN1state =HIGH; IN2state =LOW; valHERR = analogRead(sensorHERR); if(valHERR>700) x=0;else x=1; delay(15); valHERR = analogRead(sensorHERR); delay(1); if(valHERR>700) y=0;else y=1; z=x-y; if(z!=0) i=i+1; //if(valQRD>700 && k>0) //{ mu=tan(i*3.1416/180); Serial.println(mu,3); Serial.println(i); k=0; //} } } if(s==1 && i>0) { IN1state =LOW; IN2state = HIGH; valHERR = analogRead(sensorHERR); if(valHERR>700) x=0;else x=1; delay(15); valHERR = analogRead(sensorHERR); delay(1); if(valHERR>700) y=0;else y=1; z=x-y; if(z!=0) i=i-1; } //Serial.println(i); //Serial.println(z); //Serial.println(valHERR); //Serial.println(k);}