Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int score = 0;
- int button = 2;
- int a = 3;
- void setup() {
- Serial.begin(9600);
- pinMode(button, INPUT);
- for(int x = 3; x <= 11; x++)
- {
- pinMode(x, OUTPUT);
- }
- Serial.println("Gameplay: ");
- Serial.println("The led that you want will light up for 2 seconds");
- Serial.println("The leds will then light up in rotation");
- Serial.println("When the led you want is lit up, press the button");
- Serial.println("If the led you want is still lit up, your score goes up");
- Serial.println();
- Serial.println("Get the highscore and beat all your friends in this fast paced, exciting, and fun game!!! :) ");
- Serial.println();
- Serial.println();
- }
- // the loop routine runs over and over again forever:
- void loop() {
- randomSeed(analogRead(A0));
- int goal = random(3, 11);
- Serial.print("Your goal is pin: ");
- Serial.println(goal);
- digitalWrite(goal, HIGH);
- delay(2000);
- digitalWrite(goal, LOW);
- while(digitalRead(button)==LOW)
- {
- if(a >3)
- digitalWrite((a-1), LOW);
- else
- digitalWrite(11, LOW);
- digitalWrite(a, HIGH);
- delay(150);
- if(a >= 11)
- a = 3;
- else
- a++;
- }
- if((a-1)==goal)
- {
- score++;
- if(score >= highscore)
- {
- highscore = score;
- }
- Serial.print("Congratulations! Your score is: ");
- Serial.println(score);
- }
- else
- {
- Serial.println("Sorry, your game is over :(");
- Serial.print("Your score was: ");
- Serial.print(score);
- Serial.println("Press the reset button to start again");
- while(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement