Professional Documents
Culture Documents
Student: Teacher:
Claudio Vadalà Prof. Francesco Longo
In music theory we see that time is notated from left to right. I will quickly
explain the basics of rhythm. Understanding this notation is essential to
learning and studying theoretical music. The recurring pulse called the beat.
It’s the steady rhythm to which you want to tap your foot or dance.
Beats are grouped into bars, or measures as they are also called. In this
study we consider their pulse would be counted on 4/4 which is equivalent
to count such as: 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, … and so on since counting four
beats to a bar is the most common, all rhythmic terminology is based on a
bar containing 4 beats.
An eighth note lasts for half of a beat (an eighth of a whole
note). The eighth note looks like the quarter note with
a flag attached to the stem.
The Breadboard consists in, three LEDs, three buttons and a Buzzer.
The LED are respectively Red, Yellow and Green. They are associated to:
RED: 1/4 note;
YELLOW: 1/8 note;
GREEN: 1/16 note.
The button N° 1 is associated to a Demo Track which will show the alumni
the way how we represent the music in theory in 4/4 with three different
examples respectively in 1/4 notes, 1/8 notes and 1/16 notes.
It starts with four preparatory beats by 1/4, then the first five notes of C
major scale ascending and descending ( C, D, E, F ,G, F, E, D, C), ending
with the remaining rest beats (3) which will end the 4/4 bar. After It starts
again with the same first notes of C major scale ascending and descending
( C, D, E, F ,G, F, E, D, C) this time in 1/8 value notes. ending with the
remaining rest beats (3) which will end the bar. The last part of the Demo
is represented by the first five notes of C major scale ascending and
descending ( C, D, E, F ,G, F, E, D, C) in 1/16 notes value, ending with the
rests beat that will complete the final bar.
As we can see these examples shows the varieties of the rhythm in different
circumstances. This is a starting point to show under an “Arduino point of
view” how music can be learnt with electronics through coding.
The UNO boards can be used as the brains behind almost any electronics
project. UNO can interact with buttons, LEDs, motors, speakers, GPS
units, cameras, the internet etc… By connecting the UNO board with a
personal computer via a USB cable and uploading programs to the board,
users can create digital devices and interactive objects that can sense and
control objects in the physical and digital world.
1.3. Resistors
Resistors have been used to limit the amount of current going to certain
components in the circuit, such as LEDs and integrated circuits. For the
LEDs I used 220 Ohm while for the Buzzer I used 100 Ohm.
I started including the library pitches.h which give us all the frequency reference in terms
of Hertz to be sent to the buzzer for playing the correspondent notes. Then I wrote the
melody of the three song melodies that will characterize the preparatory music concept.
Note that every note contains information about the octave pitch (e.x. B4 means B or Si
on the fourth octave) and here following you will find the initialization of the buttons and
leds respectively attached to the Arduino board.
int Rest=0;
int
popnoteDurations[]={2,2,2,4,4,4,4,4,4,2,4,4,4,4,4,4,2,4,4,4,4,4,4,4,4,4,4,4
,4,4,4,2,2,};
int tetnoteDurations[]={4,4,4,4,4,8,8,4,8,8,4,8,8,4,8,8,4,8,8,4,4,4,4,2,};
I end up the first part of the code with the score notation of every single note inside the
melody arrangements and following the declaration of Input/output components.
The buttons will be taken as Input by pressing it while the LEDs will be Output to get
the message out coming from the music.
void loop(){
Here you find digitalRead function which reads the value from a specified digital pin,
it returns High or Low. In the brackets you have the pin number.
Here following you will find the condition that determines which LED will light up,
based on a division of a unity expressed in ms (e.x. one second = 1000ms). If the value
divided for the note duration is corresponding to the note range associated to the note, then
the LED will reveal the value of the note associated.
//DEMO MELODY
//if the button is pressed
if (demobuttonState == 1){
//to calculate the note duration, take one second. Divided by the
note type
int demonoteDuration = 1000 / demonoteDurations [thisNote];
if (demonoteDuration ==500){
digitalWrite(lstep1, HIGH);
tone(8, demo[thisNote],demonoteDuration);
digitalWrite(lstep1, LOW);
}
if (demonoteDuration >200 && demonoteDuration <300){
digitalWrite(lstep2, HIGH);
tone(8, demo[thisNote],demonoteDuration);
digitalWrite(lstep2, LOW);
}
if (demonoteDuration <200){
digitalWrite(led, HIGH);
tone(8, demo[thisNote],demonoteDuration);
digitalWrite(led, LOW);
You can also find another Arduino function called digitalWrite which Is used to
change the LEDs state. If it’s needed to light up than the value will be High, vice versa I
will set up to Low.
//POPCORN MELODY
//if the button is pressed
if (popbuttonState == 1){
//to calculate the note duration, take 900ms (0,9 seconds). Divided
by the note type
int popnoteDuration = 900 / popnoteDurations [thisNote];
if (popnoteDuration ==225){
digitalWrite(lstep2, HIGH);
tone(8, popcorn[thisNote],popnoteDuration);
}
if (popnoteDuration >225){
digitalWrite(lstep1, HIGH);
tone(8, popcorn[thisNote],popnoteDuration);
digitalWrite(lstep1, LOW);
Here another example of melody, this time I did time-lapse of the variable, bringing up
to 1200 to get possible the 4/8 time signature without stretching too much the speed. I
raised up to 1.2 seconds the main tempo.
//TETRIS MELODY
if (tetbuttonState == 1){
digitalWrite(led, HIGH);
tone(8, tetris[thisNote],tetnoteDuration);
digitalWrite(led, LOW);
}
if (tetnoteDuration >225){
digitalWrite(lstep2, HIGH);
tone(8, tetris[thisNote],tetnoteDuration);
digitalWrite(lstep2, LOW);
}
//to distinguish the notes, set a minimum time between them
//the note's duration +30% seems to work well
int pauseBetweenNotes = tetnoteDuration * 1.30;
delay(pauseBetweenNotes);
The Key function in this project is given by Tone which generates a square wave of the
specified frequency on a pin. So the pin is connected to the Buzzer to play the tone. On the
other hand we have noTone function which will stop the buzzer making sound.
I selected from the library only three octaves needed to play the melodies:
From C4 (first note of the fourth octave scale) to B6 (last note of the sixth
octave scale).
/*************************************************
* Public Constants
*************************************************/