this is

Dependencies:   mbed Servo Motor

main.cpp

Committer:
m210690
Date:
2018-10-09
Revision:
1:cfefb1f7549e
Parent:
0:df0146f8b257
Child:
2:260539a94ad7

File content as of revision 1:cfefb1f7549e:

#include "mbed.h"
#include "stdlib.h"
#include "stdio.h"

DigitalOut leds[4] = {p25, p24, p23, p22};
DigitalIn button[4] = {p17, p18, p19, p20};
int r; //used for randomly lighting LEDs
int i; //counter

int main() {
    for (i=0; i<10; i++){ //if
        r = rand()%4;//generate random number 0 to 3
        leds[r] = 1;//light up one of the leds
        wait(0.5);//have 0.5 seconds to respond
        if (button[r] == 1) {//if good response
            printf("noice\n\r");//good
            leds[r] = 0;}//turn off again and loop
        else {printf("fail\n\r");//else you lose
        //activate nerf gun
        //end code
        }//else
        wait(1);
        leds[r] = 0;
        wait(1);
        printf("%d", r);
    }//for
    if (i == 10) {//activate high five}
    }//if
}//main