Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
arduino code from my engineering class. for hardware, refer to this image on how to setup hardware or tinkercad circuit https://i.ibb.co/wdphB27/image.png
school stuff i can actually get into
wow
int tones[] = {
0, // cut note
392, // G-4
497, // B-4
589, // D-5
662, // E-5
786, // G-5
883, // A-5
935, // A#5
988, // B-5
};
enum note {
Cut,
G_4,
B_4,
D_5,
E_5,
G_5,
A_5,
AS5,
B_5
};
const int whole = 350;
const int half = 170;
const int quar = 68;
// structure repeats as hZ,time,hZ,time
int amazing[] = {
D_5, whole,
G_5, whole, // part 1
Cut, whole,
B_5, quar,
Cut, quar,
A_5, quar,
A_5, quar,
B_5, whole,
Cut, whole,
A_5, whole,
G_5, whole,
Cut, whole,
E_5, whole,
D_5, whole,
Cut, whole,
D_5, whole,
G_5, whole,
Cut, whole,
B_5, quar,
B_5, quar,
A_5, quar,
G_5, quar,
B_5, whole,
Cut, whole,
A_5, whole,
D_5, whole,
D_5, whole,
D_5, whole,
D_5, whole,
D_5, whole,
B_5, whole,
D_5, whole, // part 2
Cut, whole,
B_5, quar,
B_5, quar,
A_5, quar,
G_5, quar,
B_5, whole,
Cut, whole,
A_5, whole,
G_5, whole,
Cut, whole,
E_5, whole,
D_5, whole,
Cut, whole,
D_5, whole,
G_5, whole,
Cut, whole,
B_5, quar,
B_5, quar,
A_5, quar,
G_5, quar,
B_5, whole,
Cut, whole,
A_5, whole,
G_5, whole,
Cut, whole,
Cut, whole,
Cut, whole,
Cut, whole,
D_5, whole,
G_5, whole, // part 3
Cut, whole,
B_5, quar,
B_5, quar,
A_5, quar,
G_5, quar,
B_5, whole,
B_5, whole,
A_5, whole,
G_5, whole,
Cut, whole,
E_5, whole,
D_5, whole,
Cut, whole,
D_5, whole,
G_5, whole,
Cut, whole,
B_5, quar,
B_5, quar,
A_5, quar,
G_5, quar,
B_5, whole,
Cut, whole,
A_5, half,
D_5, half,
D_5, half,
D_5, half,
D_5, half,
D_5, half,
D_5, half,
D_5, half,
D_5, half,
D_5, half,
D_5, half,
D_5, half,
B_5, whole,
D_5, whole, // part 4
Cut, whole,
B_5, whole,
B_4, half,
B_4, half,
B_4, half,
B_4, half,
A_5, whole,
G_5, whole,
Cut, whole,
E_5, whole,
D_5, whole,
Cut, whole,
D_5, whole,
G_5, whole,
Cut, whole,
AS5, quar,
AS5, quar,
A_5, quar,
G_5, quar,
AS5, whole,
Cut, whole,
A_5, whole,
G_5, half,
B_4, half,
D_5, half,
B_4, half,
G_4, half,
G_4, half,
G_4, half,
D_5, half,
D_5, half,
G_4, half,
G_5, 1400,
Cut, 30,
Cut, 30,
Cut, 30,
Cut, 30
};
int songlength = 132*2;
void setup()
{
for(int i = 0; i < songlength; i += 2) {
if(amazing[i])
tone(12,tones[amazing[i]]);
delay(amazing[i+1]);
noTone(12);
delay(16);
}
}
void loop()
{
}
int tones[] = {
0, // cut note
132, 140, 148, 157, 166, 176, 186, 198, 209, 222, 235, 249, // oct 3
263, 279, 295, 313, 331, 351, 371, 393, 417, 442, 468, 495, // oct 4
525, 556, 589, 624, 661, 700, 741, 785, 832, 882, 934, 989, // oct 5
0xFFFF // end song
};
enum note {
Cut,
C_3, CS3, D_3, DS3, E_3, F_3, FS3, G_3, GS3, A_3, AS3, B_3,
C_4, CS4, D_4, DS4, E_4, F_4, FS4, G_4, GS4, A_4, AS4, B_4,
C_5, CS5, D_5, DS5, E_5, F_5, FS5, G_5, GS5, A_5, AS5, B_5,
End
};
const int whole = 350;
const int half = 170;
const int quar = 68;
int rhythm[] = {
D_5, quar, // part 1
D_5, quar,
FS4, quar,
D_4, quar,
G_4, whole,
Cut, whole,
D_4, quar,
D_4, quar,
C_4, quar,
B_3, quar,
D_4, whole,
Cut, whole,
A_3, quar,
C_4, quar,
E_4, quar,
G_4, quar,
G_4, whole,
Cut, whole,
E_4, quar,
FS4, quar,
E_4, quar,
CS4, quar,
D_4, whole,
Cut, whole,
FS3, quar,
G_3, quar,
A_3, quar,
D_3, quar,
G_3, quar,
FS3, quar,
E_3, quar,
D_3, quar,
E_3, quar,
FS3, quar,
G_3, quar,
Cut, quar,
Cut, quar,
A_3, quar,
B_3, quar,
Cut, quar,
Cut, quar,
B_3, quar,
A_3, quar,
Cut, quar,
Cut, half,
B_3, quar,
A_3, quar,
G_3, quar,
A_3, quar,
A_3, half,
G_3, quar,
A_3, quar,
D_4, quar,
D_4, quar,
D_4, quar,
D_4, quar,
FS4, quar,
D_4, quar,
FS4, quar,
C_4, quar,
CS4, quar,
D_4, quar,
E_4, quar,
FS4, quar,
D_4, quar,
Cut, quar,
Cut, quar,
Cut, quar,
C_4, half,
Cut, quar,
D_4, quar,
B_3, quar,
B_3, quar,
D_4, quar,
D_4, quar,
D_3, quar, // part 2
D_3, quar,
G_3, quar,
B_3, quar,
G_3, quar,
Cut, quar,
Cut, half,
D_4, quar,
B_3, quar,
C_4, quar,
B_3, quar,
B_3, half,
Cut, half,
G_3, quar,
G_3, quar,
B_3, quar,
B_3, quar,
AS3, quar,
Cut, quar,
Cut, half,
C_3, quar,
D_3, quar,
E_3, quar,
FS3, quar,
C_3, quar,
Cut, quar,
Cut, half,
C_4, quar,
AS3, quar,
A_3, quar,
G_3, quar,
D_4, quar,
D_4, quar,
Cut, quar,
Cut, half,
G_3, quar,
B_3, quar,
A_3, quar,
G_3, quar,
G_3, half,
Cut, quar,
D_4, quar,
G_3, quar,
A_3, quar,
C_4, quar,
Cut, quar,
C_4, quar,
Cut, quar,
CS4, quar,
C_4, quar,
B_3, quar,
A_3, quar,
A_3, quar,
B_3, quar,
B_3, quar,
Cut, quar,
B_3, quar,
Cut, quar,
B_3, quar,
Cut, quar,
B_3, quar,
Cut, quar,
A_3, half,
Cut, half,
G_3, quar,
AS3, quar,
B_3, quar,
B_3, quar,
D_4, quar,
CS4, quar,
D_4, quar,
F_4, quar,
D_4, quar,
F_4, quar,
D_4, quar,
FS4, quar,
G_3, quar,
Cut, quar,
G_3, quar,
Cut, quar,
FS4, quar,
G_3, quar,
D_4, quar,
G_3, quar+half,
FS4, quar,
E_4, quar,
D_4, quar+2, // part 3
D_4, quar+3, // time buffers for being too fast
Cut, quar+3,
D_4, quar+3,
D_4, quar,
Cut, quar+3,
Cut, quar+3,
Cut, quar+3,
D_4, quar,
D_4, quar+3,
E_4, quar+3,
FS4, quar+3,
F_4, quar+1,
D_4, quar,
F_4, quar,
D_4, quar+7,
F_4, quar+7,
Cut, quar+5,
D_4, quar+5,
Cut, quar+5,
A_3, quar+5,
B_3, quar+5,
A_3, quar+5,
D_4, quar+5,
G_3, quar+5,
G_3, quar+5,
G_3, half+5,
FS3, half+6,
D_3, quar+6,
D_3, quar,
FS3, quar,
G_3, quar,
E_4, quar,
AS3, quar,
D_4, whole+half+quar+20,
Cut, quar,
D_3, quar,
FS3, quar,
A_3, quar,
D_4, quar,
G_3, quar,
G_3, quar,
B_3, quar,
AS3, quar,
B_3, half,
B_3, quar,
DS4, quar,
E_4, quar,
DS4, quar,
E_4, quar,
FS4, quar,
B_3, quar+8, // why is this happening
Cut, quar+8,
B_3, quar+8,
Cut, quar+8,
B_3, quar+8,
Cut, quar+8,
A_3, quar+8,
B_3, quar+8,
A_3, quar+8,
AS3, quar+8,
B_3, quar+8,
C_4, quar+8,
G_3, quar+8,
A_3, quar+8,
B_3, quar+8,
C_4, quar+8,
D_4, quar+8,
G_3, quar+8,
D_4, quar+8,
B_3, quar+8,
C_4, quar+8,
D_4, quar+8,
C_4, quar+8,
B_4, quar+8,
D_4, quar,
FS4, quar,
FS4, quar,
D_4, quar,
D_4, quar,
D_4, quar,
C_4, quar,
C_4, quar,
B_3, whole,
D_4, quar-12, // part 4
D_4, quar-12,
Cut, quar-12,
D_4, quar-12,
D_4, quar+half,
Cut, half,
B_3, quar,
B_3, quar,
DS4, quar,
B_3, quar,
D_4, quar+half,
Cut, quar+8,
D_4, quar+8,
D_4, quar+8,
FS4, quar+8,
D_4, quar+8,
A_4, quar+8,
B_3, quar,
C_3, quar+8,
D_3, quar+8,
B_3, quar,
B_3, quar+8,
A_3, quar+8,
B_3, quar,
G_3, quar,
Cut, quar+half,
E_4, quar,
Cut, quar+half,
B_3, quar+8,
D_4, quar+8,
D_4, half,
B_3, quar,
D_4, quar,
B_3, quar+8,
G_3, quar+8,
G_3, quar+8,
F_3, quar+8,
E_3, quar,
FS3, quar+8,
G_3, half,
Cut, half,
Cut, whole+20,
D_4, quar+8,
D_4, quar+8,
CS4, quar+8,
B_3, quar,
AS3, quar,
DS4, quar+8,
DS4, quar+8,
DS4, quar+8,
AS4, quar+8,
DS4, quar+8,
DS4, quar+8,
Cut, quar+8,
A_3, quar,
A_3, quar,
CS4, quar,
C_4, quar,
G_3, quar,
B_3, quar,
G_3, quar,
D_4, quar,
F_4, quar,
D_4, quar,
G_3, quar,
D_4, quar,
G_3, quar,
D_4, quar,
B_3, quar,
B_3, quar,
G_3, quar,
Cut, quar,
B_3, quar,
D_3, quar,
F_3, quar,
FS4, quar,
B_3, quar,
D_4, quar,
Cut, quar,
Cut, quar,
Cut, quar,
Cut, quar,
End, 30
};
void setup()
{
for(int i = 0; rhythm[i] != End; i += 2) {
if(rhythm[i])
tone(8,tones[rhythm[i]]);
delay(rhythm[i+1]);
noTone(8);
delay(19);
}
}
void loop()
{
}
// signifying notes for ease
int FS5 = 740;
int G_5 = 780;
int E_5 = 653;
int D_5 = 588;
int DS5 = 604;
int noN = 0;
// list of notes to play
int mysong[64] = {
FS5, G_5, G_5, G_5, noN, G_5, G_5, G_5, // measure 1
G_5, G_5, G_5, G_5, noN, G_5, G_5, G_5, // measure 2
E_5, noN, D_5, E_5, noN, D_5, E_5, D_5, // measure 3
E_5, noN, noN, noN, D_5, noN, noN, noN, // measure 4
DS5, E_5, E_5, E_5, noN, E_5, E_5, E_5, // measure 5
E_5, E_5, E_5, E_5, E_5, noN, E_5, E_5, // measure 6
E_5, noN, D_5, E_5, noN, D_5, E_5, D_5, // measure 7
G_5, noN, noN, noN, noN, noN, noN, noN // measure 8
};
void setup()
{
while (1)
{
//system runs through list of notes
//and plays them one by one
for(int i = 0; i < 64; i++){
// don't play note if current note has hZ of 0
if(mysong[i])
tone(12,mysong[i]);
delay(120);
noTone(12);
delay(10);
}
}
}
void loop()
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment