![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
TP1 Ej 3 Bomba Cobas, Montero
main.cpp
- Committer:
- cobasjuan
- Date:
- 2019-05-22
- Revision:
- 0:9d8c86972a9d
- Child:
- 1:d99665a519ed
File content as of revision 0:9d8c86972a9d:
#include "mbed.h" #include "tsi_sensor.h" /* This defines will be replaced by PinNames soon */ #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) #define ELEC0 9 #define ELEC1 10 #elif defined (TARGET_KL05Z) #define ELEC0 9 #define ELEC1 8 #else #error TARGET NOT DEFINED #endif #define ESPERO_ARRANQUE 0 #define COMPARO_CABLES 1 #define GANA 2 #define PIERDE 3 #define ESPERO_CABLES 4 #define COMPARACION 5 // Funciones void CABLES(); void MAQUINA_GENERAL(); //Timer Ticker timer; void t(); //Salidas DigitalOut ledr(LED1); DigitalOut ledg(LED2); DigitalOut ledb(LED3); TSIAnalogSlider tsi(ELEC0, ELEC1, 40); // Variables unsigned int n=0, habcables=0, perdiste=0, finsec=0, tiempo=0; int secuencia[4]= {1,3,4,2}; int main(void) { ledg=1; ledr=1; ledb=1; timer.attach(&t,0.01); while (true) { CABLES(); MAQUINA_GENERAL(); } } void MAQUINA_GENERAL() { static unsigned int paso_general=ESPERO_ARRANQUE; unsigned int flag=0; switch(paso_general) { case ESPERO_ARRANQUE: n=0; tiempo=0; flag=0; perdiste=0; if(tsi.readPercentage() != 0) { paso_general=COMPARO_CABLES; } break; case COMPARO_CABLES: habcables=1; if(perdiste == 1) { paso_general=PIERDE; } if(finsec == 1) { paso_general=GANA; } break; case GANA: if(flag == 0) { flag=1; tiempo=100; ledg=0; } else if(tiempo==0 && flag == 1) { ledg=1; paso_general=ESPERO_ARRANQUE; } break; case PIERDE: break; } } void CABLES() { static unsigned int paso_cables=ESPERO_CABLES; unsigned int fail=0; switch(paso_cables) { case ESPERO_CABLES: if(habcables == 1) { paso_cables=COMPARACION; } break; case COMPARACION: if(n == 0) { if((C1 || C2 || C3 || C4) == 1) { if((secuencia[n] == 1 && C1 == 1) || (secuencia[n] == 2 && C2 == 1) || (secuencia[n] == 3 && C3 == 1) || (secuencia[n] == 4 && C4 == 1)) { n++; } else fail=1; } } else if(n == 1) { if() { if((secuencia[n] == 1 && C1 == 1) || (secuencia[n] == 2 && C2 == 1) || (secuencia[n] == 3 && C3 == 1) || (secuencia[n] == 4 && C4 == 1)) { n++; } else fail=1; } } else if(n == 2) { if() { if((secuencia[n] == 1 && C1 == 1) || (secuencia[n] == 2 && C2 == 1) || (secuencia[n] == 3 && C3 == 1) || (secuencia[n] == 4 && C4 == 1)) { n++; } else fail=1; } } else if(n == 3) { if() { if((secuencia[n] == 1 && C1 == 1) || (secuencia[n] == 2 && C2 == 1) || (secuencia[n] == 3 && C3 == 1) || (secuencia[n] == 4 && C4 == 1)) { finsec=1; habcables=0; paso_cables=ESPERO_CABLES; } else fail=1; } } if(fail == 1) { perdiste=1; habcables=0; paso_cables=ESPERO_CABLES; } break; } } void t() { if (tiempo > 0) tiempo--; }