tone() volume with PWM


I'm new to Arduino and could use some help with the tutorial for PWN tone() here:

So say I have a tone 440MHz I want to play, and that's all I want to play, for the entire loop. So

int speaker = 8; // I understand this will have to change for PWM

void setup() {

void loop() {
  tone(speaker, 440, 100);

How do I get this to play at a different volume? 1/2 the volume? 1/4? 1/x?


I believe this library has volume control...

I included the following code:

#include <toneAC.h>

void setup() {} // Nothing to setup, just start playing!

void loop() {
  for (unsigned long freq = 150; freq <= 15000; freq += 10) {  
    toneAC(freq); // Play the frequency (150 Hz to 15 kHz in 10 Hz steps).
    delay(1);     // Wait 1 ms so you can hear it.
  toneAC(0); // Turn off toneAC, can also use noToneAC().

  while(1); // Stop (so it doesn't repeat forever driving you crazy--you're welcome).

and it gave me an error saying that toneAC was not declared. I made sure that the file toneAC.h was in the same folder, as well as toneAC.cpp

It's a library. It should be installed in {SketchbookDirectory}/libraries/toneAC .