-->
Page 1 of 1

PWM/analogWrite() and tone()

PostPosted: Wed Apr 26, 2017 2:18 pm
by Thomas Runge
I have a Touch-TFT display, a photo resistor and a buzzer connected to a Wemos D1 mini. Depending on the photo resistor value (read via A0) I control the background LED of the TFT via analogWrite(). If I touch on the screen I make some click-noise via tone().

Very often (not always!) the screen gets completely dark whenever the first sound rings.

Digging into source code I found, that both (PWM and Tone) are both using timer1. This smells a lot like a concurrency problem.

Can anyone confirm that one must not use PWM and Tone at the same time?

Are there any recommendations to work around that problem? Currently I just analogWrite(PIN, 0) to stop timer1 before any sounds. Ugly, but works.

--
Tom