Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Android Things Quick Start Guide

You're reading from  Android Things Quick Start Guide

Product type Book
Published in Aug 2018
Publisher Packt
ISBN-13 9781789341799
Pages 192 pages
Edition 1st Edition
Languages
Author (1):
Raul Portales Raul Portales
Profile icon Raul Portales

LED strip (Apa102)

For the last part, we have the RGB LED strip, which is the one that gives the Rainbow HAT its name. It has seven RGB LEDs that we can set to any combination of colors.

For this example, we will just use the color red, because we are going to build a moving LED like that of KITT from Knight Rider or, if you prefer, from a Cylon eye. Having such pop culture references at hand, our example could not be any other one.

For this example, we will use a timer and keep track of the current position that is lit up, and also check edge conditions to bounce and change direction.

Let's start with the initialization and cleanup code:

class KnightRiderSimpleActivity : Activity() {
private val timer: Timer = Timer()
private var goingUp = true
private var currentPos = 0
private val interval: Long = 100

val colors = IntArray(RainbowHat.LEDSTRIP_LENGTH)
...
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 $15.99/month. Cancel anytime}