-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainActivity.kt
56 lines (49 loc) · 1.5 KB
/
MainActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package it.justonetouch.thingtest
import android.app.Activity
import android.os.Bundle
import android.util.Log
import com.google.android.things.pio.PeripheralManagerService
class MainActivity : Activity() {
private val TAG = "HomeActivity"
val hat = EasyRainbowHat()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d(TAG, "Available GPIO: " + PeripheralManagerService().gpioList)
hat.apply {
initValue()
ledStrip.colors(colorsRainbow)
buttonA.onClick {
if (it) {
segment.display("A")
ledStrip.colors(colorsRed)
} else {
initValue()
}
}
buttonB.onClick { segment.display(" B ${if (it) 1 else 0}") }
buttonC.onClick {
if (it) {
ledRed.on()
ledGreen.off()
ledBlue.on()
segment.display(temperature())
ledStrip.colors(colorsBlue)
} else {
initValue()
ledGreen.on()
ledStrip.colors(colorsRainbow)
}
}
}
}
private fun EasyRainbowHat.initValue() {
segment.display("2+2=4")
ledRed.off()
ledGreen.off()
ledBlue.off()
}
override fun onDestroy() {
hat.onDestroy()
super.onDestroy()
}
}