I have created a Java-project using Pi4j and LibGDX. I have integrated the simple example from the official homepage of the Pi4j project in my project. I have changed only the number of the LEDs from 4 to 10 and tested the program with a LED strip (ws2811) with 10 LEDs. Runtime is Java 17 (Liberica JDK). But the first LED doesn't shine. The full code is below:
public class MyGdxGame extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
@Override
public void create () {
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
System.out.println("LED strip app started ...");
int pixels = 10;
Context pi4j;
final var piGpio = PiGpio.newNativeInstance();
pi4j = Pi4J.newContextBuilder()
.noAutoDetect()
.add(new RaspberryPiPlatform() {
@Override
protected String[] getProviders() {
return new String[]{};
}
})
.add(PiGpioDigitalInputProvider.newInstance(piGpio),
PiGpioDigitalOutputProvider.newInstance(piGpio),
PiGpioPwmProvider.newInstance(piGpio),
PiGpioSerialProvider.newInstance(piGpio),
PiGpioSpiProvider.newInstance(piGpio)
//LinuxFsI2CProvider.newInstance()
)
.build();
final LedStrip ledStrip = new LedStrip(pi4j, pixels, 0.5);
//set them all off, so nothing is shining
System.out.println("Starting with setting all leds off");
ledStrip.allOff();
System.out.println("setting the LEDs to RED");
ledStrip.setStripColor(PixelColor.RED);
ledStrip.render();
delay(3000);
System.out.println("setting the LEDs to Light Blue");
ledStrip.setStripColor(PixelColor.LIGHT_BLUE);
ledStrip.render();
delay(3000);
System.out.println("setting the first led to Purple");
ledStrip.setPixelColor(0, PixelColor.PURPLE);
ledStrip.render();
delay(3000);
System.out.println("setting the brightness to full and just show the first led as White");
ledStrip.allOff();
ledStrip.setBrightness(1);
ledStrip.setPixelColor(0, PixelColor.WHITE);
ledStrip.render();
delay(3000);
//finishing and closing
ledStrip.close();
System.out.println("closing the app");
System.out.println("Color "+ ledStrip.getPixelColor(0));
System.out.println("LED strip app done.");
}
@Override
public void render () {
ScreenUtils.clear(0, 0, 0, 1);
batch.begin();
//batch.draw(img, 0, 0);
batch.end();
}
@Override
public void dispose () {
batch.dispose();
img.dispose();
}
private static void delay(int milliseconds){
try {
Thread.sleep(milliseconds);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
why doesn't the first LED shine?