A lightweight Kotlin library to calculate electrical parameters using Ohm's Law.
- Calculate current (I) given voltage (V) and resistance (R).
- Calculate voltage (V) given current (I) and resistance (R).
- Calculate resistance (R) given voltage (V) and current (I).
You can use this library with Jitpack. Add the following to your build.gradle:
repositories {
...
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.JuanBindez:kohmslaw:v1.0.0'
}
Or if you are using kotlin-DSL in an build.gradle.kts file:
repositories {
mavenCentral()
maven("https://jitpack.io")
}
dependencies {
implementation("com.github.JuanBindez:kohmslaw:v1.0.0")
}
import com.example.ohmslaw.OhmsLaw
fun main() {
val ohmsLaw = OhmsLaw()
val current = ohmsLaw.calculateCurrent(12.0, 6.0) // 2.0 A
val voltage = ohmsLaw.calculateVoltage(2.0, 6.0) // 12.0 V
val resistance = ohmsLaw.calculateResistance(12.0, 2.0) // 6.0 Ω
println("Current: $current A")
println("Voltage: $voltage V")
println("Resistance: $resistance Ω")
}
- Kotlin 1.9+
- Gradle 8.10+
This project is licensed under the MIT License.