this is
Dependencies: mbed Servo Motor
Diff: main.cpp
- Revision:
- 6:648b5e2ede73
- Parent:
- 5:c2d2c1804d2e
- Child:
- 8:67b2471a7346
--- a/main.cpp Fri Oct 19 14:13:50 2018 +0000 +++ b/main.cpp Fri Oct 19 14:48:06 2018 +0000 @@ -3,15 +3,17 @@ #include "stdio.h" #include "Servo.h" #include "Motor.h" + DigitalOut leds[4] = {p25, p24, p23, p28}; -DigitalOut ledz[2] = {p27,p26}; +DigitalOut ledz[2] = {p27,p12}; DigitalIn button[4] = {p17, p18, p19, p20}; +Motor z(p26,p30,p29); Servo myservo(p21); Servo hmyservo(p22); -Motor m(p29); + float hpos; float pos; -float f; //Motor speed +float f = 1; //Motor speed int r; //used for randomly lighting LEDs int i; //counter int s; // seed @@ -22,6 +24,7 @@ int o; // preventative variable int w = 0; //counter for successful attempts int x; //count the number of times the motor runs +float timer; int main() { @@ -29,6 +32,8 @@ myservo=0.0; hmyservo.calibrate(0.0009,90.0); hmyservo=0.0; + printf("how hard(0.05 is difficult, 0.2 is easier)\n\r"); + scanf("%f", &timer); printf("Enter ten digit number\n\r"); scanf("%10d\n\r",&s); srand(s); @@ -38,7 +43,7 @@ for (i=0; i<10; i++){ //for r = rand()%4;//generate random number 0 to 3 leds[r] = 1;//light up one of the leds - wait(0.2);//have 0.5 seconds to respond + wait(0.3);//have 0.5 seconds to respond if (button[r] == 1) {//if good response printf("noice\n\r");//good @@ -48,7 +53,7 @@ leds[r] = 0; k=1; // ensure fail code isn't activated }//turn off again and loop - wait(0.02);//have 0.5 seconds to respond + wait(timer);//have 0.5 seconds to respond if (button[r] == 1) {//if good response printf("noice\n\r");//good @@ -58,17 +63,17 @@ leds[r] = 0; l=1; }//turn off again and loop - wait(0.02);//have 0.5 seconds to respond + wait(timer);//have 0.5 seconds to respond if (button[r] == 1) {//if good response printf("noice\n\r");//good ledz[0]=1; - wait(.2); + wait(0.2); ledz[0]=0; leds[r] = 0; m=1; }//turn off again and loop - wait(0.02);//have 0.5 seconds to respond + wait(timer);//have 0.5 seconds to respond if (button[r] == 1) {//if good response printf("noice\n\r");//good @@ -78,7 +83,7 @@ leds[r] = 0; n=1; }//turn off again and loop - wait(0.02);//have 0.5 seconds to respond + wait(timer);//have 0.5 seconds to respond if (button[r] == 1) {//if good response printf("noice\n\r");//good @@ -118,13 +123,13 @@ printf("you got %d out of 10 right!\n\r", w); if (w < 10) {//if, gun trigger - for (x=0; x<1; x++){ + f = -1.0; - m.speed(f); - wait(3); - m.speed(-f); - wait(3); - } + z.speed(f); + wait(1); + z.speed(0); + + for (pos =0.0; pos<=10.0; pos=pos+10.0) { myservo=(pos/10.0); wait (0.07); @@ -135,6 +140,9 @@ wait (0.07); printf("%f\n",pos); // pulls the trigger }//ends for + z.speed(-f); + wait(1); + z.speed(0); }//if else if (w >= 10) {//if, high five