Calculating resistor value with a JavaFX application

Using the Java library I created (see previous post), it was a piece of cake to create a JavaFX UI on top of it!


The sources are part of the GitHub project which contains all the other examples, scripts, readmes and a lot more which are used in the book to explain Java, JavaFX, Maven, Raspberry Pi GPIO’s…

Color codings table

The enum from the library is used to create a nice overview table which also shows the colors.

public enum ColorCode {
    BLACK(0, 0x000000, 1D, null, 250),
    BROWN(1, 0x761d1d, 10D, 1D, 100),
    RED(2, 0xcc0000, 100D, 2D, 50),
    ORANGE(3, 0xFFA500, 1000D, null, 15),

Resistor value calculator

The same ColorCode enum is used in six comboboxes to calculate the resistor value based on 3 to 6 colors.

As soon as 3 or more colors are selected, the value can be calculated and displayed with:

ColorValue value = Calculate.resistorValue(
        Arrays.asList(ColorCode.ORANGE, ColorCode.YELLOW, ColorCode.GREEN, ColorCode.RED)

When selecting 6 colors, the temperature coefficient is also available:

Resistor value for LED calculator

An additional function of the library is a calculation method to know which resistor must be used for a LED.

By using JavaFX Spinner controls, the input values can be filled in and at every change of one of the inputs, the required resistor value is calculated with:

long value = Calculate.resistorForLed(