More Pi4J Examples

The Pi4J project includes many more comprehensive examples included both when installed locally and available in the Pi4J Exmaples project at GitHub.

Examples on GitHub

The Pi4J Examples project can be found on GitHub at this location:

Locally Installed Examples

When Pi4J is installed using the Debian package installer, Pi4J will also include all examples in the "/opt/pi4j/examples" path on your local file system.

If you have not already downloaded and installed the Pi4J library on the RaspberryPi, then view this page for instructions on where to download and how to install Pi4J:
Download & Install Pi4J


Next, use the following command to compile any of the example programs:

javac -classpath .:classes:/opt/pi4j/lib/'*' -d .


sudo pi4j --compile


The following command will run the compiled example program:

sudo java -classpath .:classes:/opt/pi4j/lib/'*' __ExampleName__


sudo pi4j --run __ExampleName__