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.
Fork of DigitCode by
main.cpp
- Committer:
- Ridaz
- Date:
- 2015-04-14
- Revision:
- 1:0f2ba28c2e70
- Parent:
- 0:163dfb02ed36
- Child:
- 2:03518f08ccc0
File content as of revision 1:0f2ba28c2e70:
#include "mbed.h"
#include "fonction.h"
DigitalOut myled(LED1);
DigitalOut myled2(LED4);
DigitalOut myled3(LED3);
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:
myled = 1;
myled2 = 0;
myled3 = 0;
if (n == code[0] && nPrecedent == -3 ) {
etat = NB1;
wait(0.2);
}
break;
case NB1:
myled = 0;
myled2 = 0;
myled3 = 0;
if (n == code[1] && nPrecedent == -3) {
etat = NB2;
myled = 0;
wait(0.2);
} else if (n != -3)
etat = ERREUR;
break;
case NB2:
if (n == code[2] && nPrecedent == -3 ) {
etat = NB3;
wait(0.2);
}
else if (n != -3)
etat = ERREUR;
break;
case NB3:
if (n == code[3] && nPrecedent == -3) {
etat = FINAL;
wait(0.2);
} else if (n != -3)
etat = ERREUR;
break;
case FINAL:
etat = ETAT0;
myled2 = 1;
wait(5);
break;
case ERREUR:
myled3 = 1;
wait(1);
myled2 = 0;
etat = ETAT0;
}
printf("etat = %d | n = %d | nPrecedent = %d\n", etat, n, nPrecedent);
}
}
