Use the piezoelectric loudspeaker in the SP&PIR Leaf to make the melody sound.
Leaf to use
Use the following leaves.
|CR2032 coin cell battery||1|
Let’s assemble leaves as shown in the figure below.
Open the Arduino, go to
File → Sketch Examples → 02.Digital → toneMelody.
In this sample code, the speaker is supposed to be connected to pin number 8.
But as the loudspeaker is connected to pin 5 in Leafony, you should fix the following part to make it correct.1
- Change the
PB4in line 37.
tone(PB4, melody[thisNote], noteDuration);
PB4in line 44.
The melody sounds only once from the speakers.
Last modified 15.03.2021