Skip to content

Commit de1913d

Browse files
committed
Extending Kotlin section
1 parent c4e171d commit de1913d

8 files changed

Lines changed: 56 additions & 22 deletions

File tree

content/kotlin/_index.md

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
---
2-
title: Pi4J Kotlin DSL
3-
description: "Pi4J Kotlin DSL & API Example & Documentation"
2+
title: Pi4J with Kotlin
43
weight: 45
54
---
65

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
87

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.
109

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.
2111

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
2313

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.
2815

29-
### GitHub projects:
16+
### Kotlin Examples
3017

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" %}}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Pi4J Kotlin DSL
3+
description: "Pi4J Kotlin DSL & API Example & Documentation"
4+
weight: 45
5+
---
6+
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.
8+
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.
10+
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+
```
21+
22+
If you want to use the [Console DSL](kotlin-api-docs/#console) to [log with SLF4J](/documentation/logging/), add the dependency:
23+
24+
``` kotlin
25+
implementation("org.slf4j:slf4j-api:1.7.32")
26+
implementation("org.slf4j:slf4j-simple:1.7.32")
27+
```
28+
29+
### GitHub projects:
30+
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)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Useful Tips
3+
weight: 2
4+
---
5+
6+
{{% notice note %}}
7+
GITHUB PROJECT: [https://github.com/RoboticsLife/Lesson02-Gpio-Kotlin-Pi4J](https://github.com/RoboticsLife/Lesson02-Gpio-Kotlin-Pi4J)
8+
{{% /notice %}}
9+
10+
11+
12+
{{< youtube bYqifO31qI0 >}}

0 commit comments

Comments
 (0)