Adrien Audouard
/
121
main.cpp@0:4b41de80ef88, 2015-05-28 (annotated)
- Committer:
- Ridaz
- Date:
- Thu May 28 08:22:12 2015 +0000
- Revision:
- 0:4b41de80ef88
; ;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Ridaz | 0:4b41de80ef88 | 1 | #include "mbed.h" |
Ridaz | 0:4b41de80ef88 | 2 | |
Ridaz | 0:4b41de80ef88 | 3 | DigitalOut myled(LED1); |
Ridaz | 0:4b41de80ef88 | 4 | DigitalOut myled2(LED2); |
Ridaz | 0:4b41de80ef88 | 5 | DigitalOut myled3(LED3); |
Ridaz | 0:4b41de80ef88 | 6 | |
Ridaz | 0:4b41de80ef88 | 7 | DigitalIn bp1(p21); |
Ridaz | 0:4b41de80ef88 | 8 | DigitalIn bp2(p22); |
Ridaz | 0:4b41de80ef88 | 9 | DigitalIn bp3(p23); |
Ridaz | 0:4b41de80ef88 | 10 | |
Ridaz | 0:4b41de80ef88 | 11 | Timer timer; |
Ridaz | 0:4b41de80ef88 | 12 | int tab[3] = {0}; |
Ridaz | 0:4b41de80ef88 | 13 | int in[3] = {0}; |
Ridaz | 0:4b41de80ef88 | 14 | bool perdu = false; |
Ridaz | 0:4b41de80ef88 | 15 | bool gagner = false; |
Ridaz | 0:4b41de80ef88 | 16 | |
Ridaz | 0:4b41de80ef88 | 17 | int main() |
Ridaz | 0:4b41de80ef88 | 18 | { |
Ridaz | 0:4b41de80ef88 | 19 | srand(time(NULL)); |
Ridaz | 0:4b41de80ef88 | 20 | |
Ridaz | 0:4b41de80ef88 | 21 | while(1) { |
Ridaz | 0:4b41de80ef88 | 22 | for (int i = 0; i < 3;i++) |
Ridaz | 0:4b41de80ef88 | 23 | in[i] =0; |
Ridaz | 0:4b41de80ef88 | 24 | for (int i = 0; i < 3; i++) |
Ridaz | 0:4b41de80ef88 | 25 | tab[i] = (rand()%3) + 1; |
Ridaz | 0:4b41de80ef88 | 26 | for (int i =0; i < 3; i++) { |
Ridaz | 0:4b41de80ef88 | 27 | switch(tab[i]) { |
Ridaz | 0:4b41de80ef88 | 28 | case 1: |
Ridaz | 0:4b41de80ef88 | 29 | myled.write(1); |
Ridaz | 0:4b41de80ef88 | 30 | break; |
Ridaz | 0:4b41de80ef88 | 31 | case 2: |
Ridaz | 0:4b41de80ef88 | 32 | myled2.write(1); |
Ridaz | 0:4b41de80ef88 | 33 | break; |
Ridaz | 0:4b41de80ef88 | 34 | case 3: |
Ridaz | 0:4b41de80ef88 | 35 | myled3.write(1); |
Ridaz | 0:4b41de80ef88 | 36 | break; |
Ridaz | 0:4b41de80ef88 | 37 | } |
Ridaz | 0:4b41de80ef88 | 38 | wait(1); |
Ridaz | 0:4b41de80ef88 | 39 | myled.write(0); |
Ridaz | 0:4b41de80ef88 | 40 | myled2.write(0); |
Ridaz | 0:4b41de80ef88 | 41 | myled3.write(0); |
Ridaz | 0:4b41de80ef88 | 42 | wait(0.5); |
Ridaz | 0:4b41de80ef88 | 43 | } |
Ridaz | 0:4b41de80ef88 | 44 | timer.start(); |
Ridaz | 0:4b41de80ef88 | 45 | while(timer.read_ms() < 500 && !perdu && !gagner) { |
Ridaz | 0:4b41de80ef88 | 46 | int i = 0; |
Ridaz | 0:4b41de80ef88 | 47 | if (bp1) |
Ridaz | 0:4b41de80ef88 | 48 | in[i] = 1; |
Ridaz | 0:4b41de80ef88 | 49 | if (bp2) |
Ridaz | 0:4b41de80ef88 | 50 | in[i] = 2; |
Ridaz | 0:4b41de80ef88 | 51 | if (bp3) |
Ridaz | 0:4b41de80ef88 | 52 | in[i] = 3; |
Ridaz | 0:4b41de80ef88 | 53 | if (in[i] != 0 && in[i] == tab[i]) { |
Ridaz | 0:4b41de80ef88 | 54 | i++; |
Ridaz | 0:4b41de80ef88 | 55 | timer.reset(); |
Ridaz | 0:4b41de80ef88 | 56 | if ( i == 3) |
Ridaz | 0:4b41de80ef88 | 57 | gagner = true; |
Ridaz | 0:4b41de80ef88 | 58 | myled = 1; |
Ridaz | 0:4b41de80ef88 | 59 | myled2 = 1; |
Ridaz | 0:4b41de80ef88 | 60 | myled3 = 1; |
Ridaz | 0:4b41de80ef88 | 61 | wait(1); |
Ridaz | 0:4b41de80ef88 | 62 | } |
Ridaz | 0:4b41de80ef88 | 63 | if (in[i] != 0 && in[i] != tab[i]) { |
Ridaz | 0:4b41de80ef88 | 64 | perdu = true; |
Ridaz | 0:4b41de80ef88 | 65 | } |
Ridaz | 0:4b41de80ef88 | 66 | } |
Ridaz | 0:4b41de80ef88 | 67 | } |
Ridaz | 0:4b41de80ef88 | 68 | } |