header
Connect Two Buttons

Connect two buttons to pins 2 and 4.

connect two buttons

Now we need to check that these buttons are connected properly. So, for our first step, let's comment out our two functions and add some code that will flash the leds when the buttons are pushed.

// Use arrays to hold our pin numbers and the pattern.
// This will let us use a loop to go through the values.
int speaker = 9;
int ledPin[] = { 67 };
int inPin[] = { 24 };
int pattern[5];  // This array will hold the pattern we generate.

// Need some notes
int C = 523;
int F = 698;

void setup() {
  pinMode(speakerOUTPUT);
  pinMode(ledPin[0], OUTPUT);
  pinMode(ledPin[1], OUTPUT);
  pinMode(inPin[0], INPUT);
  pinMode(inPin[1], INPUT);

  randomSeed(analogRead(0));  // Ensures that pattern is different at every reset
}

void loop() {
  //play_start_tones();
  //generate_pattern();
  if (digitalRead(inPin[0]) == HIGH) {
    digitalWrite(ledPin[0], HIGH);
    delay(250);
    digitalWrite(ledPin[0], LOW);
    delay(250);
  }
  if (digitalRead(inPin[1]) == HIGH) {
    digitalWrite(ledPin[1], HIGH);
    delay(250);
    digitalWrite(ledPin[1], LOW);
    delay(250);
  }
}


void play_start_tones() {
  for (int i = 0i < 3i++) {
    tone(speakerC);
    delay(350);
    noTone(speaker);
    delay(350);
  }
  tone(speakerF);
  delay(350);
  noTone(speaker);
}

void generate_pattern() {
  // Generate random pattern
  for (int i = 0i < 5i++) {
    int number = random(0,2);
    pattern[i] = number;
    digitalWrite(ledPin[number], HIGH);
    delay(500);
    digitalWrite(ledPin[number], LOW);
    delay(500);
  }
}

Here is the final schematic for our game.

schematic

We now have all the electronics for our game connected. The rest of the work needs to be done in our program. So, let's see how we'll do that.

Programming our game

Game Home