Benjamin Brou
/
DM5_ER
nothing
Diff: main.cpp
- Revision:
- 0:2d266e567c25
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Dec 03 11:04:13 2019 +0000 @@ -0,0 +1,107 @@ +#define DM5_ER +#ifdef DM5_ER + +#include "mbed.h" +#include "tsi_sensor.h" +#include "lib.h" + +DigitalOut led1(LED_RED); +DigitalOut led2(LED_GREEN); +DigitalOut led3(LED_BLUE); + +int main(void) +{ + float val; + int etat=0; + led1.write(1); + led2.write(1); + led3.write(1); + while (1) { + + val = lire_slider(); + printf("val = %f",val); + switch ( etat ) { // gestion de l’etat + case 0 : + if ((val > 0.8)&(val < 1)) { + etat =1; + } else if ((val > 0.4)&(val < 0.6)) { + etat =3; + } else if (val < 0.2) { + etat =2; + } + break ; + case 1 : + if (val ==1) { + etat =4; + } + break ; + case 2 : + if (val ==1) { + etat =4; + } + break ; + case 3 : + if (val ==1) { + etat =4; + } + break ; + case 4 : + if ((val > 0.5)&(val < 1)) { + etat =5; + } else if (val < 0.5) { + etat =6; + } + break ; + case 5 : + if (val==1) { + etat =0; + } + break ; + case 6 : + if (val==1) { + etat =0; + } + break ; + } + + switch ( etat ) { // gestion des sorties + case 0 : + led1.write(1); + led2.write(1); + led3.write(1); + break ; + case 1 : + led1.write(0); + led2.write(1); + led3.write(1); + break ; + case 2 : + led1.write(1); + led2.write(0); + led3.write(1); + break ; + case 3 : + led1.write(1); + led2.write(1); + led3.write(0); + break ; + case 4 : + led1.write(1); + led2.write(1); + led3.write(1); + break ; + case 5 : + led1.write(0); + led2.write(0); + led3.write(1); + break ; + case 6 : + led1.write(0); + led2.write(0); + led3.write(0); + break ; + } + wait(0.1); + } +} +#endif \ No newline at end of file