|
1 | 1 | --- |
2 | | -title: Pi4J Kotlin DSL |
3 | | -description: "Pi4J Kotlin DSL & API Example & Documentation" |
| 2 | +title: Pi4J with Kotlin |
4 | 3 | weight: 45 |
5 | 4 | --- |
6 | 5 |
|
7 | | -Pi4J-Kotlin (aka Pi4K) is an implementation on top of Pi4J to facilitate the development of Kotlin applications for the Raspberry Pi that can interact with the GPIOs. |
| 6 | +## Java and Kotlin: Similarities and Differences |
8 | 7 |
|
9 | | -Kotlin makes extensive use of Domain Specific Language (DSL) to provide APIs that are cleaner, easier to read, and more structured. The DSLs provided here on top of Pi4J make it very easy to use this library in a Kotlin application. These Kotlin DSLs don't introduce added runtime overhead of a new layer when used. DSL builders are always inlined on Compile-Time. |
| 8 | +As a software developer, you may be familiar with Java and Kotlin, two popular programming languages used for developing applications on many different platforms. While both languages share some similarities, they also have distinct differences that can impact your coding experience. |
10 | 9 |
|
11 | | -### Installation |
12 | | -Install the Pi4J dependency and `pi4j-ktx` in your app's `build.gradle.ktx` file: |
13 | | -``` kotlin |
14 | | -dependencies { |
15 | | - implementation("com.pi4j:pi4j-ktx:2.4.0") // Kotlin DSL |
16 | | - implementation("com.pi4j:pi4j-core:2.3.0") |
17 | | - implementation("com.pi4j:pi4j-plugin-raspberrypi:2.3.0") |
18 | | - implementation("com.pi4j:pi4j-plugin-pigpio:2.3.0") |
19 | | -} |
20 | | -``` |
| 10 | +One of the main similarities between Java and Kotlin is their ability to run on the Raspberry Pi. Both languages are supported by the Pi4J library, which provides a set of APIs for interacting with the GPIOs. This means you can use either language to develop applications that control and interact with the Raspberry Pi's hardware components. |
21 | 11 |
|
22 | | -If you want to use the [Console DSL](kotlin-api-docs/#console) to [log with SLF4J](/documentation/logging/), add the dependency: |
| 12 | +### Kotlin DSL: Simplifying Development |
23 | 13 |
|
24 | | -``` kotlin |
25 | | -implementation("org.slf4j:slf4j-api:1.7.32") |
26 | | -implementation("org.slf4j:slf4j-simple:1.7.32") |
27 | | -``` |
| 14 | +Kotlin stands out from Java due to its Domain Specific Language (DSL) capabilities. The Pi4J-Kotlin library provides a set of DSLs that simplify the development process by providing cleaner, easier-to-read APIs. These DSLs are inlined at compile-time, eliminating any runtime overhead. |
28 | 15 |
|
29 | | -### GitHub projects: |
| 16 | +### Kotlin Examples |
30 | 17 |
|
31 | | -* Kotlin Interface & DSL for Pi4J V2: [Pi4J-Kotlin](https://github.com/Pi4J/pi4j-kotlin) |
32 | | -* For Pi4J V1 Kotlin Bindings, check [Pi4K](https://github.com/mhashim6/Pi4K) |
| 18 | +Thanks to the examples created by [Oleksandr Neiko](https://www.linkedin.com/in/alexander-neiko/), a full set of Pi4J + Kotlin examples are available. |
| 19 | + |
| 20 | +## Read More |
| 21 | + |
| 22 | +{{% children depth="3" %}} |
0 commit comments