Maggie's Final Project

From CSclasswiki
Jump to: navigation, search




Project Proposal

Introduction

My project will have 3 parts. I will:

  1. Use the Arduino to display my name on a 64-LED matrix. (Part 1: Displaying My Name)
  2. Utilize the Arduino and a passive buzzer to play the Tetris theme. (Part 2: Tetris)
  3. Set up 2 buttons, one of which will pause the music and the other of which will loop back to the beginning. (Part 3: Buttons)

Implementation

Software

I will be programming the Arduino C.

Libraries

I will be using the LedControl and pitches libraries.

Hardware

  1. Arduino Mega2560
  2. 64-LED Matrix
  3. Breadboard
  4. Adapter
  5. USB-C cable
  6. Passive buzzer
  7. 2 push buttons
  8. Wiring kit

Experiments

Part 1: Displaying My Name

For the first part of my project, I utilized the 64-LED matrix and the Arduino. I connected the two as follows: (insert diagram from manual here)

Then, I uploaded the following sketch to the Arduino: [1]

/*
//We always have to include the library
#include "LedControl.h"
#include "pitches.h"

 Now we need a LedControl to work with.
 ***** These pin numbers will probably not work with your hardware *****
 pin 12 is connected to the DataIn 
 pin 11 is connected to the CLK 
 pin 10 is connected to LOAD 
 We have only a single MAX72XX.
 */
LedControl lc=LedControl(12,10,11,1);

/* we always wait a bit between updates of the display */
unsigned long delaytime=1000;

void setup() {
  /*
   The MAX72XX is in power-saving mode on startup,
   we have to do a wakeup call
   */
  lc.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,5);
  /* and clear the display */
  lc.clearDisplay(0);
  Serial.begin(9600);
  
}
  byte M[8]={B10000010, B11000010, B11101110, B10111010, B10000010, B10000010, B10000010, B10000010};
  byte A[8]={B00011000, B00011000, B00100100, B00100100, B01111110, B01000010, B10000001, B10000001};
  byte G[8]={B00111101, B01100011, B11000001, B11000000, B11000111, B11000001, B01100011, B00111110};
  byte I[8]={B00111100, B00011000, B00011000, B00011000, B00011000, B00011000, B00011000, B00111100};
  byte E[8]={B11111111, B01100001, B01101000, B01101000, B01111000, B01101000, B01100001, B11111111};

/*
 This method will display the characters for the
 name "Maggie" one after the other on the matrix. 
 (you need at least 5x7 leds to see the whole chars)
 */
void writeNameOnMatrix() {
  /* here is the data for the characters */
  
  /* now display them one by one with a small delay */
  /*Display the M.*/
  lc.setRow(0,0,M[0]);
  Serial.println("M1");
  lc.setRow(0,1,M[1]);
  Serial.println("M2");
  lc.setRow(0,2,M[2]);
  Serial.println("M3");
  lc.setRow(0,3,M[3]);
  Serial.println("M4");
  lc.setRow(0,4,M[4]);
  Serial.println("M5");
  lc.setRow(0,5,M[5]);
  Serial.println("M6");
  lc.setRow(0,6,M[6]);
  Serial.println("M7");
  lc.setRow(0,7,M[7]);
  Serial.println("M8");
  delay(delaytime);
  //Display the A. 
  lc.setRow(0,0,A[0]);
  lc.setRow(0,1,A[1]);
  lc.setRow(0,2,A[2]);
  lc.setRow(0,3,A[3]);
  lc.setRow(0,4,A[4]);
  lc.setRow(0,5,A[5]);
  lc.setRow(0,6,A[6]);
  lc.setRow(0,7,A[7]);
  delay(delaytime);
  //Display the G.
  lc.setRow(0,0,G[0]);
  lc.setRow(0,1,G[1]);
  lc.setRow(0,2,G[2]);
  lc.setRow(0,3,G[3]);
  lc.setRow(0,4,G[4]);
  lc.setRow(0,5,G[5]);
  lc.setRow(0,6,G[6]);
  lc.setRow(0,7,G[7]);
  delay(delaytime);
  //Display the second G. 
  lc.setRow(0,0,G[0]);
  lc.setRow(0,1,G[1]);
  lc.setRow(0,2,G[2]);
  lc.setRow(0,3,G[3]);
  lc.setRow(0,4,G[4]);
  lc.setRow(0,5,G[5]);
  lc.setRow(0,6,G[6]);
  lc.setRow(0,7,G[7]);
  delay(delaytime);
  lc.setRow(0,0,I[0]);
  lc.setRow(0,1,I[1]);
  lc.setRow(0,2,I[2]);
  lc.setRow(0,3,I[3]);
  lc.setRow(0,4,I[4]);
  lc.setRow(0,5,I[5]);
  lc.setRow(0,6,I[6]);
  lc.setRow(0,7,I[7]);
  delay(delaytime);
  lc.setRow(0,0,E[0]);
  lc.setRow(0,1,E[1]);
  lc.setRow(0,2,E[2]);
  lc.setRow(0,3,E[3]);
  lc.setRow(0,4,E[4]);
  lc.setRow(0,5,E[5]);
  lc.setRow(0,6,E[6]);
  lc.setRow(0,7,E[7]);
  tone(8, NOTE_B4, 500);
  delay(delaytime);
}


void loop() { 
  writeNameOnMatrix();
  
  //lc.setRow(0, 0, A[0]);
}

This had the following results:

Part 2: Tetris

For the second part of my project, I decided to hook up a passive buzzer to the Arduino alongside the LED matrix. The goal was to have the passive buzzer play the Tetris theme, or at least approximate it as closely as possible. Furthermore, as each note played, the letter indicating that note in musical notation would flash on the LED matrix.

The code I used is below: [1] [2]

 
#include "pitches.h"
#include "LedControl.h"

//Initializes a LedControl object.
LedControl lc=LedControl(12, 10, 11, 1);

//Sets up the letters of the scale
byte C[8]={B00111101, B01100011, B11000001, B11000000, B11000000, B11000000, B01100001, B00111110};
byte D[8]={B11111000, B01000110, B01000011, B01000011, B01000011, B01000011, B01000110, B11111000};
byte E[8]={B11111111, B01100001, B01101000, B01101000, B01111000, B01101000, B01100001, B11111111};
byte F[8]={B11111111, B10000000, B10000000, B11110000, B10000000, B10000000, B10000000, B10000000};
byte G[8]={B00111101, B01100011, B11000001, B11000000, B11000111, B11000001, B01100011, B00111110};
byte A[8]={B00011000, B00011000, B00100100, B00100100, B01111110, B01000010, B10000001, B10000001};
byte B[8]={B11111110, B01100011, B01100011, B01111110, B01100011, B01100001, B01100011, B11111110};
//I divided the Tetris theme into sections separated by rests. In musical parlance, such sections are called phrases.
//The notes for the first phrase:
int phrase1Notes[] = {
  NOTE_E5, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_A4, 
  NOTE_A4, NOTE_C5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_C5, 
  NOTE_D5, NOTE_E5, NOTE_C5, NOTE_A4, NOTE_A4};

//The duration of the notes for the first phrase:
int phrase1Rhythms[] = {400, 200, 200, 400, 200, 200, 400, 200, 200,
400, 200, 200, 600, 200, 400, 400, 400, 400, 400};

//The letters representing the notes in the first phrase.
  char phrase1Letters[] = {
    'e', 'b', 'c', 'd', 'c', 'b', 'a', 'a', 'c', 'e', 'd', 'c', 'b', 
    'c', 'd', 'e', 'c', 'a', 'a'
  };

//The notes for the second phrase:
  int phrase2Notes[] = {NOTE_D5, NOTE_F5,
  NOTE_A5, NOTE_G5, NOTE_F5, NOTE_E5, NOTE_C5, NOTE_E5, NOTE_D5,
  NOTE_C5, NOTE_B4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_C5,
  NOTE_A4, NOTE_A4};

//The durations of the notes in the second phrase:
  int phrase2Rhythms[] = {400, 200, 400, 200, 200, 600, 200, 400, 200,
  200, 400, 200, 200, 400, 400, 400, 400, 400};

//The letters representing the notes in the second phrase:
  char phrase2Letters[] = {
    'd', 'f', 'a', 'g', 'f', 'e', 'c', 'e', 'd', 'c', 'b', 'b', 'c',
    'd', 'e', 'c', 'a', 'a'
  };

  //The notes in the third phrase:
  
  int phrase3Notes[] = {NOTE_E5, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_A4, 
  NOTE_A4, NOTE_C5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_C5, 
  NOTE_D5, NOTE_E5, NOTE_C5, NOTE_A4, NOTE_A4};

  //The durations of the notes in the third phrase:
  int phrase3Rhythms[] = {400, 200, 200, 400, 200, 200, 400, 200, 200,
400, 200, 200, 600, 200, 400, 400, 400, 400, 400};


  //The letters representing the notes in the third phrase:
  char phrase3Letters[] = {
    'e', 'b', 'c', 'd', 'c', 'b', 'a', 'a', 'c', 'e', 'd', 'c', 'b', 'c', 'd', 'e', 'c', 'a', 'a'
  };

  //The notes in the fourth phrase.
  int phrase4Notes[] = {NOTE_D5, NOTE_F5,
  NOTE_A5, NOTE_G5, NOTE_F5, NOTE_E5, NOTE_C5, NOTE_E5, NOTE_D5,
  NOTE_C5, NOTE_B4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_C5,
  NOTE_A4, NOTE_A4};

  //The durations of the notes in the fourth phrase. 
  
  int phrase4Rhythms[] = {400, 200, 400, 200, 200, 600, 200, 400, 200,
  200, 400, 200, 200, 400, 400, 400, 400, 400};

  //The letters representing the notes in the fourth phrase. 

  char phrase4Letters[] = {
    'd', 'f', 'a', 'g', 'f', 'e', 'c', 'e', 'd', 'c', 'b', 'b', 'c', 'd', 'e', 'c', 'a', 'a'
  };

  //The notes in the fifth phrase.
  int phrase5Notes[] = { NOTE_E4, NOTE_C4, NOTE_D4, NOTE_B3, NOTE_C4, 
  NOTE_A3, NOTE_GS3, NOTE_B3};
  //The durations of the notes in the fifth phrase.
  int phrase5Rhythms[] = {800, 800, 800, 800, 800, 800, 800, 400};
  //The letters representing the notes in the fifth phrase: 
  char phrase5Letters[] = {
    'e', 'c', 'd', 'b', 'c', 'a', 'g', 'b'
  };
  //The notes of the sixth phrase.
  int phrase6Notes[] = { NOTE_E4, NOTE_C4, NOTE_D4, NOTE_B3,
  NOTE_C4, NOTE_E4, NOTE_A4, NOTE_A4, NOTE_GS4};
  //The durations of the notes in the sixth phrase.
  int phrase6Rhythms[] = {800, 800, 800, 800, 400, 400, 400, 400, 800};
  //The letters representing the notes in the sixth phrase.
  char phrase6Letters[] = {
    'e', 'c', 'd', 'b', 'c', 'e', 'a', 'a', 'g'
  };


//This function prints the letter representing a note. 
void printLetter(char letter) {
  //Prints C. 
  if (letter=='c') {
    lc.setRow(0,0,C[0]);
    lc.setRow(0,1,C[1]);
    lc.setRow(0,2,C[2]);
    lc.setRow(0,3,C[3]);
    lc.setRow(0,4,C[4]);
    lc.setRow(0,5,C[5]);
    lc.setRow(0,6,C[6]);
    lc.setRow(0,7,C[7]);
  //Prints D. 
  } else if (letter=='d') {
    lc.setRow(0,0,D[0]);
    lc.setRow(0,1,D[1]);
    lc.setRow(0,2,D[2]);
    lc.setRow(0,3,D[3]);
    lc.setRow(0,4,D[4]);
    lc.setRow(0,5,D[5]);
    lc.setRow(0,6,D[6]);
    lc.setRow(0,7,D[7]);
  //Prints E. 
  } else if (letter=='e') {
    lc.setRow(0,0,E[0]);
    lc.setRow(0,1,E[1]);
    lc.setRow(0,2,E[2]);
    lc.setRow(0,3,E[3]);
    lc.setRow(0,4,E[4]);
    lc.setRow(0,5,E[5]);
    lc.setRow(0,6,E[6]);
    lc.setRow(0,7,E[7]);
  //Prints F. 
  } else if (letter=='f') {
    lc.setRow(0,0,F[0]);
    lc.setRow(0,1,F[1]);
    lc.setRow(0,2,F[2]);
    lc.setRow(0,3,F[3]);
    lc.setRow(0,4,F[4]);
    lc.setRow(0,5,F[5]);
    lc.setRow(0,6,F[6]);
    lc.setRow(0,7,F[7]);
  //Prints G. 
  } else if (letter=='g') {
    lc.setRow(0,0,G[0]);
    lc.setRow(0,1,G[1]);
    lc.setRow(0,2,G[2]);
    lc.setRow(0,3,G[3]);
    lc.setRow(0,4,G[4]);
    lc.setRow(0,5,G[5]);
    lc.setRow(0,6,G[6]);
    lc.setRow(0,7,G[7]);
  //Prints A. 
  } else if (letter == 'a') {
    lc.setRow(0,0,A[0]);
    lc.setRow(0,1,A[1]);
    lc.setRow(0,2,A[2]);
    lc.setRow(0,3,A[3]);
    lc.setRow(0,4,A[4]);
    lc.setRow(0,5,A[5]);
    lc.setRow(0,6,A[6]);
    lc.setRow(0,7,A[7]);
  //Prints B. 
  } else if (letter=='b') {
    lc.setRow(0,0,C[0]);
    lc.setRow(0,1,C[1]);
    lc.setRow(0,2,C[2]);
    lc.setRow(0,3,C[3]);
    lc.setRow(0,4,C[4]);
    lc.setRow(0,5,C[5]);
    lc.setRow(0,6,C[6]);
    lc.setRow(0,7,C[7]);
  }
}

void setup() {
  // put your setup code here, to run once:
  //Ensures that the LED matrix is not shut off.
  lc.shutdown(0, false);
  //Sets the intensity of the LEDs. 
  lc.setIntensity(0, 8);
  //Clears the LED matrix.
  lc.clearDisplay(0);
  
  
}

void loop() {
  // put your main code here, to run repeatedly:
  //Executes the first phrase. Iterates over the lists of notes, durations, and letters. 
   START :for (int thisNote = 0; thisNote < 19; thisNote++)  {
    //Plays a note.
    tone(8, phrase1Notes[thisNote], phrase1Rhythms[thisNote]);
    //Prints a letter. 
    printLetter(phrase1Letters[thisNote]);
    
    delay(200);
  }
  //Executes the second phrase, iterating over the lists of notes, duration, and letters.
  for (int thisNote= 0; thisNote < 18; thisNote++) {
    //Plays a note.
    tone(8, phrase2Notes[thisNote], phrase2Rhythms[thisNote]);
    //Displays a letter. 
    printLetter(phrase2Letters[thisNote]);
    
    delay(200);
  }
  //Executes the third phrase, iterating over the lists of notes, duration, and letters. 
  for (int thisNote = 0; thisNote < 19; thisNote++) {
    //Plays a note. 
    tone(8, phrase3Notes[thisNote], phrase3Rhythms[thisNote]);
    //Displays the associated letter. 
    printLetter(phrase3Letters[thisNote]);
    
    delay(200);
  }
  //Executes the fourth phrase, iterating over the list of notes, durations, and letters.
  for (int thisNote = 0; thisNote < 18; thisNote++) {
    //Plays a note.
    tone(8, phrase4Notes[thisNote], phrase4Rhythms[thisNote]);
    //Displays the associated letter. 
    printLetter(phrase4Letters[thisNote]);
    
    delay(200);
  }
  //Executes the fifth phrase, iterating over the list of notes, durations, and letters.
  for (int thisNote=0; thisNote<8; thisNote++) {
    //Plays a note.
    tone(8, phrase5Notes[thisNote], phrase5Rhythms[thisNote]);
    //Displays the associated letter.
    printLetter(phrase5Letters[thisNote]);
    
    delay(200);
    
  }

  //Executes the sixth phrase, iterating over the lists of notes, durations, and letters.
  for (int thisNote=0; thisNote<9; thisNote++){
    //Plays a note.
    tone(8, phrase6Notes[thisNote], phrase6Rhythms[thisNote]);
    //Displays the associated letter.
    printLetter(phrase6Letters[thisNote]);
    
    delay(200);
  }
  delay(2000);
}

Part 3: Buttons

Next, I implemented 2 buttons. The first button paused the Tetris theme. The second button rewound back to the beginning of the Tetris theme.

The code I used is below: [1] [2] [3]

 
#include "pitches.h"
#include "LedControl.h"

//Initializes a LedControl object.
LedControl lc=LedControl(12, 10, 11, 1);

//Sets up the letters of the scale
byte C[8]={B00111101, B01100011, B11000001, B11000000, B11000000, B11000000, B01100001, B00111110};
byte D[8]={B11111000, B01000110, B01000011, B01000011, B01000011, B01000011, B01000110, B11111000};
byte E[8]={B11111111, B01100001, B01101000, B01101000, B01111000, B01101000, B01100001, B11111111};
byte F[8]={B11111111, B10000000, B10000000, B11110000, B10000000, B10000000, B10000000, B10000000};
byte G[8]={B00111101, B01100011, B11000001, B11000000, B11000111, B11000001, B01100011, B00111110};
byte A[8]={B00011000, B00011000, B00100100, B00100100, B01111110, B01000010, B10000001, B10000001};
byte B[8]={B11111110, B01100011, B01100011, B01111110, B01100011, B01100001, B01100011, B11111110};
//I divided the Tetris theme into sections separated by rests. In musical parlance, such sections are called phrases.
//The notes for the first phrase:
int phrase1Notes[] = {
  NOTE_E5, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_A4, 
  NOTE_A4, NOTE_C5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_C5, 
  NOTE_D5, NOTE_E5, NOTE_C5, NOTE_A4, NOTE_A4};

//The duration of the notes for the first phrase:
int phrase1Rhythms[] = {400, 200, 200, 400, 200, 200, 400, 200, 200,
400, 200, 200, 600, 200, 400, 400, 400, 400, 400};

//The letters representing the notes in the first phrase.
  char phrase1Letters[] = {
    'e', 'b', 'c', 'd', 'c', 'b', 'a', 'a', 'c', 'e', 'd', 'c', 'b', 
    'c', 'd', 'e', 'c', 'a', 'a'
  };

//The notes for the second phrase:
  int phrase2Notes[] = {NOTE_D5, NOTE_F5,
  NOTE_A5, NOTE_G5, NOTE_F5, NOTE_E5, NOTE_C5, NOTE_E5, NOTE_D5,
  NOTE_C5, NOTE_B4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_C5,
  NOTE_A4, NOTE_A4};

//The durations of the notes in the second phrase:
  int phrase2Rhythms[] = {400, 200, 400, 200, 200, 600, 200, 400, 200,
  200, 400, 200, 200, 400, 400, 400, 400, 400};

//The letters representing the notes in the second phrase:
  char phrase2Letters[] = {
    'd', 'f', 'a', 'g', 'f', 'e', 'c', 'e', 'd', 'c', 'b', 'b', 'c',
    'd', 'e', 'c', 'a', 'a'
  };

  //The notes in the third phrase:
  
  int phrase3Notes[] = {NOTE_E5, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_A4, 
  NOTE_A4, NOTE_C5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_C5, 
  NOTE_D5, NOTE_E5, NOTE_C5, NOTE_A4, NOTE_A4};

  //The durations of the notes in the third phrase:
  int phrase3Rhythms[] = {400, 200, 200, 400, 200, 200, 400, 200, 200,
400, 200, 200, 600, 200, 400, 400, 400, 400, 400};


  //The letters representing the notes in the third phrase:
  char phrase3Letters[] = {
    'e', 'b', 'c', 'd', 'c', 'b', 'a', 'a', 'c', 'e', 'd', 'c', 'b', 'c', 'd', 'e', 'c', 'a', 'a'
  };

  //The notes in the fourth phrase.
  int phrase4Notes[] = {NOTE_D5, NOTE_F5,
  NOTE_A5, NOTE_G5, NOTE_F5, NOTE_E5, NOTE_C5, NOTE_E5, NOTE_D5,
  NOTE_C5, NOTE_B4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_C5,
  NOTE_A4, NOTE_A4};

  //The durations of the notes in the fourth phrase. 
  
  int phrase4Rhythms[] = {400, 200, 400, 200, 200, 600, 200, 400, 200,
  200, 400, 200, 200, 400, 400, 400, 400, 400};

  //The letters representing the notes in the fourth phrase. 

  char phrase4Letters[] = {
    'd', 'f', 'a', 'g', 'f', 'e', 'c', 'e', 'd', 'c', 'b', 'b', 'c', 'd', 'e', 'c', 'a', 'a'
  };

  //The notes in the fifth phrase.
  int phrase5Notes[] = { NOTE_E4, NOTE_C4, NOTE_D4, NOTE_B3, NOTE_C4, 
  NOTE_A3, NOTE_GS3, NOTE_B3};
  //The durations of the notes in the fifth phrase.
  int phrase5Rhythms[] = {800, 800, 800, 800, 800, 800, 800, 400};
  //The letters representing the notes in the fifth phrase: 
  char phrase5Letters[] = {
    'e', 'c', 'd', 'b', 'c', 'a', 'g', 'b'
  };
  //The notes of the sixth phrase.
  int phrase6Notes[] = { NOTE_E4, NOTE_C4, NOTE_D4, NOTE_B3,
  NOTE_C4, NOTE_E4, NOTE_A4, NOTE_A4, NOTE_GS4};
  //The durations of the notes in the sixth phrase.
  int phrase6Rhythms[] = {800, 800, 800, 800, 400, 400, 400, 400, 800};
  //The letters representing the notes in the sixth phrase.
  char phrase6Letters[] = {
    'e', 'c', 'd', 'b', 'c', 'e', 'a', 'a', 'g'
  };


//This function prints the letter representing a note. 
void printLetter(char letter) {
  //Prints C. 
  if (letter=='c') {
    lc.setRow(0,0,C[0]);
    lc.setRow(0,1,C[1]);
    lc.setRow(0,2,C[2]);
    lc.setRow(0,3,C[3]);
    lc.setRow(0,4,C[4]);
    lc.setRow(0,5,C[5]);
    lc.setRow(0,6,C[6]);
    lc.setRow(0,7,C[7]);
  //Prints D. 
  } else if (letter=='d') {
    lc.setRow(0,0,D[0]);
    lc.setRow(0,1,D[1]);
    lc.setRow(0,2,D[2]);
    lc.setRow(0,3,D[3]);
    lc.setRow(0,4,D[4]);
    lc.setRow(0,5,D[5]);
    lc.setRow(0,6,D[6]);
    lc.setRow(0,7,D[7]);
  //Prints E. 
  } else if (letter=='e') {
    lc.setRow(0,0,E[0]);
    lc.setRow(0,1,E[1]);
    lc.setRow(0,2,E[2]);
    lc.setRow(0,3,E[3]);
    lc.setRow(0,4,E[4]);
    lc.setRow(0,5,E[5]);
    lc.setRow(0,6,E[6]);
    lc.setRow(0,7,E[7]);
  //Prints F. 
  } else if (letter=='f') {
    lc.setRow(0,0,F[0]);
    lc.setRow(0,1,F[1]);
    lc.setRow(0,2,F[2]);
    lc.setRow(0,3,F[3]);
    lc.setRow(0,4,F[4]);
    lc.setRow(0,5,F[5]);
    lc.setRow(0,6,F[6]);
    lc.setRow(0,7,F[7]);
  //Prints G. 
  } else if (letter=='g') {
    lc.setRow(0,0,G[0]);
    lc.setRow(0,1,G[1]);
    lc.setRow(0,2,G[2]);
    lc.setRow(0,3,G[3]);
    lc.setRow(0,4,G[4]);
    lc.setRow(0,5,G[5]);
    lc.setRow(0,6,G[6]);
    lc.setRow(0,7,G[7]);
  //Prints A. 
  } else if (letter == 'a') {
    lc.setRow(0,0,A[0]);
    lc.setRow(0,1,A[1]);
    lc.setRow(0,2,A[2]);
    lc.setRow(0,3,A[3]);
    lc.setRow(0,4,A[4]);
    lc.setRow(0,5,A[5]);
    lc.setRow(0,6,A[6]);
    lc.setRow(0,7,A[7]);
  //Prints B. 
  } else if (letter=='b') {
    lc.setRow(0,0,C[0]);
    lc.setRow(0,1,C[1]);
    lc.setRow(0,2,C[2]);
    lc.setRow(0,3,C[3]);
    lc.setRow(0,4,C[4]);
    lc.setRow(0,5,C[5]);
    lc.setRow(0,6,C[6]);
    lc.setRow(0,7,C[7]);
  }
}

void setup() {
  // put your setup code here, to run once:
  //Ensures that the LED matrix is not shut off.
  lc.shutdown(0, false);
  //Sets the intensity of the LEDs. 
  lc.setIntensity(0, 8);
  //Clears the LED matrix.
  lc.clearDisplay(0);
  //Sets PWM pins 2 and 3 and pulls up the built-in resistors. 
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  
}

void loop() {
  // put your main code here, to run repeatedly:
  //Executes the first phrase. Iterates over the lists of notes, durations, and letters. 
   START :for (int thisNote = 0; thisNote < 19; thisNote++)  {
    //Plays a note.
    tone(8, phrase1Notes[thisNote], phrase1Rhythms[thisNote]);
    //Prints a letter. 
    printLetter(phrase1Letters[thisNote]);
    //Checks to see if the user has hit pause.
    int buttonValue1=digitalRead(2);
    if (buttonValue1==0) {
      thisNote=thisNote-1;
    }
    //Checks to see if the user has hit Rewind. 
    int startValue1=digitalRead(3);
    if (startValue1==0) {
      goto START;
    }
    
    delay(200);
  }
  //Executes the second phrase, iterating over the lists of notes, duration, and letters.
  for (int thisNote= 0; thisNote < 18; thisNote++) {
    //Plays a note.
    tone(8, phrase2Notes[thisNote], phrase2Rhythms[thisNote]);
    //Displays a letter. 
    printLetter(phrase2Letters[thisNote]);
    //Checks to see if the user has hit Pause.
    int buttonValue2=digitalRead(2);
    if (buttonValue2==0){
      thisNote=thisNote-1;
    }
    //Checks to see if the user has hit Rewind.
    int startValue2=digitalRead(3);
    if (startValue2 == 0) {
      goto START;
    }
    delay(200);
  }
  //Executes the third phrase, iterating over the lists of notes, duration, and letters. 
  for (int thisNote = 0; thisNote < 19; thisNote++) {
    //Plays a note. 
    tone(8, phrase3Notes[thisNote], phrase3Rhythms[thisNote]);
    //Displays the associated letter. 
    printLetter(phrase3Letters[thisNote]);
    //Checks to see if the user has hit Pause.
    int buttonValue3=digitalRead(2);
    if (buttonValue3 == 0) {
      thisNote = thisNote-1;
    }
    //Checks to see if the user has hit Rewind.
    int startValue3=digitalRead(3);
    if (startValue3==0) {
      goto START;
    }
    delay(200);
  }
  //Executes the fourth phrase, iterating over the list of notes, durations, and letters.
  for (int thisNote = 0; thisNote < 18; thisNote++) {
    //Plays a note.
    tone(8, phrase4Notes[thisNote], phrase4Rhythms[thisNote]);
    //Displays the associated letter. 
    printLetter(phrase4Letters[thisNote]);
    //Checks to see if the user has hit Pause.
    int buttonValue4 = digitalRead(2);
    if (buttonValue4==0) {
      thisNote=thisNote-1;
    }
    //Checks to see if the user has hit Rewind.
    int startValue4= digitalRead(3);
    if (startValue4==0) {
      goto START;
    }
    delay(200);
  }
  //Executes the fifth phrase, iterating over the list of notes, durations, and letters.
  for (int thisNote=0; thisNote<8; thisNote++) {
    //Plays a note.
    tone(8, phrase5Notes[thisNote], phrase5Rhythms[thisNote]);
    //Displays the associated letter.
    printLetter(phrase5Letters[thisNote]);
    //Checks to see if the user has hit Pause.
    int buttonValue5 = digitalRead(2);
    if (buttonValue5==0) {
      thisNote=thisNote-1;
    }
    //Checks to see if the user has hit Rewind. 
    int startValue5=digitalRead(3);
    if (startValue5==0) {
      goto START;
    }
    delay(200);
    
  }

  //Executes the sixth phrase, iterating over the lists of notes, durations, and letters.
  for (int thisNote=0; thisNote<9; thisNote++){
    //Plays a note.
    tone(8, phrase6Notes[thisNote], phrase6Rhythms[thisNote]);
    //Displays the associated letter.
    printLetter(phrase6Letters[thisNote]);
    //Checks to see if the user has hit Pause.
    int buttonValue6=digitalRead(2);
    if (buttonValue6==0) {
      thisNote=thisNote-1;
    }
    //Checks to see if the user has hit Rewind. 
    int startValue6=digitalRead(3);
    if (startValue6==0) {
      goto START;
    }
    delay(200);
  }
  delay(2000);
}

The schematic below portrays the wiring for all 3 parts outlined above:

Center

The following video captures the results for parts 2 and 3:


External References