Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Adafruit_GFX
Diff: main.cpp
- Revision:
- 0:e3755f5769fe
- Child:
- 1:1d515eb7abf3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Dec 15 08:47:04 2021 +0000 @@ -0,0 +1,168 @@ +#include "mbed.h" +#include "math.h" +//#include "hcsr04.h" +Serial pc(USBTX, USBRX); // tx, rx +Ticker tickerMideDistancia; +unsigned distancia=1000; + + +DigitalIn final1(D9); +DigitalIn final2(D10); +DigitalOut step(D2); +DigitalOut dir(A4); +DigitalOut enableMotor(D11); +DigitalIn boton_inicial(D3); + +enum estados {reset, apagado, encendido, motorpalante }; +estados estado; + +//HCSR04 usensor(D7,D8); //(PinName TrigPin,PinName EchoPin): +void paso(int d) +{ + dir=d; + step=1; + wait_us(100); + step=0; + wait_us(900); +} +void estadoreset() +{ + if (final1!=1) { + paso(0); + } else if (final1 ==1) { + estado = apagado; + step=0; + enableMotor =0; + } +} + +void estadoapagado() +{ + if (boton_inicial==1) { + enableMotor=1; + step = 1; + //paso(1); + estado= encendido; + + } +} + +void estadoencendido() +{ + if (boton_inicial==0 && final1==1) { + enableMotor=1; + step = 1; + paso(1); + estado = motorpalante; + + } +} + +void estadomotorpalante(){ +//if (final2) +if (final1!=1){ + enableMotor=1; + step =1; + paso(1); + //rele=1; + //Encender el motor de arriba +}} + + +//void mideDistancia() +//{ +// usensor.start(); +//} + + + +//void estadoCerrada(){ +//{ +// if(distancia<10) { +// enable=1; +// estado=abriendose; +// pc.printf("Estado Abriendose, distancia %d\n",distancia); +// } +//} + +//void estadoAbriendose() +//{ +// if((final1==1)&&(distancia<10)) { +// estado=abierta; +// enable=0; +// } else if((final1==1)&&(distancia>=10)) { +// enable=1; +// estado=cerrandose; +// } else { +// paso(1); +// pc.printf("paso\n"); + +// } +//} + +//void estadoCerrandose() +//{ +// if(distancia<10) { +// estado=abriendose; +// enable=1; +// } else if(final2==1) { +// estado=cerrada; +// enable=0; +// } else { +// paso(0); +// pc.printf("paso\n"); +// } +//} + +//void estadoAbierta() +//{ +// if (distancia>=10) { +// enable=1; +// estado=cerrandose; +// } +//} + +int main() +{ + pc.baud(115200); + //tickerMideDistancia.attach(&mideDistancia, 0.5); + estado=reset; + step=1; + enableMotor =1; + pc.printf("Estado cerrada\n"); + while(1) { + //distancia=usensor.get_dist_cm(); + switch ( estado ) { + case reset: + estadoreset(); + break; + case apagado: + pc.printf("HOLI"); + estadoapagado(); + break; + case encendido: + pc.printf("HOLI2"); + estadoencendido(); + break; + case motorpalante: + pc.printf("ALANTE"); + // estadomotorpalante(); + break; + /*case cerrada: + estadoCerrada(); + break; + case abriendose: + estadoAbriendose(); + break; + case abierta: + estadoAbierta(); + break; + case cerrandose: + estadoCerrandose(); + break; + default: + break; + }*/ + } + } +} \ No newline at end of file