thomas strcic
/
ProjetInfo2_Multi12
oki
Fork of ProjetInfo2_Multi by
main.cpp@3:98f5de1dd010, 2018-06-05 (annotated)
- Committer:
- thomasstrcic
- Date:
- Tue Jun 05 11:54:56 2018 +0000
- Revision:
- 3:98f5de1dd010
- Parent:
- 2:ae058dfdebac
nique bitoun
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jujuonthebeat | 0:5755bf39c144 | 1 | #include "mbed.h" |
jujuonthebeat | 0:5755bf39c144 | 2 | #include "coffre.h" |
thomasstrcic | 1:d446f0124474 | 3 | #include "music.h" |
jujuonthebeat | 0:5755bf39c144 | 4 | |
jujuonthebeat | 0:5755bf39c144 | 5 | |
thomasstrcic | 1:d446f0124474 | 6 | #define O 0.0193 |
thomasstrcic | 2:ae058dfdebac | 7 | #define F 0.0179 |
thomasstrcic | 1:d446f0124474 | 8 | |
jujuonthebeat | 0:5755bf39c144 | 9 | |
jujuonthebeat | 0:5755bf39c144 | 10 | |
jujuonthebeat | 0:5755bf39c144 | 11 | // VARIABLE ***************** |
jujuonthebeat | 0:5755bf39c144 | 12 | |
thomasstrcic | 2:ae058dfdebac | 13 | |
jujuonthebeat | 0:5755bf39c144 | 14 | extern BusIn digicode; |
thomasstrcic | 2:ae058dfdebac | 15 | DigitalOut led1(p20); |
jujuonthebeat | 0:5755bf39c144 | 16 | DigitalOut led2(p18); |
jujuonthebeat | 0:5755bf39c144 | 17 | Timer t1; |
jujuonthebeat | 0:5755bf39c144 | 18 | Timer t2; |
thomasstrcic | 3:98f5de1dd010 | 19 | extern int u; |
thomasstrcic | 3:98f5de1dd010 | 20 | extern Timer t3; |
thomasstrcic | 3:98f5de1dd010 | 21 | extern int code[4]; |
thomasstrcic | 3:98f5de1dd010 | 22 | extern int etat =0; |
thomasstrcic | 3:98f5de1dd010 | 23 | extern int N_precedent; |
thomasstrcic | 3:98f5de1dd010 | 24 | extern int N; |
thomasstrcic | 1:d446f0124474 | 25 | int juste; |
thomasstrcic | 1:d446f0124474 | 26 | int count; |
thomasstrcic | 3:98f5de1dd010 | 27 | extern Serial pc; |
thomasstrcic | 3:98f5de1dd010 | 28 | Serial bluetooth(p28,p27); |
thomasstrcic | 3:98f5de1dd010 | 29 | char chara; |
thomasstrcic | 3:98f5de1dd010 | 30 | int val; |
jujuonthebeat | 0:5755bf39c144 | 31 | |
jujuonthebeat | 0:5755bf39c144 | 32 | |
jujuonthebeat | 0:5755bf39c144 | 33 | |
jujuonthebeat | 0:5755bf39c144 | 34 | |
jujuonthebeat | 0:5755bf39c144 | 35 | // CODE ************ |
jujuonthebeat | 0:5755bf39c144 | 36 | |
jujuonthebeat | 0:5755bf39c144 | 37 | |
jujuonthebeat | 0:5755bf39c144 | 38 | int main() |
jujuonthebeat | 0:5755bf39c144 | 39 | { |
thomasstrcic | 2:ae058dfdebac | 40 | |
jujuonthebeat | 0:5755bf39c144 | 41 | while(1) |
jujuonthebeat | 0:5755bf39c144 | 42 | { |
jujuonthebeat | 0:5755bf39c144 | 43 | N_precedent=N; |
jujuonthebeat | 0:5755bf39c144 | 44 | t3.start(); |
thomasstrcic | 2:ae058dfdebac | 45 | if(t3.read()>0.01) |
jujuonthebeat | 0:5755bf39c144 | 46 | { |
thomasstrcic | 3:98f5de1dd010 | 47 | if (bluetooth.readable()) |
thomasstrcic | 3:98f5de1dd010 | 48 | { |
thomasstrcic | 3:98f5de1dd010 | 49 | chara=bluetooth.getc(); |
thomasstrcic | 3:98f5de1dd010 | 50 | N=chara-'0'; |
thomasstrcic | 3:98f5de1dd010 | 51 | } |
thomasstrcic | 3:98f5de1dd010 | 52 | |
thomasstrcic | 3:98f5de1dd010 | 53 | |
jujuonthebeat | 0:5755bf39c144 | 54 | t3.reset(); |
jujuonthebeat | 0:5755bf39c144 | 55 | t3.stop(); |
jujuonthebeat | 0:5755bf39c144 | 56 | } |
thomasstrcic | 3:98f5de1dd010 | 57 | pc.printf("%d \n\r",N_precedent); |
thomasstrcic | 3:98f5de1dd010 | 58 | pc.printf("%d \n\r",N); |
jujuonthebeat | 0:5755bf39c144 | 59 | switch(etat) |
jujuonthebeat | 0:5755bf39c144 | 60 | { |
jujuonthebeat | 0:5755bf39c144 | 61 | case 0: |
thomasstrcic | 1:d446f0124474 | 62 | if (count>=3) |
thomasstrcic | 1:d446f0124474 | 63 | { |
thomasstrcic | 1:d446f0124474 | 64 | |
thomasstrcic | 1:d446f0124474 | 65 | led2.write(1); |
thomasstrcic | 1:d446f0124474 | 66 | music(); |
thomasstrcic | 3:98f5de1dd010 | 67 | wait(3); |
thomasstrcic | 1:d446f0124474 | 68 | count=0; |
thomasstrcic | 1:d446f0124474 | 69 | } |
jujuonthebeat | 0:5755bf39c144 | 70 | |
thomasstrcic | 3:98f5de1dd010 | 71 | if ( N_precedent==0 and N == code[0] ) |
jujuonthebeat | 0:5755bf39c144 | 72 | { |
jujuonthebeat | 0:5755bf39c144 | 73 | etat=1; |
jujuonthebeat | 0:5755bf39c144 | 74 | pc.printf("ok1\n\r"); |
jujuonthebeat | 0:5755bf39c144 | 75 | } |
thomasstrcic | 3:98f5de1dd010 | 76 | if(N_precedent == 0 and N!=code[0] and N!=0) |
jujuonthebeat | 0:5755bf39c144 | 77 | { |
jujuonthebeat | 0:5755bf39c144 | 78 | etat=5; |
jujuonthebeat | 0:5755bf39c144 | 79 | t1.reset(); |
jujuonthebeat | 0:5755bf39c144 | 80 | t1.start(); |
jujuonthebeat | 0:5755bf39c144 | 81 | |
jujuonthebeat | 0:5755bf39c144 | 82 | } |
thomasstrcic | 3:98f5de1dd010 | 83 | if (N_precedent==0 and N==10) |
thomasstrcic | 3:98f5de1dd010 | 84 | { |
thomasstrcic | 3:98f5de1dd010 | 85 | changement_code(code); |
thomasstrcic | 3:98f5de1dd010 | 86 | u=0; |
thomasstrcic | 3:98f5de1dd010 | 87 | } |
thomasstrcic | 2:ae058dfdebac | 88 | pc.printf("etat =0\n\r"); |
jujuonthebeat | 0:5755bf39c144 | 89 | break; |
jujuonthebeat | 0:5755bf39c144 | 90 | case 1 : |
jujuonthebeat | 0:5755bf39c144 | 91 | |
thomasstrcic | 2:ae058dfdebac | 92 | pc.printf("etat =1\n\r"); |
thomasstrcic | 3:98f5de1dd010 | 93 | if ( N_precedent==code[0] and N == code[1]) |
jujuonthebeat | 0:5755bf39c144 | 94 | { |
jujuonthebeat | 0:5755bf39c144 | 95 | etat=2; |
jujuonthebeat | 0:5755bf39c144 | 96 | pc.printf("ok2\n\r"); |
jujuonthebeat | 0:5755bf39c144 | 97 | } |
jujuonthebeat | 0:5755bf39c144 | 98 | |
thomasstrcic | 3:98f5de1dd010 | 99 | if(N_precedent == code[0] and N!=code[1] and N!=-3) |
jujuonthebeat | 0:5755bf39c144 | 100 | { |
jujuonthebeat | 0:5755bf39c144 | 101 | etat=5; |
jujuonthebeat | 0:5755bf39c144 | 102 | t1.reset(); |
jujuonthebeat | 0:5755bf39c144 | 103 | t1.start(); |
jujuonthebeat | 0:5755bf39c144 | 104 | } |
jujuonthebeat | 0:5755bf39c144 | 105 | break; |
jujuonthebeat | 0:5755bf39c144 | 106 | case 2 : |
thomasstrcic | 2:ae058dfdebac | 107 | pc.printf("etat =2\n\r"); |
jujuonthebeat | 0:5755bf39c144 | 108 | if( N_precedent==-3 and N == code[2]) |
jujuonthebeat | 0:5755bf39c144 | 109 | { |
jujuonthebeat | 0:5755bf39c144 | 110 | etat=3; |
jujuonthebeat | 0:5755bf39c144 | 111 | pc.printf("ok3\n\r"); |
jujuonthebeat | 0:5755bf39c144 | 112 | } |
jujuonthebeat | 0:5755bf39c144 | 113 | if(N_precedent == -3 and N!=code[2] and N!=-3) |
jujuonthebeat | 0:5755bf39c144 | 114 | { |
jujuonthebeat | 0:5755bf39c144 | 115 | etat=5; |
jujuonthebeat | 0:5755bf39c144 | 116 | t1.reset(); |
jujuonthebeat | 0:5755bf39c144 | 117 | t1.start(); |
jujuonthebeat | 0:5755bf39c144 | 118 | } |
jujuonthebeat | 0:5755bf39c144 | 119 | break; |
jujuonthebeat | 0:5755bf39c144 | 120 | case 3 : |
thomasstrcic | 2:ae058dfdebac | 121 | pc.printf("etat =3\n\r"); |
jujuonthebeat | 0:5755bf39c144 | 122 | if ( N_precedent==-3 and N == code[3]) |
jujuonthebeat | 0:5755bf39c144 | 123 | { |
jujuonthebeat | 0:5755bf39c144 | 124 | etat=4; |
jujuonthebeat | 0:5755bf39c144 | 125 | pc.printf("bravo c bon msieur\n\r"); |
thomasstrcic | 1:d446f0124474 | 126 | juste=1; |
thomasstrcic | 2:ae058dfdebac | 127 | |
thomasstrcic | 3:98f5de1dd010 | 128 | wait(0.5); |
jujuonthebeat | 0:5755bf39c144 | 129 | t2.reset(); |
jujuonthebeat | 0:5755bf39c144 | 130 | t2.start(); |
jujuonthebeat | 0:5755bf39c144 | 131 | } |
jujuonthebeat | 0:5755bf39c144 | 132 | if(N_precedent == -3 and N!=code[3] and N!=-3) |
jujuonthebeat | 0:5755bf39c144 | 133 | { |
jujuonthebeat | 0:5755bf39c144 | 134 | etat=5; |
jujuonthebeat | 0:5755bf39c144 | 135 | t1.reset(); |
jujuonthebeat | 0:5755bf39c144 | 136 | t1.start(); |
jujuonthebeat | 0:5755bf39c144 | 137 | } |
jujuonthebeat | 0:5755bf39c144 | 138 | break; |
jujuonthebeat | 0:5755bf39c144 | 139 | |
jujuonthebeat | 0:5755bf39c144 | 140 | case 4: |
jujuonthebeat | 0:5755bf39c144 | 141 | |
jujuonthebeat | 0:5755bf39c144 | 142 | |
thomasstrcic | 2:ae058dfdebac | 143 | pc.printf("etat =4\n\r"); |
thomasstrcic | 3:98f5de1dd010 | 144 | if(t2.read()>0.5) |
jujuonthebeat | 0:5755bf39c144 | 145 | { |
jujuonthebeat | 0:5755bf39c144 | 146 | etat=0; |
jujuonthebeat | 0:5755bf39c144 | 147 | } |
jujuonthebeat | 0:5755bf39c144 | 148 | break; |
jujuonthebeat | 0:5755bf39c144 | 149 | case 5: |
jujuonthebeat | 0:5755bf39c144 | 150 | if (t1.read()>1) |
jujuonthebeat | 0:5755bf39c144 | 151 | { |
thomasstrcic | 1:d446f0124474 | 152 | count++; |
thomasstrcic | 1:d446f0124474 | 153 | pc.printf(" count = %d \n\r",count); |
jujuonthebeat | 0:5755bf39c144 | 154 | pc.printf("c faux msieur\n\r"); |
jujuonthebeat | 0:5755bf39c144 | 155 | etat=0; |
thomasstrcic | 1:d446f0124474 | 156 | |
jujuonthebeat | 0:5755bf39c144 | 157 | } |
thomasstrcic | 2:ae058dfdebac | 158 | pc.printf("etat =5\n\r"); |
thomasstrcic | 1:d446f0124474 | 159 | |
jujuonthebeat | 0:5755bf39c144 | 160 | break; |
jujuonthebeat | 0:5755bf39c144 | 161 | |
jujuonthebeat | 0:5755bf39c144 | 162 | } |
jujuonthebeat | 0:5755bf39c144 | 163 | switch(etat) |
jujuonthebeat | 0:5755bf39c144 | 164 | { |
jujuonthebeat | 0:5755bf39c144 | 165 | case 0: |
thomasstrcic | 1:d446f0124474 | 166 | //led1.write(1); |
jujuonthebeat | 0:5755bf39c144 | 167 | led2.write(0); |
jujuonthebeat | 0:5755bf39c144 | 168 | break; |
jujuonthebeat | 0:5755bf39c144 | 169 | |
jujuonthebeat | 0:5755bf39c144 | 170 | case 1: |
jujuonthebeat | 0:5755bf39c144 | 171 | led1.write(0); |
jujuonthebeat | 0:5755bf39c144 | 172 | led2.write(0); |
jujuonthebeat | 0:5755bf39c144 | 173 | break; |
jujuonthebeat | 0:5755bf39c144 | 174 | |
jujuonthebeat | 0:5755bf39c144 | 175 | case 2: |
jujuonthebeat | 0:5755bf39c144 | 176 | led1.write(0); |
jujuonthebeat | 0:5755bf39c144 | 177 | led2.write(0); |
jujuonthebeat | 0:5755bf39c144 | 178 | break; |
jujuonthebeat | 0:5755bf39c144 | 179 | case 3: |
jujuonthebeat | 0:5755bf39c144 | 180 | break; |
jujuonthebeat | 0:5755bf39c144 | 181 | case 4: |
jujuonthebeat | 0:5755bf39c144 | 182 | led1.write(0); |
thomasstrcic | 1:d446f0124474 | 183 | //led2.write(1); |
thomasstrcic | 2:ae058dfdebac | 184 | servo(); |
jujuonthebeat | 0:5755bf39c144 | 185 | break; |
jujuonthebeat | 0:5755bf39c144 | 186 | } |
jujuonthebeat | 0:5755bf39c144 | 187 | |
jujuonthebeat | 0:5755bf39c144 | 188 | |
jujuonthebeat | 0:5755bf39c144 | 189 | } |
jujuonthebeat | 0:5755bf39c144 | 190 | } |