this is
Dependencies: mbed Servo Motor
Diff: main.cpp
- Revision:
- 4:6888480c5133
- Parent:
- 3:a7c54d27d7f7
--- a/main.cpp Tue Oct 16 17:44:02 2018 +0000 +++ b/main.cpp Fri Oct 19 14:08:50 2018 +0000 @@ -1,15 +1,15 @@ -#include "mbed.h" +#include "mbed.h" // required libraries #include "stdlib.h" #include "stdio.h" #include "Servo.h" -DigitalOut leds[4] = {p25, p24, p23, p28}; -DigitalOut ledz[2] = {p27,p26}; -DigitalIn button[4] = {p17, p18, p19, p20}; -Servo myservo(p21); -Servo hmyservo(p22); -float hpos; -float pos; +DigitalOut leds[4] = {p25, p24, p23, p28}; // defining which pins go to the game's LEDs +DigitalOut ledz[2] = {p27,p26}; // defining which pins go to the success/failure lights +DigitalIn button[4] = {p17, p18, p19, p20}; // defining which pins receive input from the buttons +Servo myservo(p21); // defining the nerf gun servo +Servo hmyservo(p22); // defining the high-five servo +float hpos; // position variable for the high-five servo +float pos; // position variable for the nerf gun servo int r; //used for randomly lighting LEDs int i; //counter int s; // seed @@ -19,20 +19,20 @@ int n; // preventatibe variable int o; // preventative variable int w = 0; //counter for successful attempts -float timer; +float timer; // variable used to easily change the pace of the game int main() { - myservo.calibrate(0.0009,90.0); - myservo=0.0; - hmyservo.calibrate(0.0009,90.0); - hmyservo=0.0; - printf("Enter ten digit number\n\r"); - scanf("%10d\n\r",&s); - srand(s); - k=0; - timer = .02; - wait(3); + myservo.calibrate(0.0009,90.0); // calibrating nerf gun servo + myservo=0.0; // initial position of nerf gun servo + hmyservo.calibrate(0.0009,90.0); // calibrating high-five servo + hmyservo=0.0; // initial position of high-five servo + printf("Enter ten digit number\n\r"); // requesting user for ten digits + scanf("%10d\n\r",&s); // scanning those digits into variable s + srand(s); // seeding rand() with those ten digits + k=0; // initializing + timer = .02; // initializing + wait(3); // give the player three seconds from putting in twn digits to the start of the game for (i=0; i<10; i++){ //for r = rand()%4;//generate random number 0 to 3