Adrien Audouard
/
DigitCode
Diff: main.cpp
- Revision:
- 0:163dfb02ed36
- Child:
- 1:0f2ba28c2e70
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Apr 14 08:34:05 2015 +0000 @@ -0,0 +1,62 @@ +#include "mbed.h" +#include "fonction.h" +DigitalOut myled(LED1); +DigitalOut myled2(LED4); +BusIn bus(p19, p18,p17,p16,p15,p14,p13,p12,p11,p10,p9,p8); +int etat = 0; +int code[] = {1, 2, 3, 4}; +int nPrecedent = -3; +int n = -3; +int main() +{ + while(1) { + nPrecedent = n; + n = bus.read(); + n = bitToInt(n); + switch (etat) { + case ETAT0: + if (n == code[0] && nPrecedent == -3 ) { + etat = NB1; + myled = 1; + myled2 = 0; + wait(0.2); + } + break; + + case NB1: + if (n == code[1] && nPrecedent == -3) { + etat = NB2; + myled = 0; + wait(0.2); + } else if (n != -3) + etat = ETAT0; + break; + + case NB2: + if (n == code[2] && nPrecedent == -3 ) { + etat = NB3; + wait(0.2); + } + + else if (n != -3) + etat = ETAT0; + break; + + case NB3: + if (n == code[3] && nPrecedent == -3) { + etat = FINAL; + wait(0.2); + } else if (n != -3) + etat = ETAT0; + break; + + case FINAL: + etat = ETAT0; + myled2 = 1; + wait(5); + break; + + } + printf("etat = %d | n = %d | nPrecedent = %d\n", etat, n, nPrecedent); + } +}