Skip to content

Instantly share code, notes, and snippets.

@tomaszrykala
Created January 20, 2018 23:57
Show Gist options
  • Save tomaszrykala/bdd16a6d4d378348c12643e935a1ccdd to your computer and use it in GitHub Desktop.
Save tomaszrykala/bdd16a6d4d378348c12643e935a1ccdd to your computer and use it in GitHub Desktop.
LedStripSupplierImpl.kt
class LedStripSupplierImpl : LedStripSupplier {
private val apa102: Apa102 by lazy {
RainbowHat.openLedStrip().apply {
direction = Apa102.Direction.REVERSED
brightness = 7
}
}
override fun getLength(): Int = RainbowHat.LEDSTRIP_LENGTH
override fun light(colors: IntArray) {
val writeColors = IntArray(colors.size)
colors.forEachIndexed { index, color ->
writeColors[index] = if (color == TURN_OFF_COLOR) Color.BLACK else color
}
try {
apa102.write(writeColors)
} catch (e: IOException) {
e.printStackTrace()
}
}
@Throws(Exception::class)
override fun close() {
apa102.close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment