SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
(continued from previous page)
// to calculate the note duration, take one second divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int
noteDuration
=
1000
/
noteDurations [i];
tone
(
15
, melody [i], noteDuration);
//to distinguish the notes, set a minimum time between them
//the note's du30% seems to work well
int
pauseBetweenNotes
=
noteDuration
*
1.30
;
delay
(pauseBetweenNotes);
}
}
First read the value of the button in loop(). When the button is pressed,
buttonState
will be equal to 1.
In the for() statement, a
is used to let the buzzer play one note at a time, and then after 8 times, the buzzer can
play the notes in the array melody[] one by one.
tone
(
15
, melody [i], noteDuration);
•
15
: The pin on which to generate the tone (the buzzer pin).
•
melody [i]
: The frequency of the tone in hertz.
•
noteDuration
: The duration of the tone in milliseconds (optional).
else
{
noTone
(
15
);
//if the button is released, stop the tone playing.
}
Stops the generation of a square wave triggered by tone(). Has no effect if no tone is being generated.
The new projects for Arduino are still being updated continuously.
4.2. Projects
159
Summary of Contents for Thales Kit
Page 1: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 Jimmy SunFounder Jun 04 2021 ...
Page 2: ......
Page 4: ...ii ...
Page 6: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 CONTENTS ...
Page 140: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 136 Chapter 3 For MicroPython User ...
Page 164: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 160 Chapter 4 For Arduino User ...