arduino / ArduinoCore-avr

The Official Arduino AVR core
https://www.arduino.cc
1.21k stars 1.04k forks source link

tone() used with delay() #110

Open cds333 opened 5 years ago

cds333 commented 5 years ago

If the delay is less than the duration no tone will play. Using delay() after tone() only works if the delay is longer than the tone's duration, and then only for the time that is equal to (duration - delay)

For example, looping the following plays nothing:

tone(piezoPin, 2000, 500); delay(500);

While looping the following plays 500ms tones followed by 50ms of silences

tone(piezoPin, 2000, 500); delay(550);

Using official build 1.8.7

PaulStoffregen commented 5 years ago

Please give us a complete program, so we can copy it into Arduino without having the fill in (guess) the rest of the code, and then upload to a board to see the problem.

Also, let us know which board. The tone() code is different on some boards, so that too is a pretty important detail for anyone to actually investigate this problem.

cds333 commented 5 years ago

void setup() { }

void loop() { tone(8, 2000, 500); delay(500); }

cds333 commented 5 years ago

Lanmu Arduino Uno R3 clone:

https://www.miniarduino.com/lanmu-uno-r3-board-atmega328p-atmega16u2-compatible-with-arduino-uno-r3/

Also tried it on another brand R3 clone and same thing.

cds333 commented 5 years ago

Used with one of these piezo buzzers connected to the pin with a single 100 ohm resistor.

https://www.amazon.com/GFORTUN-Terminals-Electronic-Continuous-Industrial/dp/B0716FD838/ref=sr_1_15?ie=UTF8&qid=1544752294&sr=8-15&keywords=piezo+buzzer