I'm incredibly new to coding and programming, but I've been diligently trying my best with all the fun tutorials and projects I stumble upon. I decided to do a project with a friend to control a mini "animatronic" as it were.
I got down controlling the movements of the animatronic through a potentiometer controlling multiple servos! It's very delightful. However, I want to be able to also control audio with a potentiometer! I've used the wave shield package so I have the volume control knob, but I was wondering if it was feasible to also switch to a different track using the potentiometer. Maybe defining what particular notch increase will play which particular file?
I would really appreciate some help and if I haven't described my goal well enough, any questions would be fine, I'll clear anything up.
If you want to select different audio files based on the value of a potentiometer, just read the value and cut the range (0-1023) into chunks.
int value = analogRead(potPin);
if ( value > 768 ) {
song = 1;
} else if ( value > 512 ) {
song = 2;
} else if ( value > 256 ) {
song = 3;
} else {
song = 4;
}
playSong(song);
...
You can also do this using a switch statement and providing a range of values for each case statement.
blh64:
If you want to select different audio files based on the value of a potentiometer, just read the value and cut the range (0-1023) into chunks.
int value = analogRead(potPin);
if ( value > 768 ) {
song = 1;
} else if ( value > 512 ) {
song = 2;
} else if ( value > 256 ) {
song = 3;
} else {
song = 4;
}
playSong(song);
...
You can also do this using a switch statement and providing a range of values for each case statement.
Oh, thank you! That worked really smoothly, I think I'll get a better pento for some ease of control since it seems to slide like nothing but that seemed to work really well.