Making Music with the Arduino Uno

Download Report

Transcript Making Music with the Arduino Uno

Making Music with VEX
Mike Martin
King High School, Riverside, CA
PLTW State Conference – February 19, 2015
[email protected]
Introduction
• Teaching kids to write programming code has become a priority for
STEM programs like PLTW.
• Many of our PLTW students are also involved with music, whether
band, choir, or off-campus.
• Learning to program music can add another component to an already
fun, challenging, and rewarding POE class.
Music Theory
Frere Jacques / Brother John
4/4 Time
Quarter Notes
Half Notes
Eighth Notes
Measures - Bars
What do you notice about the
measures and bars?
Music Theory
There are 4 groups of notes that are repeated twice.
This allows us to simplify our programming.
Programming the VEX Cortex
• How do we program a note?
• Frequency – each note must have a different frequency.
• Middle C – also called C4
Programming the VEX Cortex
• How do we program a note?
• Let’s use Variables to represent each frequency.
• Let’s use Variables to also represent the quarter and half notes.
Programming the VEX Cortex
• How do we program a note?
• What command do we use to play a note on the VEX Cortex using RobotC?
Programming the VEX Cortex
• How do we program a note?
• How do we ‘loop’ the notes that are being repeated?
• Let’s use a For loop:
Programming the VEX Cortex
• How do we program a note?
• What will a loop look like?
Programming the VEX Cortex
• How do we program the entire song?
• Put all of the For loops consecutive:
void setup ()
{
for (int i=0; i<2; i++)
{
body
}
for (int i=0; i<2; i++)
{
body
}
for (int i=0; i<2; i++)
{
body
}
for (int i=0; i<2; i++)
{
body
}
}
Programming the VEX Cortex
• How do we actually play the song on the Cortex?
• VEX speaker – plug into SP port in Digital section of Cortex
• Speaker is available for $9.99
• Using some other speaker not recommended – bad sound
Using Switches to Play Music
• Not only can we program the song into the Uno, but we can set up
our own “VEX Keyboard”
• VEX switches are probably the easiest to access, since your school
probably has POE or CIM. (Isn’t that why you’re here?  )
• Momentary push-button switches can also be used.
Using Switches to Play Music
• How do I program the Cortex to play music with switches?
Using Switches to Play Music
• How do I program the Cortex to play
music with switches?
Using Switches to Play Music
• Project Idea – a full keyboard!
• File available upon request.