Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pi4j/pi4j-kotlin
Kotlin DSL for Pi4J V2
https://github.com/pi4j/pi4j-kotlin
dsl gpio kotlin kotlin-backend kotlin-bindings kotlin-library pi4j pi4k raspberry-pi raspberry-pi-gpio
Last synced: about 1 month ago
JSON representation
Kotlin DSL for Pi4J V2
- Host: GitHub
- URL: https://github.com/pi4j/pi4j-kotlin
- Owner: Pi4J
- License: apache-2.0
- Created: 2022-09-12T15:04:05.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-07-25T13:10:02.000Z (5 months ago)
- Last Synced: 2024-11-15T02:59:33.641Z (about 1 month ago)
- Topics: dsl, gpio, kotlin, kotlin-backend, kotlin-bindings, kotlin-library, pi4j, pi4k, raspberry-pi, raspberry-pi-gpio
- Language: Kotlin
- Homepage: https://pi4j.com/kotlin/
- Size: 145 KB
- Stars: 47
- Watchers: 5
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Pi4J - Kotlin
Kotlin Interface & DSL for [Pi4J V2](https://github.com/Pi4J/pi4j-v2)
For Pi4J V1 Kotlin Bindings, check [Pi4K](https://github.com/mhashim6/Pi4K) (no longer supported).[![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin)
[![Maven Central](https://img.shields.io/maven-central/v/com.pi4j/pi4j-ktx.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.pi4j%22%20AND%20a:%22pi4j-ktx%22)
[![License](https://img.shields.io/github/license/pi4j/pi4j-v2)](http://www.apache.org/licenses/LICENSE-2.0)
![GitHub Actions build state](https://github.com/pi4j/pi4j-kotlin/workflows/Build%20pi4j-kotlin/badge.svg)## Documentation
Full documentation can be found on the [website](https://pi4j.com/kotlin/kotlin-api-docs/)## Example
This is a minimal working example, make sure
to [check it out](https://github.com/Pi4J/pi4j-kotlin/blob/master/example/src/main/kotlin/MinimalExample.kt) for full
introduction and comments.``` kotlin
const val PIN_BUTTON = 24 // PIN 18 = BCM 24
const val PIN_LED = 22 // PIN 15 = BCM 22
var pressCount = 0console {
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))
}
}
}
}
}
```