Dependencies:   mbed

Committer:
Ridaz
Date:
Tue Apr 14 08:42:37 2015 +0000
Revision:
1:0f2ba28c2e70
Parent:
0:163dfb02ed36
;

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