I
I
intTosha2016-02-01 19:28:14
Arduino
intTosha, 2016-02-01 19:28:14

Arduino. How to make a melody for two or more piezo emitters?

Good day. I want to write a simple melody for the arduino board. So to say, I am pouring into the musical sphere from the side of programming). But since any piece of music cannot exist without harmony, one piezo emitter is not enough for me. The question arises of using multiple buzzers. The "but" comes up again. The tone() operator can only play one sound source, the second buzzer just doesn't play anything. In this case, for example, only the sound with output to 3 pin, which is earlier in the code, at a frequency of 500 Hertz, will be played, the second sound to 7 pin will not be played.

tone(3,500,150);
tone(7,300,500);
delay(700);

Please help me because I can't figure it out myself.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Gusev, 2016-02-01
@Sanchogus

"Only one signal can be played at a time. If the signal is already playing on one port, then calling Tone() with a different port number as a parameter will not lead to anything, if Tone() is called with the same port number, then new signal frequency."

There is no way to go by means of Arduino.
"Generates a signal on the input/output port - a square wave, of the specified frequency and with 50% duty cycle. The duration can be set by a parameter, otherwise the signal is generated until the noTone () function is called. connected to a piezo or other speaker to play a
signal.Using the Tone() function will prevent you from using PWM on I/O ports 3 and 11 (except on the Arduino Mega board)."

It follows from this that it is implemented on a timer.
And there are 3 timers on Una, 4 on mega, if I'm not mistaken. Zero will affect the delay, it is better not to touch it.
So you need to go to those who program Atmels, not arduinos and ask how to make a square wave at x Hertz in C / Assembler for several pins at different frequencies.
Or if the functionality is minimal, try just turning the port off with delays of milliseconds, cram a function into it and enjoy life. But this will heavily load the MK if done in the forehead.
Well, or find something that will generate a meander of a given frequency and be controlled from the MK.

V
vanyamba-electronics, 2016-02-11
@vanyamba-electronics

To control signal generation with Arduino, you will need to learn fast PWM (pulse width modulation) signal generation. I think this article on signal generation with Arduino will be useful.
Arduino. Signal generator

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question