Dependencies:   mbed

Committer:
Ridaz
Date:
Tue Apr 14 08:34:05 2015 +0000
Revision:
0:163dfb02ed36
Child:
1:0f2ba28c2e70
; ;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ridaz 0:163dfb02ed36 1 #include "mbed.h"
Ridaz 0:163dfb02ed36 2 #include "fonction.h"
Ridaz 0:163dfb02ed36 3 DigitalOut myled(LED1);
Ridaz 0:163dfb02ed36 4 DigitalOut myled2(LED4);
Ridaz 0:163dfb02ed36 5 BusIn bus(p19, p18,p17,p16,p15,p14,p13,p12,p11,p10,p9,p8);
Ridaz 0:163dfb02ed36 6 int etat = 0;
Ridaz 0:163dfb02ed36 7 int code[] = {1, 2, 3, 4};
Ridaz 0:163dfb02ed36 8 int nPrecedent = -3;
Ridaz 0:163dfb02ed36 9 int n = -3;
Ridaz 0:163dfb02ed36 10 int main()
Ridaz 0:163dfb02ed36 11 {
Ridaz 0:163dfb02ed36 12 while(1) {
Ridaz 0:163dfb02ed36 13 nPrecedent = n;
Ridaz 0:163dfb02ed36 14 n = bus.read();
Ridaz 0:163dfb02ed36 15 n = bitToInt(n);
Ridaz 0:163dfb02ed36 16 switch (etat) {
Ridaz 0:163dfb02ed36 17 case ETAT0:
Ridaz 0:163dfb02ed36 18 if (n == code[0] && nPrecedent == -3 ) {
Ridaz 0:163dfb02ed36 19 etat = NB1;
Ridaz 0:163dfb02ed36 20 myled = 1;
Ridaz 0:163dfb02ed36 21 myled2 = 0;
Ridaz 0:163dfb02ed36 22 wait(0.2);
Ridaz 0:163dfb02ed36 23 }
Ridaz 0:163dfb02ed36 24 break;
Ridaz 0:163dfb02ed36 25
Ridaz 0:163dfb02ed36 26 case NB1:
Ridaz 0:163dfb02ed36 27 if (n == code[1] && nPrecedent == -3) {
Ridaz 0:163dfb02ed36 28 etat = NB2;
Ridaz 0:163dfb02ed36 29 myled = 0;
Ridaz 0:163dfb02ed36 30 wait(0.2);
Ridaz 0:163dfb02ed36 31 } else if (n != -3)
Ridaz 0:163dfb02ed36 32 etat = ETAT0;
Ridaz 0:163dfb02ed36 33 break;
Ridaz 0:163dfb02ed36 34
Ridaz 0:163dfb02ed36 35 case NB2:
Ridaz 0:163dfb02ed36 36 if (n == code[2] && nPrecedent == -3 ) {
Ridaz 0:163dfb02ed36 37 etat = NB3;
Ridaz 0:163dfb02ed36 38 wait(0.2);
Ridaz 0:163dfb02ed36 39 }
Ridaz 0:163dfb02ed36 40
Ridaz 0:163dfb02ed36 41 else if (n != -3)
Ridaz 0:163dfb02ed36 42 etat = ETAT0;
Ridaz 0:163dfb02ed36 43 break;
Ridaz 0:163dfb02ed36 44
Ridaz 0:163dfb02ed36 45 case NB3:
Ridaz 0:163dfb02ed36 46 if (n == code[3] && nPrecedent == -3) {
Ridaz 0:163dfb02ed36 47 etat = FINAL;
Ridaz 0:163dfb02ed36 48 wait(0.2);
Ridaz 0:163dfb02ed36 49 } else if (n != -3)
Ridaz 0:163dfb02ed36 50 etat = ETAT0;
Ridaz 0:163dfb02ed36 51 break;
Ridaz 0:163dfb02ed36 52
Ridaz 0:163dfb02ed36 53 case FINAL:
Ridaz 0:163dfb02ed36 54 etat = ETAT0;
Ridaz 0:163dfb02ed36 55 myled2 = 1;
Ridaz 0:163dfb02ed36 56 wait(5);
Ridaz 0:163dfb02ed36 57 break;
Ridaz 0:163dfb02ed36 58
Ridaz 0:163dfb02ed36 59 }
Ridaz 0:163dfb02ed36 60 printf("etat = %d | n = %d | nPrecedent = %d\n", etat, n, nPrecedent);
Ridaz 0:163dfb02ed36 61 }
Ridaz 0:163dfb02ed36 62 }