Andrea Coronado
/
Seguidor_de_linea
Seguidor de linea
Revision 0:68aff7f85b84, committed 2014-12-03
- Comitter:
- AndreaC
- Date:
- Wed Dec 03 13:50:07 2014 +0000
- Commit message:
- Seguidor
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Seguidor_de_linea.cpp Wed Dec 03 13:50:07 2014 +0000 @@ -0,0 +1,53 @@ +#include "mbed.h" +#include "Servo.h" + +// Declaracion de las fotoresistencias +AnalogIn Fotoresistencia1(PTB1); +AnalogIn Fotoresistencia2(PTB2); + +// Declaracion de la comunicacion serial +Serial pc(USBTX,USBRX); + +// Declaracion del servo +PwmOut Servo(PTD4); + +// Declaracion del motor DC +PwmOut motorPin(PTC1); + +int main() +{ // Inicializa el programa + Servo.period_ms(20); // Establece el periodo Pwm del servo + + while(1) + { // Inicializa un ciclo infinito + + motorPin = 1; // Se inicializa el motor DC + + // Asigna a valorFotoresistencia el valor obtenido del sensor + float valorFotoresistencia1 = Fotoresistencia1.read(); + float valorFotoresistencia2 = Fotoresistencia2.read(); + + // Imprime para cuestiones de calibracion + pc.printf("%f\t%f\n", valorFotoresistencia1, valorFotoresistencia2); + wait(0.1); // Espera de 0.1 segundos + + while (valorFotoresistencia2 == 0.02 && valorFotoresistencia1 == 0.02) + { // Mientras ambas fotoresistencias detecten blanco... + Servo.pulsewidth_us(1800); // El servo se mantiene en su posicion inicial, hacia adelante + } + + while (valorFotoresistencia2 = 0.02 && valorFotoresistencia1 == 0.01) + { // Mientras una resistencia lea blanco y otra negro... + int movimiento = 1800; // Se declara una variable de nombre movimiento con un valor de 1500 + movimiento = movimiento + 35; // A este valor se le agrega 35 + Servo.pulsewidth_us(movimiento); // El servo se mueve a la posicion que indique la variable movimiento + { + + while (valorFotoresistencia 2 == 0.01 && valorFotoresistencia1 == 0.02) + { // Mientras una resistencia lea negro y la otra blanco... + int movimiento = 1800; // Se declara una variable de nombre movimiento con un valor de 1500 + movimiento = movimiento - 35; // A este valor se le resta 35 + Servo.pulsewidth_us(movimiento); // El servo se mueve a la posicion que indique la variable movimiento + } + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.lib Wed Dec 03 13:50:07 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/Servo/#36b69a7ced07
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Dec 03 13:50:07 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file