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(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() {
  if (digitalRead(inPin[0]) == HIGH) {
    digitalWrite(ledPin[0], HIGH);
    digitalWrite(ledPin[0], LOW);
  if (digitalRead(inPin[1]) == HIGH) {
    digitalWrite(ledPin[1], HIGH);
    digitalWrite(ledPin[1], LOW);

void play_start_tones() {
  for (int i = 0i < 3i++) {

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

Here is the final schematic for our game.


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