I shall point you into to right direction regarding the volume control.
From the pictures I have seen, you are using a stereo motorpot. If you connected it just like Leon's integration guide, you connected only one channel of the stereo pot to the BIII. Now you can use the other (free) channel to read the volume.
What you must do is let Arduino read the resistance of the pot. You can do this by connecting connecting the free channel of the pot like this:
You can use any of the free analog pins.
To read the resistance you need the following code (in blue):
#define potPin 2 // define the analog pin, pin 2 in this caseint val = 0; // variable to store the value coming from the potentiometervoid loop() { val = analogRead(potPin); // read the value from the sensor}The value coming from the potentiometer will be somewhere between 0 and 1023, depending on the level of resitance. The value is proportional to the amount of voltage being applied to the used analoge pin.
When you turn the volume all the way up there will be no resistance and the value will be 1023 (=5 volt to the pin) while turning the volume all the way down there will be 10K resistance (depending on the pot you used) and the value would be 0 (= 0 volt to the pin).
Now you know that reading the resistance gives you a value between 0 and 1023 you can work out a way to show the correct volume. If you used a linear pot this is easy, especially if it doesn't matter if the scale is not a Db scale.
What I would suggest is is using a scale from 0 to 99 to display the volume, this way you would have 100 steps in volume (just like HiFiDUINO).
The easiest way is to devide 1023 by 100. (1023/100=10.23). Now you know that for every step up or down in volume the analogRead value goes roughly 10 points up or down. So lets say you turn the volume up about halfway and the analogRead function return a value of 480. The displayed volume would be 480/10=48.
#define potPin 2 // define the analog pin, pin 2 in this caseint val = 0; // variable to store the value coming from the potentiometerint volumeToDisplay; // variable to store the volume to be displayedvoid loop() { val = analogRead(potPin); // read the value from the sensor volumeToDisplay = (val / 10); // calculate the volume }Diving it by 10 is not fully accurate, but probably accurate enough. If not you can always change the code using floating point numbers, like this:
#define potPin 2 // define the analog pin, pin 2 in this casefloat val = 0; // variable to store the value coming from the potentiometerint volumeToDisplay; // variable to store the volume to be displayedvoid loop() { val = analogRead(potPin); // read the value from the sensor volumeToDisplay = (val / 10.23) + 0.5; // calculate the volume }Using floating point numbers allow you to calculate it more accuratly, but the calculated volume now needs to be rounded in order to display a two number value. That's why the 0.5 needs to be added to the calculated value.
Knowing how to read and calculate the volume you just need to display it. This code can be found in the HifiDUINO code, but if you don't know where to find it, I can send the code to you if you like.
Edited by user Sunday, August 26, 2012 3:44:55 PM(UTC)
| Reason: Not specified