this is
Dependencies: mbed Servo Motor
main.cpp@1:cfefb1f7549e, 2018-10-09 (annotated)
- Committer:
- m210690
- Date:
- Tue Oct 09 15:41:52 2018 +0000
- Revision:
- 1:cfefb1f7549e
- Parent:
- 0:df0146f8b257
- Child:
- 2:260539a94ad7
this is pretty good guys
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
m210690 | 0:df0146f8b257 | 1 | #include "mbed.h" |
m210690 | 1:cfefb1f7549e | 2 | #include "stdlib.h" |
m210690 | 1:cfefb1f7549e | 3 | #include "stdio.h" |
m210690 | 0:df0146f8b257 | 4 | |
m210690 | 1:cfefb1f7549e | 5 | DigitalOut leds[4] = {p25, p24, p23, p22}; |
m210690 | 1:cfefb1f7549e | 6 | DigitalIn button[4] = {p17, p18, p19, p20}; |
m210690 | 1:cfefb1f7549e | 7 | int r; //used for randomly lighting LEDs |
m210690 | 1:cfefb1f7549e | 8 | int i; //counter |
m210690 | 0:df0146f8b257 | 9 | |
m210690 | 0:df0146f8b257 | 10 | int main() { |
m210690 | 1:cfefb1f7549e | 11 | for (i=0; i<10; i++){ //if |
m210690 | 1:cfefb1f7549e | 12 | r = rand()%4;//generate random number 0 to 3 |
m210690 | 1:cfefb1f7549e | 13 | leds[r] = 1;//light up one of the leds |
m210690 | 1:cfefb1f7549e | 14 | wait(0.5);//have 0.5 seconds to respond |
m210690 | 1:cfefb1f7549e | 15 | if (button[r] == 1) {//if good response |
m210690 | 1:cfefb1f7549e | 16 | printf("noice\n\r");//good |
m210690 | 1:cfefb1f7549e | 17 | leds[r] = 0;}//turn off again and loop |
m210690 | 1:cfefb1f7549e | 18 | else {printf("fail\n\r");//else you lose |
m210690 | 1:cfefb1f7549e | 19 | //activate nerf gun |
m210690 | 1:cfefb1f7549e | 20 | //end code |
m210690 | 1:cfefb1f7549e | 21 | }//else |
m210690 | 1:cfefb1f7549e | 22 | wait(1); |
m210690 | 1:cfefb1f7549e | 23 | leds[r] = 0; |
m210690 | 1:cfefb1f7549e | 24 | wait(1); |
m210690 | 1:cfefb1f7549e | 25 | printf("%d", r); |
m210690 | 1:cfefb1f7549e | 26 | }//for |
m210690 | 1:cfefb1f7549e | 27 | if (i == 10) {//activate high five} |
m210690 | 1:cfefb1f7549e | 28 | }//if |
m210690 | 1:cfefb1f7549e | 29 | }//main |