I need to play sound on 10 piezos at once. How to do that without delay() function.
Asked
Active
Viewed 132 times
2
Code Gorilla
- 5,617
- 1
- 14
- 31
Lowder
- 27
- 5
-
You could use the millis() function of your Arduino... – Fusseldieb Mar 07 '17 at 11:51
-
@Fusseldieb post example please – Lowder Mar 07 '17 at 11:52
-
1Use the blink-without-delay pattern https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay, a TimeMarker https://github.com/mikaelpatel/Arduino-Timemark or a Scheduler https://github.com/mikaelpatel/Arduino-Scheduler – Mikael Patel Mar 07 '17 at 13:20
1 Answers
1
Use the Timer library.
You can attach up to 10 events to each Timer object you declare. That will suit your use case.
Enric Blanco
- 2,103
- 1
- 12
- 25
-
-
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 Mar 09 '17 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 Mar 09 '17 at 15:58