#define buzz 13
#define t 100 // the time of each noise
#define d 200 // the time between each noise
void setup()
{
// put your setup code here, to run once:
pinMode(buzz, OUTPUT);
Serial.begin(9600);
}
void loop()
{
// put your main code here, to run repeatedly:
String song[] = {"C3", "1", "CS2"}; // this is the song
int size = sizeof(song)/sizeof(song[0]); // gets the size of the song
for(int i = 0; i < size; i++) // repeats for each key
{
delay(100);
note(song[i]); // plays each key
}
delay(1000);
}
void note(String inp) // this it a way to quickly play each key without remembering each of their frequencies
{
//Serial.println(key);
char key;
if(inp == "1")
{
delay(100); // 1 will be a blank space
//Serial.print("- ");
}
else
{
Serial.println(key);
char octive = (inp[(inp.length()-1)]); // gets the octive
//Serial.println(key[0]);
int oNum = 0;
if (octive == '1')
{
oNum = 1;
}
else if (octive == '2')
{
oNum = 2;
}
else if (octive == '3')
{
oNum = 3;
Serial.print("a ");
}
else if (octive == '4')
{
oNum = 4;
}
else if (octive == '5')
{
oNum = 5;
}
else if (octive == '6')
{
oNum = 6;
}
else if (octive == '7')
{
oNum = 7;
}
else if (octive == '8')
{
oNum = 8;
}
else
{
oNum = 0;
}
Serial.println(oNum);
int x = pow (2, oNum-1); // changes it to a the value of how it affects each key
if (inp[1] != octive) // checks if the key is sharp
{
key = inp[0] + inp[1];
}
else // checks if the key isnt sharp
{
key = inp[0];
}
Serial.println(key);
Serial.println();
if(key == "C")
{
tone(buzz, 131*x, t);
//Serial.print("C ");
}
else if(key == "CS")
{
tone(buzz, 139*x, t);
//Serial.print("CS ");
}
else if(key == "D")
{
tone(buzz, 147*x, t);
}
else if(key == "DS")
{
tone(buzz, 156*x, t);
}
else if(key == "E")
{
tone(buzz, 165*x, t);
}
else if(key == "F")
{
tone(buzz, 175*x, t);
}
else if(key == "FS")
{
tone(buzz, 185*x, t);
}
else if(key == "G")
{
tone(buzz, 196*x, t);
}
else if(key == "GS")
{
tone(buzz, 208*x, t);
}
else if(key == "A")
{
tone(buzz, 220*x, t);
}
else if(key == "AS")
{
tone(buzz, 233*x, t);
}
else if(key == "B")
{
tone(buzz, 247*x, t);
}
}
}