Skip to content

HoldYourWaffle/blinkt4j

 
 

Repository files navigation

blinkt4j

GPLv3 license

Java library for controlling the Pimoroni Blinkt LED-strip on the Raspberry Pi. Derived from hackerjimbo/PiJava, but stripped and tweaked specifically for the Blinkt, including some additional convenience methods.

Usage

Requirements

  • Java 8 (newer versions probably work, but have not been tested)
  • wiringpi

Gradle

You can use jitpack.io to add this library to your project:

repositories {
	maven { url 'https://jitpack.io' }
	maven { url 'https://oss.sonatype.org/content/groups/public' } // Required for transitive pi4j dependency
}

dependencies {
	compile 'com.github.HoldYourWaffle:blinkt4j:v1.3.1'
}

Example

import java.awt.Color;
import jimbo.pijava.blinkt.BlinktController;

public class BlinktExample {
	
	public static void main(String[] args) throws InterruptedException {
		BlinktController blinkt = new BlinktController();
		blinkt.setBrightness(.1F);
		
		boolean movingForward = true;
		int i = 1;
		
		while (true) {
			// Clear any previous state
			blinkt.clear();
			
			// Set the left pixel to red
			blinkt.set(i-1, Color.RED);
			// Set the middle pixel to green
			blinkt.set(i, 0, 255, 0);
			// Set the last pixel to blue, at full brightness
			blinkt.set(i+1, Color.BLUE, 1);
			
			// Push state to the GPIO pins
			blinkt.push();
			
			// Cycle the lights from left to right and back
			if (movingForward) i++;
			else i--;
			
			if (i >= 7) {
				i = 5;
				movingForward = false;
			} else if (i <= 0) {
				i = 2;
				movingForward = true;
			}
			
			Thread.sleep(250);
		}
	}
	
}

Further information can be found in the Javadoc-comments.

Troubleshooting

Permission denied

Make sure the user running your program is a member of the gpio group:

sudo usermod -a -G gpio username

Alternatively, try running your program with sudo.

About

Java library for controlling the Pimoroni Blinkt on a Raspberry Pi

Resources

License

Stars

Watchers

Forks

Languages

  • Java 100.0%