Hi, I am new to Arduino and I am trying to make a small radio. I have sample code that will play the music, but I cant find anything that will make it so that I can control the volume with a potentiometer. I would also like the potentiometer to pause the music when it reaches 0 if that is possible. So if someone could help me out that would be great. Let me know if you need the sample code. Thank you.
Of course we need the code! Please put it in code tags.
That is the volume part because the rest of it was over 9000 characters.
Here is a link to the whole script.
//if +/- to change volume
} else if((key_command == '-') || (key_command == '+')) {
union twobyte mp3_vol; // create key_command existing variable that can be both word and double byte of left and right.
mp3_vol.word = MP3player.getVolume(); // returns a double uint8_t of Left and Right packed into int16_t
if(key_command == '-') { // note dB is negative
// assume equal balance and use byte[1] for math
if(mp3_vol.byte[1] >= 254) { // range check
mp3_vol.byte[1] = 254;
} else {
mp3_vol.byte[1] += 2; // keep it simpler with whole dB's
}
} else {
if(mp3_vol.byte[1] <= 2) { // range check
mp3_vol.byte[1] = 2;
} else {
mp3_vol.byte[1] -= 2;
}
}
I figured out how to change the values on the potentiometer, but I cant get it to change the volume.
Give us a diagram of what you are making. Where is the sound coming from. Can't actually be the Arduino.
Paul
dirtbikeguy55:
Hi, I am new to Arduino and I am trying to make a small radio. I have sample code that will play the music, but I cant find anything that will make it so that I can control the volume with a potentiometer.
Are you perhaps looking for an "Alps motorpotentiometer", or what?
dirtbikeguy55:
That is the volume part because the rest of it was over 9000 characters.
You can add it as an attachment.
Ok here is the code and a picture. I have speakers plugged into the headphone jack on the mp3 shield.
FilePlayerCustom.ino (24 KB)
