Hello everyone,
I'm working on my first 'big' arduino project, which is a midi file player. Bascially, it reads midi files from an SD card and play the notes on differents piezo buzzers.
So far, I've got it working, but I would like to adjust the volume of my buzzers depending on the velocity of the notes.
I can control the volume by changing the value of the resistor of each buzzer, and I thought of doing something like the attached picture.
In this example, I would have 2 pins controlling one buzzer, each pin would be connected to a different resistor value.That way :
- Playing the tone on pin 2 would give me a high volume
- Playing the tone on pin 3 would give me a low volume
I'm using Tone library (Google Code Archive - Long-term storage for Google Code Project Hosting.). In order to change the pin, I thought I could just call tone.begin(pin) like this :
#include <Tone.h>
Tone t1;
void setup(void)
{
t1.begin(2);
}
void loop(void)
{
// Play a high volume note
t1.play(400);
delay(1000);
t1.stop();
// Switch to pin 3 and play a low volume note
t1.begin(3);
t1.play(400);
delay(1000);
t1.stop();
}
But everytime I call tone.begin(pin), it eats a new timer instead of using the same.
So right now, I'm looking for a way to re-use the same timer, or maybe another way to change the volume of the buzzer with code.
Thanks in advance ![]()

