lab 5 final

This commit is contained in:
2022-01-31 01:11:41 -06:00
parent f409bfa319
commit 8817dae579
3 changed files with 204 additions and 296 deletions

View File

@@ -1,8 +1,18 @@
/*
* main.c
*
* Created on: January 12, 2022
* Author: Trevor Barnes
/**
* @file main.c
* @author Trevor Barnes
* @brief Main Driver for the Week 5 "Play a Tune" Lab. This program uses a similar menu style to the previous
* lab. The user is given a new option to play 3 different hard coded songs in arrays of "Note" structs,
* provided by the piezoSpeaker.h file.
* Experience: As a former music student I enjoyed working on this lab very much, to the point that I became
* sort of a perfectionist with its implementation. Getting the timer configured and working with the piezo speaker
* was certainly the most difficult and time consuming part. Once I had that figured out though figuring
* out the best note implementation and songs to play was very enjoyable.
* @version 0.1
* @date 2022-01-12
*
* @copyright Copyright (c) 2022
*
*/
#include <stdio.h>
@@ -17,53 +27,45 @@
#define F_CPU 16000000UL
// Super Mario "Flagpole Fanfare"
Note songSMFF[66]= { {G3, S/3}, {Ab3,S/3}, {A3, S/3}, {Bb3,S/3}, {B3,S/3},
{C4, S/3}, {Db4,S/3}, {D4, S/3}, {Eb4,S/3}, {E4,S/3},
{F4, S/3}, {Gb4,S/3}, {G4, S/3}, {Ab4,S/3}, {A4,S/3},
{Bb4,S/3}, {B4, S/3}, {C5, S/3}, {Db5,S/3}, {D5,S/3},
{Eb5,S/3}, {E5, S/3}, {F5, S/3}, {Gb5,S/3}, {G5,S/3},
{Ab5,S/3}, {A5, S/3}, {Bb5,S/3}, {B5, S/3}, {C6,S/3},
{Db6,S/3}, {D6, S/3}, {Eb6,S/3}, {E6, S/3}, {F6,S/3},
{Eb6,S/3}, {G6, S/3}, {r, 7*S}, {G3, Q}, {C4, Q},
{E4, Q}, {G4, Q}, {C5, Q}, {E5, Q}, {G5, H},
{E5, H}, {Ab3, Q}, {C4, Q}, {Eb4, Q}, {Ab4, Q},
{C5, Q}, {Eb5, Q}, {Ab6, H}, {Eb5, H}, {Bb3, Q},
{D4, Q}, {F4, Q}, {Bb4, Q}, {D5, Q}, {F5, Q},
{Bb5, W}, {B5, Q}, {B5, Q}, {B5, Q}, {C6, W}, {T}
};
// Imperial March
Note songIMold[138] = { {A3, Q}, {A3, Q}, {A3, Q}, {r, Q},
{F3,E+S}, {r, E+S}, {C4, S}, {r, S}, {A3, Q}, {r, Q},
{F3,E+S}, {r, E+S}, {C4, S}, {r, S}, {A3, H}, {r, H},
{E4, Q}, {r, Q}, {E4, Q}, {r, Q}, {E4, Q}, {r, Q},
{F4,E+S}, {r, E+S}, {C4, S}, {r, S}, {Ab3, Q}, {r, Q},
{F3,E+S}, {r, E+S}, {C4, S}, {r, S}, {A3, H}, {r, H},
{A4, Q}, {r, Q}, {A3, E+S}, {r, E+S}, {A3, S}, {r, S},
{A4, Q}, {r, Q}, {Ab4,E+S}, {r, E+S}, {G4, S}, {r, S},
{Gb4, Q}, {r, S}, {E4, S}, {r, S}, {F4, E}, {r, E},
{r, E}, {Bb3, E}, {r, E}, {Eb4, Q}, {r, Q}, {D4,E+S},
{r, E+S}, {Db4, S}, {r, H}, {C4, S}, {r, S}, {B3, S},
{r, S}, {C4, E}, {r, E}, {r, E}, {F3, E}, {r, E},
{Ab3, Q}, {r, Q}, {F3, E+S}, {r, E+S}, {A3, S}, {r, S},
{C4, Q}, {r, Q}, {A3, E+S}, {r, E+S}, {C4, S}, {r, S},
{E4, H}, {r, H}, {A4, Q}, {r, Q}, {A3, E+S}, {r, E+S},
{A3, S}, {r, S}, {A4, Q}, {r, S}, {Ab4,E+S}, {r, E+S},
{G4, S}, {r, S}, {Gb4, S}, {r, S}, {E4, S}, {r, S},
{F4, E}, {r, E}, {r, E}, {Bb3, E}, {r, E}, {Eb4, Q},
{r, Q}, {D4,E+S}, {r, E+S}, {Db4, S}, {r, S}, {C4, S},
{r, S}, {B3, S}, {r, S}, {C4, E}, {r, E}, {r, E},
{F3, E}, {r, E}, {Ab3, Q}, {r, Q}, {F3, E+S}, {r, E+S},
{C4, S}, {r, S}, {A3, Q}, {r, Q}, {F3, E+S}, {r, E+S},
{C4, S}, {r, S}, {A3, H}, {r, H}, {T, Q}
};
// Imperial March - Star Wars
Note songIM[138] = {
{A3, Q}, {A3, Q}, {A3, Q}, {F3, S*3}, {C4, S}, {A3, Q}, {F3, S*3}, {C4, S}, {A3, H},
{E4, Q}, {E4, Q}, {E4, Q}, {F4, S*3}, {C4, S}, {Ab3, Q}, {F3, S*3}, {C4, S}, {A3, H}, {T}
{A4, Q}, {A4, Q}, {A4, Q}, {F4, S*3}, {C5, S}, {A4, Q}, {F4, S*3}, {C5, S}, {A4, H},
{E5, Q}, {E5, Q}, {E5, Q}, {F5, S*3}, {C5, S}, {Ab4, Q}, {F4, S*3}, {C5, S}, {A4, H},
{A5, Q}, {A4, S*3}, {A4, S}, {A5, Q}, {Ab5, S*3}, {G5, S},
{Gb5, S}, {F5, S}, {Gb5, E}, {r, E}, {Bb4, E}, {Eb5, Q}, {D5, S*3}, {Db5, S},
{C5, S}, {B4, S}, {C5, E}, {r, E}, {F4, E}, {Ab4, Q}, {F4, S*3}, {A4, S},
{C5, Q}, {A4, S*3}, {C5, S}, {E5, H},
{A5, Q}, {A4, S*3}, {A4, S}, {A5, Q}, {Ab5, S*3}, {G5, S},
{Gb5, S}, {F5, S}, {Gb5, E}, {r, E}, {Bb4, E}, {Eb5, Q}, {D5, S*3}, {Db5, S},
{C5, S}, {B4, S}, {C5, E}, {r, E}, {F4, E}, {Ab4, Q}, {F4, S*3}, {C5, S},
{A4, Q}, {F4, S*3}, {C5, S}, {A4, H},
{END}
};
// Metropolis Theme - Ratchet & Clank
Note songMT[33] = {
{B5, E}, {G5, E}, {E5, E}, {G5, E}, {B5, E}, {G5, E}, {E5, E}, {B5, E},
{Bb5, E}, {F5, E}, {D5, E}, {F5, E}, {Bb5, E}, {F5, E}, {D5, E}, {Bb5, E},
{B5, E}, {G5, E}, {E5, E}, {G5, E}, {B5, E}, {G5, E}, {E5, E}, {B5, E},
{Bb5, E}, {F5, E}, {D5, E}, {F5, E}, {Bb5, E}, {F5, E}, {D5, E}, {Bb5, E},
{END}
};
// Flower Garden - Yoshi's Island
Note songFG[77] = {
{E4, E}, {r, E}, {G4, E}, {r, S}, {G4, S}, {E4, E}, {C4, E}, {r, Q},
{A3, E}, {r, E}, {C4, E}, {r, S}, {A3, S}, {D4, E}, {E4, E}, {r, Q},
{E4, E}, {r, E}, {G4, E}, {r, S}, {G4, S}, {E4, E}, {C4, E}, {r, Q},
{A3, E}, {r, E}, {C4, E}, {r, S}, {A3, S}, {E4, E}, {D4, E}, {r, Q},
{G5, S}, {Gb5, S}, {G5, E+(Q*3)},
{r , E}, {F5, E}, {E5, E}, {F5, E}, {E5, E}, {C5, E}, {A4, E}, {G4, E+(Q*5)}, {r, E},
{C5, E}, {B4, E}, {D5, E}, {A5, E}, {G5, E+H+Q}, {r, E},
{A5, E}, {B5, E}, {A5, E}, {G5, E}, {F5, E}, {E5, E}, {D5, E}, {E5, Q}, {C5, E}, {G4, E+(Q*3)}, {r, E},
{C5, E}, {B4, E}, {C5, E}, {D5, E}, {E5, E+Q}, {G5, Q}, {C5, Q}, {E5, Q},
{F5, E}, {E5, E}, {F5, E}, {D5, E*2}, {C5, E}, {B4, E}, {C5, E+W},
{END}
};
void printHelp() {
printf("*Commands*\n\r");
printf("'rmw {hex address}' - Reads mem at a given address\n\r");
@@ -75,8 +77,9 @@ void printHelp() {
}
void songInfo() {
printf("Type 1 or 2 to play a song!\n\r");
printf("Song 1: Imperial March\n\r");
printf("Song 2: Super Mario Bros Flagpole Fanfare\n\r");
printf("Song 1: Imperial March from Star Wars\n\r");
printf("Song 2: Metropolis Theme from Ratchet & Clank\n\r");
printf("Song 3: Flower Garden from Yoshi's Island");
}
int main(void) {
@@ -115,8 +118,12 @@ int main(void) {
play_song(songIM);
break;
case 2:
printf("Playing Super Mario Bros Flagpole Fanfare\n\r");
play_song(songSMFF);
printf("Playing Metropolis Theme\n\r");
play_song(songMT);
break;
case 3:
printf("Playing Flower Garden\n\r");
play_song(songFG);
break;
default:
break;