Sunteți pe pagina 1din 7

CMPEH 472 Lab

Making Sounds

1. For this lab you will need:

Arduino Uno USB cable +5v DC power supply ushbuttons !5"

Breadboard and wires o#scope$ %ulti%eter &#oh% loudspea'er 1('#oh% resistor !5"$ 15(#oh% resistor$ and 1('#potentio%eter

). Use*ul lin's:

a. +one!" re*erence b. entatonic scale

http:,,arduino.cc,en,-e*erence,+one http:,,en.wi'ipedia.or.,wi'i, entatonic/scale

c. 0hile loop re*erence http:,,arduino.cc,en,-e*erence,0hile d. De*ine re*erence e. 1nclude re*erence *. Array re*erence http:,,arduino.cc,en,-e*erence,De*ine http:,,arduino.cc,en,-e*erence,1nclude http:,,arduino.cc,en,-e*erence,Array

2. -e#read pa.es 35#1(5 in your te4tboo'.

5. 67+8: A*ter you9ve created your pro.ra% s'etch$ you will need to download the de*inition *ile :pitches.h; and place it in your s'etch directory. !See pa.e 35 in your te4tboo' *or help".

5. Be sure to *a%iliari<e yoursel* with the details o* the *ollowin. code shown below !listin. 5#1" and the sche%atic$ !Fi.ure 5#5 *ro% your te4tboo'". Build this system to make sound sequences.

/* Exploring Arduino - Code Listing 5-1: Arduino Music Player By Jere y Blu ! Exploring Arduino! "iley and #ons! $%1& */ //Plays a song on a spea'er (include )pitc*es+*) //,eader -ile .it* pitc* de-initions const int #PEA/E0123 //4ote Array int notes56 1 7 489E:A;! 489E:E&! 489E:A;! 489E:E&! 489E:E;! 489E:<;! 489E:E;! 489E:E&! =3 //#pea'er Pin

489E:A;! 489E:A;! 489E:C;! 489E:A;!

%! %! 489E:B;! 489E:A;! 489E:B;! 489E:C;! 489E:<;! %

//9*e <uration o- eac* note >in s? int ti es56 1 7 $5%! $5%! $5%! $5%! $5%! $5%! $5%! $5%! 1$5! 1$5! 1$5! 1$5! 1$5! 1$5! 1$5! 1$5! $5%! $5%! $5%! $5% =3

@oid setup>? 7 //Play eac* note -or t*e rig*t duration -or >int i 1 %3 i A $%3 iBB? 7 tone>#PEA/E0! notes5i6! ti es5i6?3 delay>ti es5i6?3 = = @oid loop>? 7 //Press t*e reset Cutton to play again+ =

Fi.ure 5#5$ *ro% your te4tboo'

=. Build and code a entatonic mic!o iano system. Use the *ollowin. code and sche%atic !>istin. 5#) and Fi.ure 5#=" *ro% your te4tboo': /* Exploring Arduino - Code Listing 5-$: Pentatonic Micro Piano By Jere y Blu ! Exploring Arduino! "iley and #ons! $%1&+ */ //Pentatonic Piano //C < E D A (de-ine (de-ine (de-ine (de-ine (de-ine 489E:C 489E:< 489E:E 489E:D 489E:A $E$ $2; &&% &2$ ;;% //,F //,F //,F //,F //,F //#pea'er on Pin 2 //Button //Button //Button //Button //Button Pin Pin Pin Pin Pin

const int #PEA/E0123 const const const const const int int int int int BG9984:C1H3 BG9984:<1E3 BG9984:E153 BG9984:D1;3 BG9984:A1&3

@oid setup>? 7 //4o setup needed //9one -unction sets outputs = @oid loop>? 7 .*ile >digital0ead>BG9984:C?? tone>#PEA/E0! 489E:C?3 .*ile>digital0ead>BG9984:<?? tone>#PEA/E0! 489E:<?3 .*ile>digital0ead>BG9984:E?? tone>#PEA/E0! 489E:E?3 .*ile>digital0ead>BG9984:D?? tone>#PEA/E0! 489E:D?3 .*ile>digital0ead>BG9984:A?? tone>#PEA/E0! 489E:A?3 //#top playing i- all Cuttons *a@e Ceen released

no9one>#PEA/E0?3

Fi.ure 5#=$ *ro% your te4tboo'

?. @uestions to answer:

a. 84plain the tone!" *unction and .ive an e4a%ple. b. 84plain how this line o* code wor's: (de-ine 489E:C $E$ //,F

c. 84plain how this line o* code wor's in your pro.ra%: (include )pitc*es+*) d. Create a *low chart that %atches up with code listin. 5#1$ pa.e 1(1 in your te4tboo'. e. Create a *low chart that %atches up with code listin. 5#)$ pa.e 1(5 in your te4tboo'. *. 84plain in detail how the *ollowin. *or#loop wor's in your pro.ra%: -or >int i 1 %3 i A $%3 iBB? 7 tone>#PEA/E0! notes5i6! ti es5i6?3 delay>ti es5i6?3 = = .. 0hat is a pentatonic %usic scaleA h. At ho%e: create a sound or son. to share durin. a +hursday classB sub%it your code in the lab report.

S-ar putea să vă placă și