<< Creating a timeline image with JavaFX
Resistor color codes and calculations as a Java Maven library >>

Calculating resistor value with a JavaFX application

2019-11-27 09:35:52
This is a JavaFX application made and shared as preparation for my book-in-progress Getting started with Java on the Raspberry Pi.
More example applications and a lot more info about Java and the Pi in the book!
You can already buy it on Leanpub and will receive all future updates!
Using the Java library I created (see previous post), it was a piece of cake to create a JavaFX UI on top of it!

Source

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(
   inputVoltage.getValue(), 
   ledVoltage.getValue(), 
   ledCurrent.getValue()
);