mirror of
https://github.com/Pi4J/pi4j-kotlin.git
synced 2025-12-08 00:53:28 +01:00
Kotlin DSL for Pi4J V2
dsl
gpio
kotlin
kotlin-backend
kotlin-bindings
kotlin-library
pi4j
pi4k
raspberry-pi
raspberry-pi-gpio
| .github/workflows | ||
| .run | ||
| example | ||
| gradle/wrapper | ||
| lib | ||
| .gitignore | ||
| build.gradle.kts | ||
| gradle.properties | ||
| gradlew | ||
| gradlew.bat | ||
| LICENSE.txt | ||
| README.md | ||
| settings.gradle.kts | ||
Pi4J - Kotlin
Kotlin Interface & DSL for Pi4J V2
For Pi4J V1 Kotlin Bindings, check Pi4K (no longer supported).
Documentation
Full documentation can be found on the website
Example
This is a minimal working example, make sure to check it out for full introduction and comments.
const val PIN_BUTTON = 24 // PIN 18 = BCM 24
const val PIN_LED = 22 // PIN 15 = BCM 22
var pressCount = 0
console {
title("<-- The Pi4J Project -->", "Minimal Example project")
pi4j {
digitalInput(PIN_BUTTON) {
id("button")
name("Press button")
pull(PullResistance.PULL_DOWN)
debounce(3000L)
piGpioProvider()
}.onLow {
pressCount++
+"Button was pressed for the ${pressCount}th time"
}
}
digitalOutput(PIN_LED) {
id("led")
name("LED Flasher")
shutdown(DigitalState.LOW)
initial(DigitalState.LOW)
piGpioProvider()
}.run {
while (pressCount < 5) {
+"LED ${state()}"
toggle()
sleep(500L / (pressCount + 1))
}
}
}
}
}