Volume change between 2 different tones?

I am trying to alter the volume between many different tones.

I do not need to turn the volume level up, just some tones need to be much quieter.

here is a snippet of my sketch:

void setup()
{
 pinMode(TICK_PIN,OUTPUT);
for(int i = 0;i < 5;i++)

tone(TICK_PIN,200,5);            //pitch,duration
    delay(500);
    tone(TICK_PIN,1000,5);      //pitch,duration
    delay(500);

I am using an Arduino Mega, and I am powering an 8ohm speaker with an LM386 op amp.
I can control total volume of all the notes, but would like to lower some and keep others at the regular volume.

Thank you to all who have helped me out so far, much appreciated!

This is just a wild thought that may not work ...

Perhaps you could use the Arduino to control a digital potentiometer that controls the gain of the OpAmp ?

...R

Two ideas:

  1. Use another digital output when you want a quieter tone. Combine both outputs through a resistor network so there is more attenuation of the signal from the extra output (input impedance of your LM386 amplifier is about 50kΩ). Use more digital outputs to give more than two signal levels if you wish. There's the option to make unused digital outputs become inputs when they are not being used so they become high impedance.

  2. Don't use the tone() function. Write code to generate square waves with unequal mark:space ratio.

Digital volume control usually is implemented by an DAC, whose reference voltage is the sound signal. The controller provides the digital volume, e.g. 0-255 for an 8 bit DAC.