I am so new to Raspberry Pi. I want to use pi4j 2 to flash a led that is connected to a raspberry pi. This is my code but the led does not turn on at all:
import com.pi4j.Pi4J;
import com.pi4j.io.gpio.digital.DigitalOutput;
import com.pi4j.io.gpio.digital.DigitalState;
public class RobotResource {
private static final int PIN_LED = 16;
public static void main(String[] args) throws Exception {
var pi4j = Pi4J.newAutoContext();
int x = 0;
var ledConfig = DigitalOutput.newConfigBuilder(pi4j)
.id("led")
.name("LED Flasher")
.address(PIN_LED)
.shutdown(DigitalState.LOW)
.initial(DigitalState.LOW)
.provider("pigpio-digital-output");
var led = pi4j.create(ledConfig);
while (x != 5) {
led.high();
sleep(1000);
led.low();
sleep(500);
x++;
}
}
static void sleep(int z) {
try {
Thread.sleep(z);
} catch (InterruptedException ex) {
System.out.println("Thread.sleep");
}
}
}
What should I do to turn on the led?
Thanks in advance for your guide.
sudo pigpiod
thenpigs w 16 1
thenpigs w 16 0
. Does the LED go on then off? If not check you have connected it to GPIO 16 (NOT pin 16) and that it is connected the right way around. pinout.xyz