I need to play sound on 10 piezos at once. How to do that without delay()
function.
Code Gorilla
5,6521 gold badge17 silver badges31 bronze badges
-
You could use the millis() function of your Arduino...Fusseldieb– Fusseldieb2017年03月07日 11:51:53 +00:00Commented Mar 7, 2017 at 11:51
-
@Fusseldieb post example pleaseLowder– Lowder2017年03月07日 11:52:53 +00:00Commented Mar 7, 2017 at 11:52
-
1Use the blink-without-delay pattern arduino.cc/en/Tutorial/BlinkWithoutDelay, a TimeMarker github.com/mikaelpatel/Arduino-Timemark or a Scheduler github.com/mikaelpatel/Arduino-SchedulerMikael Patel– Mikael Patel2017年03月07日 13:20:19 +00:00Commented Mar 7, 2017 at 13:20
1 Answer 1
Use the Timer library.
You can attach up to 10 events to each Timer
object you declare. That will suit your use case.
answered Mar 7, 2017 at 15:39
-
-
Why this code not work?
long ids[10]; void playNote(int pin, unsigned long freq) { int ms = 1000/freq; ids[pin] = t.oscillate(pin, ms / 2, HIGH); } void stopNote(int pin) { t.stop(ids[pin]); }
Lowder– Lowder2017年03月09日 13:40:38 +00:00Commented Mar 9, 2017 at 13:40 -
Post a new question with your full code and not just a snippet, You'll get much better help. I'll also participate.Enric Blanco– Enric Blanco2017年03月09日 15:58:34 +00:00Commented Mar 9, 2017 at 15:58