Created
January 20, 2018 23:57
-
-
Save tomaszrykala/bdd16a6d4d378348c12643e935a1ccdd to your computer and use it in GitHub Desktop.
LedStripSupplierImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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