0% found this document useful (0 votes)
153 views5 pages

Arduino Music Lavender Town PDF Free

Uploaded by

miojomaromba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
153 views5 pages

Arduino Music Lavender Town PDF Free

Uploaded by

miojomaromba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

void setup() {

// iterate over the notes of the melody:


for (int thisNote = 0; thisNote < 8; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}
}
void loop() {
// no need to repeat the melody.
}
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
//this noteLibrary depicts the frequencies of each note.
z=0
b2=123
c3=131
cs31=39
d3=147
ds3=156
e3=165
f3=175
fs3=185
g3=196
gs3=208
a3=220
as3=233
b3=247
c4=262
cs4=277
d4=294
ds4311
e4=330
f4=349
fs4=370
g4=392
gs4=415
a4=440
as4=466
b4=494
c5=523
cs5=554
d5=587
ds5=622
e5=659
f5=698
fs5=740
g5=784
gs5=831
a5=880
as5=932
b5=988
c6=1047
cs6=1109
d6=1175
ds6=1245
e6=1319
f6=1397
fs6=1480
g6=1568
gs6=1661
a6=1760
as6=1865
b6=1976
c7=2093
cs7=2217
d7=2349
ds7=2489
e7=2637
f7=2794
fs7=2960
g7=3136
gs7=3322
a7=3520
as7=3729
b7=3951
c8=4186
cs8=4435
d8=4699
ds8=4978
//tone[inputPin, melody[], noteDuration[]]
//This is code which uses the lock of an arduino to play notes in a sequ
ence at particular durations
//as well as particular pitches.
//As the arduino can only play one tone at a time, this code is simply a
mockup for a more
//powerful arduino such as th arduino Mega.
//inputPin# denotes which pin# is being used as a digital output to the
circuit which leads to the speaker.
//melody plays a specific frequency
//melody has a list of notes which have been specifiied earlier
//to correspond to particular frequencies i.e. keys.
//noteDuration corresponds to a formula which is altered through tempo t
o specific particlaur length to
//each note played by tone.
//MaximumOneNote=8
//MaximumOneNote denotes the fractional length of the smallest note such
that
//MaximumOneNote's value times the smallest note is a whole note
int tempo=120
//this tempo is particular to lavender town, it is different for every s
ong.
//noteDuration[]=(1/tempo)*15*oneNote[]
//Through this equation, noteDuration plays the speed at which is desire
d without
//having to lookup how many fractions of a second each note is.
int melody[161:0]={c5, gs4, z, b4, z, f4, z,
c5, gs4, z, b4, z, f4, z,
c5, gs4, z, b4, z, f4, z,
c5, gs4, z, b4, z, f4, z,
c5, gs4, z, b4, z, f4, z,
c5, gs4, z, b4, z, f4, z,
c5, gs4, z, b4, z, f4, z,
c5, gs4, z, b4, z, f4, z,
c5, gs4, z, b4, z, f4, z,
c5, gs4, z, b4, z, f4, z,
c5, gs4, z, b4, z, f4, z,
c5, z, gs4, b4, z, f4, z,
c5, gs4, z, b4, z, f4, z,
c5, gs4, z, b4, z, f4, z,
c5, gs4, z, b4, z, f4, z,
c5, gs4, z, b4, z, f4, z,
b4, gs4, b4, z, b4,
b4, gs4, b4, z, b4,
b4, gs4, b4, z, b4,
c5, gs4, z, b4, z, f4, z,
z, gs4, z, b4, z, f4, z,
z, gs4, z, b4, z, f4, z,
c5, gs4, z, b4, z, f4, z,
c5, gs4, z, b4, z, f4, z}
//array of notes to be played
int oneNote[161:0]={2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 2, 1, 1, 1,
2, 2, 1, 1, 1,
2, 2, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 1, 1, 1}
int noteDuration[161:0]=(1/tempo)*15*oneNote[161:0]
//corresponding array of durations each note is played, each denotes a m
ultiple of the smallest fraction
tone[inputPin1, melody[161:0], noteDuration[161:0]]
//this plays the tune through input 1; this tune can be played on the arduino gi
ven.
//the other tunes which add to a song found below
//not accurate in programming t the moment, numbers must be changed
int melody[57:0]={z, z, z, z,
gs4, gs4, e5, e5, gs4, f4, e5, b4, e5, c5, b4, e
5,
gs4, gs4, e5, e5, gs4, f4, e5, b4, e5, c5, b4, e
5,
gs4, gs4, e5, e5, gs4, f4, e5, b4, e5, c5, b4, e
5,
gs4, gs4, e5, e5, gs4, f4, e5, b4, e5, g4, f4, b
4,
c5, z, c5, z, z, z}
int oneNote[57:0]={8, 8, 8, 8
4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2,
4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2,
4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2,
4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2,
2, 6, 2, 6, 8, 8,}
int noteDuration[57:0]=(1/tempo)*15*oneNote[57:0]
tone[inputPin2, melody[57:0], noteDuration[57:0]]
//this is the limit of the arduino
melody[33:0]={z, z, z, z,
e5, d5, c5, cs5, cs5,
e5, z, d5, c5, z,
e5, z, d5, c5, cs5, cs5,
c5, z, c5, z, c5, z, z,
e5, d5, c5, e5, c5, b4, e5}
int oneNote[33:0]={8, 8, 8, 8,
8, 8, 8, 4, 4,
2, 6, 8, 8, 8,
2, 6, 8, 8, 4, 4,
2, 6, 2, 6, 2, 6, 8,
8, 8, 8, 2, 2, 2, 2}
itn noteDuration[33:0]=(1/tempo)*15*oneNote[33:0]
tone[inputPin3, melody[33:0], noteDuration[33:0]]
//If tune works, should play Lavender Town theme from Pokemon Red/Blue/Y
ellow

You might also like