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