Let's make some noise. The buzzer also has its own driver. We can open it using the RainbowHat.openPiezo() method and it returns an object of type Speaker.
The Speaker class has two methods: play, which receives the frequency to play, and stop, which -unsurprisingly- makes the speaker stop.
To follow up from the previous section, let's build a three-tone piano where the buttons A, B, and C will play the frequencies of 1,000 Hz, 3,000 Hz, and 5,000 Hz, respectively. The buzzer will start sounding when the button is pressed and stop when the button is released.
For this example, we'll use button drivers for simplicity. The initialization and cleanup for PianoActivity looks like this:
class PianoActivity : Activity() {
private lateinit var buttonA: ButtonInputDriver
private lateinit var buttonB: ButtonInputDriver
private lateinit var buttonC:...