Music Mouse, Part IV
This post is part of a series of notes and exercises for a summer camp on making musical instruments with Arduino and Pure Data.
We’ve got horizontal motion working in the Music Mouse. Let’s add vertical motion. This will be very similar to the horizontal motion, but there is an important difference.
Vertical Motion
In loop
, read and print the value from pin A1. This pin controls the y-position. Upload and run the program. Inspect the values you see and answer these questions:
- What value do you see when the joystick is pushed all the way down?~1023
- What value do you see when the joystick is pushed all the way up?~0
It’d be nice if pushing down made the number go negative, idle was 0, and pushing up made the number go positive. Let’s make that happen. We want to turn a number in the top range into a number in the bottom range:
No, really. How do we do that?
Center the reading and test that it works.
Create variable dy
and calculate it similarly to dx
. Create variable scale_index_y
. Add code to handle changes to y
just like you did with the horizontal motion—but use the vertical variables instead.
Upload your code and test that you can change both x
and y
.