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.
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:
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:
Center the reading and test that it works.
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