A
A
Alex Alex2016-05-21 16:18:08
Arduino
Alex Alex, 2016-05-21 16:18:08

How to make several piezo tweeters squeak at the same time?

Good day, comrades.
There was a need to connect two piezo tweeters, which should squeak on a specific event. The problem is that the tone() method, which generates a sound wave, cannot make several tweeters beep at the same time. I tried using the ArduinoThread library to implement multithreading, but it did not work out. Here is this example soltau.ru/index.php/arduino/item/373-kak-vypolnyat...
Has anyone encountered a similar problem? How to generate sound wave without tone() method?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Gusev, 2016-05-21
@Alex_512

Tone makes a square wave of a certain frequency.
The dumbest method is to write a function that will toggle the pin at regular intervals.
Let's say we need a frequency f = 3kHz. The period is T = 1/f s.
Switching the pin every t = T/2 seconds, we get our square wave at 3 kHz.
Only it will be necessary to overtake time in microseconds.
f = 3000;
T = 1000000/f;//period in µs
t = T/2; // half-cycle time
I can mess up in the code:
We take the remainder of dividing the timer of microseconds by the period.
If the remainder is greater than the half-cycle, then one state (high), otherwise another (low).
But this line will need to be called constantly.
if((micros() % T) > t) digitalWrite(BUZZ1, HIGH);
else digitalWrite(BUZZ1, LOW);
A better option is to do this on interrupts from one of the timers.

A
Alexander Volkov, 2016-05-21
@a_volkov1987

Why not take the path of least resistance and buy tweeters with a built-in generator? The difference in price is small, but it’s easier to manage and you don’t need to spend resources on squeaking. Or is it critical for you to be able to play the melody on squeakers?

S
Sly_tom_cat ., 2016-05-22
@Sly_tom_cat

But it’s not clear to me - if they squeak at the same time, then why not hang them on one output with an elementary amplifier on any transistor?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question