Maxence Galopin
/
Projet_Test_11_BLE
Bonjour, ce code est pour Nathan Juranville , désolé pour le mail
main_2_1.cpp@0:6e18e2969238, 2019-11-20 (annotated)
- Committer:
- Nthnthj
- Date:
- Wed Nov 20 14:02:40 2019 +0000
- Revision:
- 0:6e18e2969238
Bon chance 2 !
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nthnthj | 0:6e18e2969238 | 1 | #include "mbed.h" |
Nthnthj | 0:6e18e2969238 | 2 | |
Nthnthj | 0:6e18e2969238 | 3 | InterruptIn my_button(USER_BUTTON); |
Nthnthj | 0:6e18e2969238 | 4 | //PwmOut my_pwm(D3); |
Nthnthj | 0:6e18e2969238 | 5 | DigitalOut myled(LED1); |
Nthnthj | 0:6e18e2969238 | 6 | Serial pc(USBTX, USBRX); // tx, rx terminal |
Nthnthj | 0:6e18e2969238 | 7 | Timer timer; |
Nthnthj | 0:6e18e2969238 | 8 | Timer timer2; |
Nthnthj | 0:6e18e2969238 | 9 | InterruptIn event(A0); |
Nthnthj | 0:6e18e2969238 | 10 | InterruptIn event2(A1); |
Nthnthj | 0:6e18e2969238 | 11 | //DigitalOut laser(D3); |
Nthnthj | 0:6e18e2969238 | 12 | |
Nthnthj | 0:6e18e2969238 | 13 | bool flag= false; |
Nthnthj | 0:6e18e2969238 | 14 | bool flag2= false; |
Nthnthj | 0:6e18e2969238 | 15 | bool duo = false ; |
Nthnthj | 0:6e18e2969238 | 16 | bool pass1= false; |
Nthnthj | 0:6e18e2969238 | 17 | bool pass2= false; |
Nthnthj | 0:6e18e2969238 | 18 | float begin, end; |
Nthnthj | 0:6e18e2969238 | 19 | float debut2, fin1, fin2; |
Nthnthj | 0:6e18e2969238 | 20 | |
Nthnthj | 0:6e18e2969238 | 21 | void skater_d() |
Nthnthj | 0:6e18e2969238 | 22 | { |
Nthnthj | 0:6e18e2969238 | 23 | |
Nthnthj | 0:6e18e2969238 | 24 | if(duo == false) { |
Nthnthj | 0:6e18e2969238 | 25 | printf("Ligne de depart coupee solo \n"); |
Nthnthj | 0:6e18e2969238 | 26 | if( flag == false && flag2 == false ) { |
Nthnthj | 0:6e18e2969238 | 27 | printf("Depart skate \n"); |
Nthnthj | 0:6e18e2969238 | 28 | begin = timer.read_ms(); |
Nthnthj | 0:6e18e2969238 | 29 | pc.printf(" skater lance %.0f \n", begin); |
Nthnthj | 0:6e18e2969238 | 30 | flag = true; |
Nthnthj | 0:6e18e2969238 | 31 | flag2= false; |
Nthnthj | 0:6e18e2969238 | 32 | } else if(flag == true && flag2 == true) { |
Nthnthj | 0:6e18e2969238 | 33 | printf("erreur \n"); |
Nthnthj | 0:6e18e2969238 | 34 | //end = timer.read_ms(); |
Nthnthj | 0:6e18e2969238 | 35 | //pc.printf(" skater arrive %.0f \n", end); |
Nthnthj | 0:6e18e2969238 | 36 | pc.printf(" Temps du skater : %.0f \n", end-begin); |
Nthnthj | 0:6e18e2969238 | 37 | flag = false; |
Nthnthj | 0:6e18e2969238 | 38 | } |
Nthnthj | 0:6e18e2969238 | 39 | |
Nthnthj | 0:6e18e2969238 | 40 | } |
Nthnthj | 0:6e18e2969238 | 41 | |
Nthnthj | 0:6e18e2969238 | 42 | else if(duo == true) { |
Nthnthj | 0:6e18e2969238 | 43 | printf("Ligne de depart coupee duo \n"); |
Nthnthj | 0:6e18e2969238 | 44 | if(pass1 == false) { |
Nthnthj | 0:6e18e2969238 | 45 | printf("arrive skate 1 duo \n"); |
Nthnthj | 0:6e18e2969238 | 46 | fin1 = timer2.read_ms(); |
Nthnthj | 0:6e18e2969238 | 47 | //pc.printf(" skater lance %.0f \n", begin); |
Nthnthj | 0:6e18e2969238 | 48 | pass1 = true; |
Nthnthj | 0:6e18e2969238 | 49 | } else if(pass1 == true) { |
Nthnthj | 0:6e18e2969238 | 50 | printf("ligne 1 deja coupee duo \n"); |
Nthnthj | 0:6e18e2969238 | 51 | //end = timer.read_ms(); |
Nthnthj | 0:6e18e2969238 | 52 | //pc.printf(" skater arrive %.0f \n", end); |
Nthnthj | 0:6e18e2969238 | 53 | //pc.printf(" Temps du skater : %.0f \n", end-begin); |
Nthnthj | 0:6e18e2969238 | 54 | //flag = false; |
Nthnthj | 0:6e18e2969238 | 55 | } |
Nthnthj | 0:6e18e2969238 | 56 | |
Nthnthj | 0:6e18e2969238 | 57 | |
Nthnthj | 0:6e18e2969238 | 58 | |
Nthnthj | 0:6e18e2969238 | 59 | } |
Nthnthj | 0:6e18e2969238 | 60 | if(pass1 == true && pass2== true ) { |
Nthnthj | 0:6e18e2969238 | 61 | printf("resultats : skater1 = %.0f , skater2 = %.0f . \n", fin1-debut2, fin2-debut2); |
Nthnthj | 0:6e18e2969238 | 62 | pass1 =false; |
Nthnthj | 0:6e18e2969238 | 63 | pass2 =false; |
Nthnthj | 0:6e18e2969238 | 64 | debut2= timer2.read_ms(); |
Nthnthj | 0:6e18e2969238 | 65 | } |
Nthnthj | 0:6e18e2969238 | 66 | |
Nthnthj | 0:6e18e2969238 | 67 | |
Nthnthj | 0:6e18e2969238 | 68 | |
Nthnthj | 0:6e18e2969238 | 69 | } |
Nthnthj | 0:6e18e2969238 | 70 | |
Nthnthj | 0:6e18e2969238 | 71 | |
Nthnthj | 0:6e18e2969238 | 72 | void skater_f() |
Nthnthj | 0:6e18e2969238 | 73 | { |
Nthnthj | 0:6e18e2969238 | 74 | if(duo == false) { |
Nthnthj | 0:6e18e2969238 | 75 | |
Nthnthj | 0:6e18e2969238 | 76 | printf("Ligne d'arrivee coupee \n"); |
Nthnthj | 0:6e18e2969238 | 77 | if( flag == false && flag2 == true) { |
Nthnthj | 0:6e18e2969238 | 78 | printf("arrivee coupe sans depart\n"); |
Nthnthj | 0:6e18e2969238 | 79 | //begin = timer.read_ms(); |
Nthnthj | 0:6e18e2969238 | 80 | //pc.printf(" skater arret a %.0f \n", begin); |
Nthnthj | 0:6e18e2969238 | 81 | flag = true; |
Nthnthj | 0:6e18e2969238 | 82 | } else if(flag == true && flag2 ==false ) { |
Nthnthj | 0:6e18e2969238 | 83 | printf("Arrivee skate \n"); |
Nthnthj | 0:6e18e2969238 | 84 | end = timer.read_ms(); |
Nthnthj | 0:6e18e2969238 | 85 | //pc.printf(" skater arrive %.0f \n", end); |
Nthnthj | 0:6e18e2969238 | 86 | pc.printf(" Temps du skater : %.0f \n", end-begin); |
Nthnthj | 0:6e18e2969238 | 87 | flag = false; |
Nthnthj | 0:6e18e2969238 | 88 | flag2=false; |
Nthnthj | 0:6e18e2969238 | 89 | } |
Nthnthj | 0:6e18e2969238 | 90 | |
Nthnthj | 0:6e18e2969238 | 91 | } else if(duo == true) { |
Nthnthj | 0:6e18e2969238 | 92 | printf("Ligne 2 de depart coupee duo \n"); |
Nthnthj | 0:6e18e2969238 | 93 | if(pass2 == false) { |
Nthnthj | 0:6e18e2969238 | 94 | printf("arrive skate 2 duo \n"); |
Nthnthj | 0:6e18e2969238 | 95 | fin2 = timer2.read_ms(); |
Nthnthj | 0:6e18e2969238 | 96 | //pc.printf(" skater lance %.0f \n", begin); |
Nthnthj | 0:6e18e2969238 | 97 | pass2 = true; |
Nthnthj | 0:6e18e2969238 | 98 | |
Nthnthj | 0:6e18e2969238 | 99 | |
Nthnthj | 0:6e18e2969238 | 100 | } else if(pass2 == true) { |
Nthnthj | 0:6e18e2969238 | 101 | printf("ligne 2 deja coupee duo \n"); |
Nthnthj | 0:6e18e2969238 | 102 | //end = timer.read_ms(); |
Nthnthj | 0:6e18e2969238 | 103 | //pc.printf(" skater arrive %.0f \n", end); |
Nthnthj | 0:6e18e2969238 | 104 | //pc.printf(" Temps du skater : %.0f \n", end-begin); |
Nthnthj | 0:6e18e2969238 | 105 | //flag = false; |
Nthnthj | 0:6e18e2969238 | 106 | } |
Nthnthj | 0:6e18e2969238 | 107 | |
Nthnthj | 0:6e18e2969238 | 108 | //printf("resultats : skater1 = %.0f , skater2 = %.0f . \n", fin1-debut2, fin2-debut2); |
Nthnthj | 0:6e18e2969238 | 109 | |
Nthnthj | 0:6e18e2969238 | 110 | } |
Nthnthj | 0:6e18e2969238 | 111 | if(pass1 == true && pass2== true ) { |
Nthnthj | 0:6e18e2969238 | 112 | printf("resultats : skater1 = %.0f , skater2 = %.0f . \n", fin1-debut2, fin2-debut2); |
Nthnthj | 0:6e18e2969238 | 113 | pass1 =false; |
Nthnthj | 0:6e18e2969238 | 114 | pass2 =false; |
Nthnthj | 0:6e18e2969238 | 115 | debut2= timer2.read_ms(); |
Nthnthj | 0:6e18e2969238 | 116 | } |
Nthnthj | 0:6e18e2969238 | 117 | } |
Nthnthj | 0:6e18e2969238 | 118 | |
Nthnthj | 0:6e18e2969238 | 119 | void pressed() { |
Nthnthj | 0:6e18e2969238 | 120 | /* |
Nthnthj | 0:6e18e2969238 | 121 | if(duo == false){ |
Nthnthj | 0:6e18e2969238 | 122 | //pc.printf("rapport cyclique : 0.5 "); |
Nthnthj | 0:6e18e2969238 | 123 | // pc.scanf("%f", &valeur_pwm); |
Nthnthj | 0:6e18e2969238 | 124 | //my_pwm.write(0.5); |
Nthnthj | 0:6e18e2969238 | 125 | //my_pwm.period_ms(500); |
Nthnthj | 0:6e18e2969238 | 126 | pc.printf("choix de course : solo \n"); |
Nthnthj | 0:6e18e2969238 | 127 | //laser=1; |
Nthnthj | 0:6e18e2969238 | 128 | wait(0.05); |
Nthnthj | 0:6e18e2969238 | 129 | } |
Nthnthj | 0:6e18e2969238 | 130 | else if (duo == true){ |
Nthnthj | 0:6e18e2969238 | 131 | //pc.printf("rapport cyclique : 0 "); |
Nthnthj | 0:6e18e2969238 | 132 | // pc.scanf("%f", &valeur_pwm); |
Nthnthj | 0:6e18e2969238 | 133 | //my_pwm.write(0); |
Nthnthj | 0:6e18e2969238 | 134 | //my_pwm.period_ms(500); |
Nthnthj | 0:6e18e2969238 | 135 | pc.printf("choix de course : duo \n"); |
Nthnthj | 0:6e18e2969238 | 136 | //laser=0; |
Nthnthj | 0:6e18e2969238 | 137 | wait(0.05); |
Nthnthj | 0:6e18e2969238 | 138 | timer2.start(); |
Nthnthj | 0:6e18e2969238 | 139 | debut2= timer2.read_ms(); |
Nthnthj | 0:6e18e2969238 | 140 | } |
Nthnthj | 0:6e18e2969238 | 141 | //test=my_pwm.read(); |
Nthnthj | 0:6e18e2969238 | 142 | //pc.printf("%f", test); |
Nthnthj | 0:6e18e2969238 | 143 | */ |
Nthnthj | 0:6e18e2969238 | 144 | duo = !duo ; |
Nthnthj | 0:6e18e2969238 | 145 | |
Nthnthj | 0:6e18e2969238 | 146 | } |
Nthnthj | 0:6e18e2969238 | 147 | |
Nthnthj | 0:6e18e2969238 | 148 | |
Nthnthj | 0:6e18e2969238 | 149 | /* |
Nthnthj | 0:6e18e2969238 | 150 | void choix() { |
Nthnthj | 0:6e18e2969238 | 151 | char cValue; |
Nthnthj | 0:6e18e2969238 | 152 | pc.printf("Press '1' to go solo, '0' to go duo \n"); |
Nthnthj | 0:6e18e2969238 | 153 | |
Nthnthj | 0:6e18e2969238 | 154 | char c = pc.scanf("%c", &cValue); // Read hyperterminal |
Nthnthj | 0:6e18e2969238 | 155 | if (c == '0') { |
Nthnthj | 0:6e18e2969238 | 156 | duo = true; // OFF |
Nthnthj | 0:6e18e2969238 | 157 | pc.printf("choix de course : duo \n"); |
Nthnthj | 0:6e18e2969238 | 158 | } |
Nthnthj | 0:6e18e2969238 | 159 | if (c == '1') { |
Nthnthj | 0:6e18e2969238 | 160 | duo = false; // ON |
Nthnthj | 0:6e18e2969238 | 161 | pc.printf("choix de course : solo \n"); |
Nthnthj | 0:6e18e2969238 | 162 | } |
Nthnthj | 0:6e18e2969238 | 163 | } |
Nthnthj | 0:6e18e2969238 | 164 | |
Nthnthj | 0:6e18e2969238 | 165 | */ |
Nthnthj | 0:6e18e2969238 | 166 | |
Nthnthj | 0:6e18e2969238 | 167 | int main() |
Nthnthj | 0:6e18e2969238 | 168 | { |
Nthnthj | 0:6e18e2969238 | 169 | |
Nthnthj | 0:6e18e2969238 | 170 | //duo=false; |
Nthnthj | 0:6e18e2969238 | 171 | |
Nthnthj | 0:6e18e2969238 | 172 | my_button.fall(&pressed); |
Nthnthj | 0:6e18e2969238 | 173 | timer.start(); |
Nthnthj | 0:6e18e2969238 | 174 | timer2.start(); |
Nthnthj | 0:6e18e2969238 | 175 | event.fall(&skater_d); |
Nthnthj | 0:6e18e2969238 | 176 | event2.fall(skater_f); |
Nthnthj | 0:6e18e2969238 | 177 | |
Nthnthj | 0:6e18e2969238 | 178 | |
Nthnthj | 0:6e18e2969238 | 179 | while(1) { |
Nthnthj | 0:6e18e2969238 | 180 | } |
Nthnthj | 0:6e18e2969238 | 181 | } |