Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int score = 0;      
  2. int button = 2;  
  3. int a = 3;          
  4.  
  5. void setup() {
  6.   Serial.begin(9600);          
  7.   pinMode(button, INPUT);      
  8.   for(int x = 3; x <= 11; x++)
  9.    {
  10.     pinMode(x, OUTPUT);  
  11.    }
  12.   Serial.println("Gameplay: ");                                                                            
  13.   Serial.println("The led that you want will light up for 2 seconds");
  14.   Serial.println("The leds will then light up in rotation");
  15.   Serial.println("When the led you want is lit up, press the button");
  16.   Serial.println("If the led you want is still lit up, your score goes up");
  17.   Serial.println();
  18.   Serial.println("Get the highscore and beat all your friends in this fast paced, exciting, and fun game!!! :) ");
  19.   Serial.println();
  20.   Serial.println();
  21. }
  22. // the loop routine runs over and over again forever:
  23. void loop() {
  24.   randomSeed(analogRead(A0));      
  25.   int goal = random(3, 11);              
  26.   Serial.print("Your goal is pin: ");      
  27.   Serial.println(goal);                  
  28.   digitalWrite(goal, HIGH);                
  29.   delay(2000);                            
  30.   digitalWrite(goal, LOW);                  
  31.   while(digitalRead(button)==LOW)
  32.     {
  33.       if(a >3)
  34.         digitalWrite((a-1), LOW);
  35.       else
  36.         digitalWrite(11, LOW);
  37.       digitalWrite(a, HIGH);
  38.       delay(150);
  39.       if(a >= 11)
  40.         a = 3;
  41.       else
  42.         a++;
  43.     }
  44.   if((a-1)==goal)
  45.     {
  46.     score++;
  47.       if(score >= highscore)
  48.         {
  49.           highscore = score;
  50.         }
  51.         Serial.print("Congratulations! Your score is: ");
  52.         Serial.println(score);
  53.     }
  54.   else
  55.     {
  56.     Serial.println("Sorry, your game is over :(");
  57.     Serial.print("Your score was: ");
  58.     Serial.print(score);
  59.     Serial.println("Press the reset button to start again");
  60.     while(1);
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement