15
Making Music with VEX Mike Martin King High School, Riverside, CA PLTW State Conference – February 19, 2015 [email protected]

Making Music with VEX Mike Martin King High School, Riverside, CA PLTW State Conference – February 19, 2015 [email protected]

Embed Size (px)

Citation preview

Page 1: Making Music with VEX Mike Martin King High School, Riverside, CA PLTW State Conference – February 19, 2015 mmartin@rusdlearns.net

Making Music with VEX

Mike MartinKing High School, Riverside, CA

PLTW State Conference – February 19, [email protected]

Page 2: Making Music with VEX Mike Martin King High School, Riverside, CA PLTW State Conference – February 19, 2015 mmartin@rusdlearns.net

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.

Page 3: Making Music with VEX Mike Martin King High School, Riverside, CA PLTW State Conference – February 19, 2015 mmartin@rusdlearns.net

Music Theory

Frere Jacques / Brother John

4/4 TimeQuarter NotesHalf NotesEighth Notes

Measures - Bars

What do you notice about themeasures and bars?

Page 4: Making Music with VEX Mike Martin King High School, Riverside, CA PLTW State Conference – February 19, 2015 mmartin@rusdlearns.net

Music Theory

There are 4 groups of notes that are repeated twice.

This allows us to simplify our programming.

Page 5: Making Music with VEX Mike Martin King High School, Riverside, CA PLTW State Conference – February 19, 2015 mmartin@rusdlearns.net

Programming the VEX Cortex

• How do we program a note?• Frequency – each note must have a different frequency.

• Middle C – also called C4

Page 6: Making Music with VEX Mike Martin King High School, Riverside, CA PLTW State Conference – February 19, 2015 mmartin@rusdlearns.net

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.

Page 7: Making Music with VEX Mike Martin King High School, Riverside, CA PLTW State Conference – February 19, 2015 mmartin@rusdlearns.net

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?

Page 8: Making Music with VEX Mike Martin King High School, Riverside, CA PLTW State Conference – February 19, 2015 mmartin@rusdlearns.net

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:

Page 9: Making Music with VEX Mike Martin King High School, Riverside, CA PLTW State Conference – February 19, 2015 mmartin@rusdlearns.net

Programming the VEX Cortex

• How do we program a note?• What will a loop look like?

Page 10: Making Music with VEX Mike Martin King High School, Riverside, CA PLTW State Conference – February 19, 2015 mmartin@rusdlearns.net

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 }}

Page 11: Making Music with VEX Mike Martin King High School, Riverside, CA PLTW State Conference – February 19, 2015 mmartin@rusdlearns.net

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

Page 12: Making Music with VEX Mike Martin King High School, Riverside, CA PLTW State Conference – February 19, 2015 mmartin@rusdlearns.net

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.

Page 13: Making Music with VEX Mike Martin King High School, Riverside, CA PLTW State Conference – February 19, 2015 mmartin@rusdlearns.net

Using Switches to Play Music

• How do I program the Cortex to play music with switches?

Page 14: Making Music with VEX Mike Martin King High School, Riverside, CA PLTW State Conference – February 19, 2015 mmartin@rusdlearns.net

Using Switches to Play Music

• How do I program the Cortex to play music with switches?

Page 15: Making Music with VEX Mike Martin King High School, Riverside, CA PLTW State Conference – February 19, 2015 mmartin@rusdlearns.net

Using Switches to Play Music

• Project Idea – a full keyboard!• File available upon request.