Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Android Things Quick Start Guide

You're reading from   Android Things Quick Start Guide Build your own smart devices using the Android Things platform

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher Packt
ISBN-13 9781789341799
Length 192 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Raul Portales Raul Portales
Author Profile Icon Raul Portales
Raul Portales
Arrow right icon
View More author details
Toc

Piezo buzzer

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:...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime