 const int DIFFERENT_VALUES = 4;
-const int MAX_LENGTH = 20;
+const int MAX_LENGTH = 40;
 const int SHOW_DELAY = 1000;
 const int BLINK_DELAY = 300;
-const int DEBOUNCE_DELAY = 50;
+const int DEBOUNCE_DELAY = 200;
+const int READ_WAITING_DELAY = 200;
+const int FIRST_INPUT = 2;
+const int FIRST_OUTPUT = 6;
 
 int sequence[MAX_LENGTH];
 int currentLength = 0;
-
-// Set every pin to specified mode
-void setMode(int mode) {
-  for (int i = 0; i < DIFFERENT_VALUES; i++) {
-    pinMode(i, mode);
-  }
-  // To show current mode
-  if (mode == OUTPUT) {
-    digitalWrite(13, LOW);
-  } else {
-    digitalWrite(13, HIGH);
-  }
-}
 
 // Increase the random sequence in one element
 void newElement() {

  int pushedElement = -1;
  while (pushedElement == -1) {
    for (int i = 0; i < DIFFERENT_VALUES; i++) {
      if (digitalRead(i) ==  HIGH) {
        // Waits some milliseconds to prevent bouncing
        delay(DEBOUNCE_DELAY);

        waitForUnpush();

        pushedElement = i;
        // Doesn't read other inputs
        break;
      }
    }
  }
  return pushedElement;
}

void blinkCorrectElement(int element) {
  setMode(OUTPUT);
  while (true) {
    digitalWrite(element, HIGH);
    delay(BLINK_DELAY);
    digitalWrite(element, LOW);
    delay(BLINK_DELAY);
  }
}

void readSequence() {
  setMode(INPUT);
  for (int i = 0; i < currentLength; i++) {
    int pushed = readFirstPushed();
    if (sequence[i] != pushed) {
      // Wrong element, game over
      Serial.begin(9600);
      Serial.println("Game over");
      Serial.print("Sequence was ");
      Serial.print(sequence[i]);

  while (allInputsAreUnpushed == 0) {
    allInputsAreUnpushed = 1;
    for (int i = 0; i < DIFFERENT_VALUES; i++) {
      // Value to check must be LOW, because input is pull up
      if (digitalRead(i + FIRST_INPUT) ==  LOW) {
        // At least one input is not unpushed
        allInputsAreUnpushed = 0;
        // Doesn't read other inputs
        break;
      }
    }
    delay(READ_WAITING_DELAY);
  }
}

