Arduino memory game -


this game has 4 leds , 4 buttons. game turning randomly leds on , off.

the player should able push right button whenever sees 1 led turned on.

the leds should turning on , off incerasing speed, reaction time of player shorter , shorter

i have code know how add more leds , buttons.

const int button1 = a0;  const int button2 = a1; const int button3 = a2;  const int button4 = a3; int led1 = 2;  int led2 = 3;  int led3 = 4;  int led4 = 5;  int ran; int right = 0; int ledorder[9]; int guessorder[9];  void setup()  {   serial.begin(9600);    pinmode(led1,output);   pinmode(led2,output);   pinmode(led3,output);   pinmode(led4,output);   pinmode(button1,input);   pinmode(button2,input);   pinmode(button3,input);   pinmode(button4,input); } void randomled() {   (int = 0; < 9; i++) {      ran = random(1,20);     if (ran < 11) {       digitalwrite(led1,high);       delay(500);       digitalwrite(led1,low);       ledorder[i] = 1;      }     else {       digitalwrite(led2,high);       delay(500);       digitalwrite(led2,low);       ledorder[i] = 2;     }     delay(500);   } } void btnclick() {   int ans = 0;   while (ans < 9) {      if (digitalread(button1) == high) {       guessorder[ans] = 1;       ans++;       while (digitalread(button1) == high) {       }     }     else if (digitalread(button2) == high) {       guessorder[ans] = 2;       ans++;       while (digitalread(button2) == high) {       }     }   } } void loop() {     serial.print("press button1 start \n");     while (digitalread(button1) == low) {     }     randomled();     btnclick();     (int = 0; < 9; = + 1) {       serial.print("guess: ");       serial.print(guessorder[i]);       serial.print(" answer: ");       serial.print(ledorder[i]);       if (guessorder[i] == ledorder[i]) {         serial.print(" right");         right++;       } else {         serial.print(" wrong");       }       serial.print("\n ");     }     serial.print(right);     serial.print("/9\n");     delay(2000);  } 

if understand question correctly, increase led blink rate(when led's come on) each time user gets previous game right. if true should try put loop in for/if user got the previous one(game) right increase blink rate simple increment( i++;). comment if feel clarified enough or if asking else


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -