Go Down

Topic: tone() volume with PWM (Read 4640 times) previous topic - next topic

joepshoulak

Dec 08, 2013, 07:46 am Last Edit: Dec 08, 2013, 08:03 am by joepshoulak Reason: 1
Hello.

I'm new to Arduino and could use some help with the tutorial for PWN tone() here: http://www.arduino.cc/en/Tutorial/PlayMelody

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

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

void setup() {
}

void loop() {
 tone(speaker, 440, 100);
 delay(100);
 noTone(speaker);
}


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

Thanks.

Coding Badly


I believe this library has volume control...
http://forum.arduino.cc/index.php?topic=142097.0

joepshoulak

I included the following code:
Code: [Select]

#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

Coding Badly


It's a library.  It should be installed in[font=Courier New] {SketchbookDirectory}/libraries/toneAC [/font].

Go Up