Simple LED


The SimpleLed is a template class, that you can use in your own Java-project.

The template Class gives you the option to switch off, switch on or toggle the state of the LED.


Simple LED Layout


A simple example on how to use the LED-Class from the Hardware-Catalog:

System.out.println("Simple LED app started ...");

// Create a new SimpleLED component
SimpleLed led = new SimpleLed(pi4j, PIN.D26);

// Turn on the LED to have a defined state
System.out.println("Turn on LED.");

// Make a flashing light by toggling the LED every second
for (int i = 0; i < 10; i++) {
	System.out.println("Current LED state is " + led.toggleState() +".");

// That's all so turn off the relay and quit;
System.out.println("Turn off LED.");

System.out.println("Simple LED app done.");

Further application

The class is implemented in the two sample projects Theremin and Photobooth.

Further project ideas

  • Use an infrared LED to establish communication with an infrared receiver.
  • Use several red LEDs to recreate the running lights of KITT, the car from Knight Rider.