Pi4K Save Abandoned

Pi4J Kotlin bindings for the Raspberry Pi GPIO.

Project README

Notice

This repo is for Pi4J V1 and is no longer maintained. The project is now maintained at Pi4J/pi4j-kotlin instead

Pi4K

Pi4J Kotlin bindings.
Awesome Kotlin Badge

Demo

Make sure to check Examples.kt.

fun blink() = digitalOutput(GPIO_01) {
    while (true) {
        toggle()
        delay(500)
    }
}
  • Pulse:
digitalOutput(GPIO_01).pulse(600)
  • Triggers:
val input = digitalInput(GPIO_04)
val output = digitalOutput(GPIO_05)
input.trigger(output) //output is HIGH when input is HIGH.
// input.trigger(output, whenState = PinState.LOW, targetState = PinState.HIGH) //output is HIGH when input is LOW.
  • Pulse triggers:
val input = digitalInput(GPIO_04)
val output = digitalOutput(GPIO_05)
input.triggerPulse(output, PinState.HIGH, millis = 1000) //when input is HIGH, output is HIGH for 1 second
  • State change listeners:
digitalInput(GPIO_06).onStateChange { event, edge, state -> println(state) }
  • PWM
pwm(clockDivisor = 500, mode = PWM_MODE_MS, range = 1000)
pwmOutput(GPIO_01, 400)
  • Software PWM
softPwmOutput(GPIO_01, 400)
  • Analog counterparts are also available.

  • When done with gpio, housekeeping is necessary;

gpioShutdown()

Testing

Tests were simulated on my machine using the PI4J_PLATFORM=Simulated Environment variable.
However, I was not able to mock/test AnalogPins bindings. Contributions are always welcome.

Dependency

  • Gradle

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Add the dependency:

dependencies {
    implementation 'com.github.mhashim6:Pi4K:0.1'
}

  • Maven
<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Add the dependency:

<dependency>
    <groupId>com.github.mhashim6</groupId>
    <artifactId>Pi4K</artifactId>
    <version>0.1</version>
</dependency>
Open Source Agenda is not affiliated with "Pi4K" Project. README Source: mhashim6/Pi4K
Stars
69
Open Issues
0
Last Commit
1 year ago
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating