so i have to follow the format and make the song \"mary had a little lamb\" to p
ID: 3754732 • Letter: S
Question
so i have to follow the format and make the song "mary had a little lamb" to play on my arduino
2. Binary Music Synthesize The name of this program will be lab5p2 We are going to use the switches as a "keyboard" so that we can create music using the Arduino. The keys are unusual, in that they are binary encoded. Thus, pressing two or more keys doesn't sound like two or more notes pressed at once Instead, pressing two or more keys results in a different note a. b. c. From loop (, call the function read_switches Based on the returned value, create a large switch statement, such that a different musical note is played for each binary encoded value of the 4 switches. If the returned value is 0 (no key pressed), turn off the music. That leaves 15 other combinations that can Page 1 EE112- Embedded Systems Lab 5 Fall 2018 be used to play a maximum of 15 different notes, which is slightly more than one octave. Below are the frequencies (notes) selected for this program. If the returned value is equal to one, play middle C. If the returned value is 2, play C sharp (C#). Cut and paste these constant macro definitions into your program #define NOTE-C4 262 // middle C frequency #de fine NOTE CS4 277 #de fine NOTE D4 294 #de fine NOTE DS4 311 #de fine NOTE E4 330 #de fine NOTE F4 349 #de fine NOTE FS 4 370 #de fine NOTE G4 392 #de fine NOTE GS 4 415 #de fine NOTE A4 440 #de fine NOTE AS 4 466 #de fine NOTE B4 494 #de fine NOTE C5 523 #de fine NOTE CS5 554 #de fine NOTE D5 587 d. Three songs are on the back page. Select one of them. Annotate it with binary notes, e.g., C is 1 (annotate with 0001), D is 3 (annotate with 001 If you do not know how to read music, please get with another student in the class that can read music to assist you with the annotations. Run the program. Play one of the songs for the TA. Each student upload source file to Canvas. TA Signature Date (0/1/2/3 points)Explanation / Answer
Below program could be used to play the song.
Class lab5p2{
Public void main(){
for {
int keyPressed = read_switches();
switch (keyPressed) {
Case 0000:
return 0;
Case 0001:
#define NOTE_C4 262;
Break;
Case 0010:
#define NOTE_CS4 277;
Break;
Case 0011:
#define NOTE_D4 294;
Break;
Case 0100:
#define NOTE_DS4 311;
Break;
Case 0101:
#define NOTE_E4 330;
Break;
Case 0110:
#define NOTE_F4 349;
Break;
Case 0111:
#define NOTE_FS4 370;
Break;
Case 1000:
#define NOTE_G4 392;
Break;
Case 1001:
#define NOTE_GS4 415;
Break;
Case 1010:
#define NOTE_A4 440;
Break;
Case 1011:
#define NOTE_AS4 466;
Break;
Case 1100:
#define NOTE_B4 494;
Break;
Case 1101:
#define NOTE_C5 523;
Break;
Case 1110:
#define NOTE_CS5 554;
Break;
Case 1111:
#define NOTE_D5 587;
Break;
}
}while (keyPressed!=null)
}
int read_switches()
{
int keyValue=0000;
keyValue = key1.value()+key2.value()+key3.value()+key4.value();
return keyValue;
}
}
Part d:
Your song lyrics is “mary had a little lamb”, which must be played using the Arduino.
Binary Notes for the song (in lower case):
m
a
r
y
h
a
d
a
L
01101101
01100001
01110010
01111001
01101000
01100001
01100100
01100001
01101100
i
t
t
l
e
l
a
m
B
01101001
01110100
01110100
01101100
01100101
01101100
01100001
01101101
01100010
m
a
r
y
h
a
d
a
L
01101101
01100001
01110010
01111001
01101000
01100001
01100100
01100001
01101100
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.