Benjamin Brou
/
DM5_ER
nothing
main.cpp@0:2d266e567c25, 2019-12-03 (annotated)
- Committer:
- benbrou06
- Date:
- Tue Dec 03 11:04:13 2019 +0000
- Revision:
- 0:2d266e567c25
V1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
benbrou06 | 0:2d266e567c25 | 1 | #define DM5_ER |
benbrou06 | 0:2d266e567c25 | 2 | #ifdef DM5_ER |
benbrou06 | 0:2d266e567c25 | 3 | |
benbrou06 | 0:2d266e567c25 | 4 | #include "mbed.h" |
benbrou06 | 0:2d266e567c25 | 5 | #include "tsi_sensor.h" |
benbrou06 | 0:2d266e567c25 | 6 | #include "lib.h" |
benbrou06 | 0:2d266e567c25 | 7 | |
benbrou06 | 0:2d266e567c25 | 8 | DigitalOut led1(LED_RED); |
benbrou06 | 0:2d266e567c25 | 9 | DigitalOut led2(LED_GREEN); |
benbrou06 | 0:2d266e567c25 | 10 | DigitalOut led3(LED_BLUE); |
benbrou06 | 0:2d266e567c25 | 11 | |
benbrou06 | 0:2d266e567c25 | 12 | int main(void) |
benbrou06 | 0:2d266e567c25 | 13 | { |
benbrou06 | 0:2d266e567c25 | 14 | float val; |
benbrou06 | 0:2d266e567c25 | 15 | int etat=0; |
benbrou06 | 0:2d266e567c25 | 16 | led1.write(1); |
benbrou06 | 0:2d266e567c25 | 17 | led2.write(1); |
benbrou06 | 0:2d266e567c25 | 18 | led3.write(1); |
benbrou06 | 0:2d266e567c25 | 19 | while (1) { |
benbrou06 | 0:2d266e567c25 | 20 | |
benbrou06 | 0:2d266e567c25 | 21 | val = lire_slider(); |
benbrou06 | 0:2d266e567c25 | 22 | printf("val = %f",val); |
benbrou06 | 0:2d266e567c25 | 23 | switch ( etat ) { // gestion de l’etat |
benbrou06 | 0:2d266e567c25 | 24 | case 0 : |
benbrou06 | 0:2d266e567c25 | 25 | if ((val > 0.8)&(val < 1)) { |
benbrou06 | 0:2d266e567c25 | 26 | etat =1; |
benbrou06 | 0:2d266e567c25 | 27 | } else if ((val > 0.4)&(val < 0.6)) { |
benbrou06 | 0:2d266e567c25 | 28 | etat =3; |
benbrou06 | 0:2d266e567c25 | 29 | } else if (val < 0.2) { |
benbrou06 | 0:2d266e567c25 | 30 | etat =2; |
benbrou06 | 0:2d266e567c25 | 31 | } |
benbrou06 | 0:2d266e567c25 | 32 | break ; |
benbrou06 | 0:2d266e567c25 | 33 | case 1 : |
benbrou06 | 0:2d266e567c25 | 34 | if (val ==1) { |
benbrou06 | 0:2d266e567c25 | 35 | etat =4; |
benbrou06 | 0:2d266e567c25 | 36 | } |
benbrou06 | 0:2d266e567c25 | 37 | break ; |
benbrou06 | 0:2d266e567c25 | 38 | case 2 : |
benbrou06 | 0:2d266e567c25 | 39 | if (val ==1) { |
benbrou06 | 0:2d266e567c25 | 40 | etat =4; |
benbrou06 | 0:2d266e567c25 | 41 | } |
benbrou06 | 0:2d266e567c25 | 42 | break ; |
benbrou06 | 0:2d266e567c25 | 43 | case 3 : |
benbrou06 | 0:2d266e567c25 | 44 | if (val ==1) { |
benbrou06 | 0:2d266e567c25 | 45 | etat =4; |
benbrou06 | 0:2d266e567c25 | 46 | } |
benbrou06 | 0:2d266e567c25 | 47 | break ; |
benbrou06 | 0:2d266e567c25 | 48 | case 4 : |
benbrou06 | 0:2d266e567c25 | 49 | if ((val > 0.5)&(val < 1)) { |
benbrou06 | 0:2d266e567c25 | 50 | etat =5; |
benbrou06 | 0:2d266e567c25 | 51 | } else if (val < 0.5) { |
benbrou06 | 0:2d266e567c25 | 52 | etat =6; |
benbrou06 | 0:2d266e567c25 | 53 | } |
benbrou06 | 0:2d266e567c25 | 54 | break ; |
benbrou06 | 0:2d266e567c25 | 55 | case 5 : |
benbrou06 | 0:2d266e567c25 | 56 | if (val==1) { |
benbrou06 | 0:2d266e567c25 | 57 | etat =0; |
benbrou06 | 0:2d266e567c25 | 58 | } |
benbrou06 | 0:2d266e567c25 | 59 | break ; |
benbrou06 | 0:2d266e567c25 | 60 | case 6 : |
benbrou06 | 0:2d266e567c25 | 61 | if (val==1) { |
benbrou06 | 0:2d266e567c25 | 62 | etat =0; |
benbrou06 | 0:2d266e567c25 | 63 | } |
benbrou06 | 0:2d266e567c25 | 64 | break ; |
benbrou06 | 0:2d266e567c25 | 65 | } |
benbrou06 | 0:2d266e567c25 | 66 | |
benbrou06 | 0:2d266e567c25 | 67 | switch ( etat ) { // gestion des sorties |
benbrou06 | 0:2d266e567c25 | 68 | case 0 : |
benbrou06 | 0:2d266e567c25 | 69 | led1.write(1); |
benbrou06 | 0:2d266e567c25 | 70 | led2.write(1); |
benbrou06 | 0:2d266e567c25 | 71 | led3.write(1); |
benbrou06 | 0:2d266e567c25 | 72 | break ; |
benbrou06 | 0:2d266e567c25 | 73 | case 1 : |
benbrou06 | 0:2d266e567c25 | 74 | led1.write(0); |
benbrou06 | 0:2d266e567c25 | 75 | led2.write(1); |
benbrou06 | 0:2d266e567c25 | 76 | led3.write(1); |
benbrou06 | 0:2d266e567c25 | 77 | break ; |
benbrou06 | 0:2d266e567c25 | 78 | case 2 : |
benbrou06 | 0:2d266e567c25 | 79 | led1.write(1); |
benbrou06 | 0:2d266e567c25 | 80 | led2.write(0); |
benbrou06 | 0:2d266e567c25 | 81 | led3.write(1); |
benbrou06 | 0:2d266e567c25 | 82 | break ; |
benbrou06 | 0:2d266e567c25 | 83 | case 3 : |
benbrou06 | 0:2d266e567c25 | 84 | led1.write(1); |
benbrou06 | 0:2d266e567c25 | 85 | led2.write(1); |
benbrou06 | 0:2d266e567c25 | 86 | led3.write(0); |
benbrou06 | 0:2d266e567c25 | 87 | break ; |
benbrou06 | 0:2d266e567c25 | 88 | case 4 : |
benbrou06 | 0:2d266e567c25 | 89 | led1.write(1); |
benbrou06 | 0:2d266e567c25 | 90 | led2.write(1); |
benbrou06 | 0:2d266e567c25 | 91 | led3.write(1); |
benbrou06 | 0:2d266e567c25 | 92 | break ; |
benbrou06 | 0:2d266e567c25 | 93 | case 5 : |
benbrou06 | 0:2d266e567c25 | 94 | led1.write(0); |
benbrou06 | 0:2d266e567c25 | 95 | led2.write(0); |
benbrou06 | 0:2d266e567c25 | 96 | led3.write(1); |
benbrou06 | 0:2d266e567c25 | 97 | break ; |
benbrou06 | 0:2d266e567c25 | 98 | case 6 : |
benbrou06 | 0:2d266e567c25 | 99 | led1.write(0); |
benbrou06 | 0:2d266e567c25 | 100 | led2.write(0); |
benbrou06 | 0:2d266e567c25 | 101 | led3.write(0); |
benbrou06 | 0:2d266e567c25 | 102 | break ; |
benbrou06 | 0:2d266e567c25 | 103 | } |
benbrou06 | 0:2d266e567c25 | 104 | wait(0.1); |
benbrou06 | 0:2d266e567c25 | 105 | } |
benbrou06 | 0:2d266e567c25 | 106 | } |
benbrou06 | 0:2d266e567c25 | 107 | #endif |