arduino-volume1 icon indicating copy to clipboard operation
arduino-volume1 copied to clipboard

Unexpected results using noTone()

Open glyndavidson opened this issue 5 years ago • 0 comments

The standard arduino tone() function allows a third parameter 'duration'.

As this is absent in the volume.tone(), I thought I'd use a delay followed by the volume.noTone() command.

Example:

#include <Volume.h>
Volume vol;

void setup() {
  vol.begin();
}
void loop() {
  vol.tone(900, 255);
  vol.delay(500);
  vol.noTone();
  vol.delay(500);
}

I thought this would turn the buzzer on for a half a second then turn it off for half a second and keep repeating, however, it just results in complete silence (Arduino Nano).

Very strangely though, the following code works perfectly!?!?!

#include <Volume.h>
Volume vol;

void setup() {
  vol.begin();
  Serial.begin(9600);
}
void loop() {
  vol.tone(900, 255);
  Serial.println("Tone");
  vol.delay(500);
  vol.noTone();
  Serial.println("No Tone");
  vol.delay(500);
}

And this works:

#include <Volume.h>
Volume vol;

void setup() {
  vol.begin();
  Serial.begin(9600);
}
void loop() {
  vol.tone(900, 255);
  Serial.println("Tone");
  vol.delay(500);
  vol.noTone();
  /* Serial.println("No Tone"); */
  vol.delay(500);
}

But this doesn't...

#include <Volume.h>
Volume vol;

void setup() {
  vol.begin();
  Serial.begin(9600);
}
void loop() {
  vol.tone(900, 255);
  /* Serial.println("Tone"); */
  vol.delay(500);
  vol.noTone();
  Serial.println("No Tone");
  vol.delay(500);
}

glyndavidson avatar Dec 04 '19 11:12 glyndavidson