VCC=>3.3v GND=>ground IN=>GPIO 01 Normally open, the common terminal is a switch import com.pi4j.io.gpio.GpioController; import com.pi4j.io.gpio.GpioFactory; import com.pi4j.io.gpio.GpioPinDigitalOutput; import com.pi4j.io.gpio.PinState; import com.pi4j.io.gpio.RaspiPin; public class Test{ public static void main(String args[]) throws InterruptedException { System.out.println("Hello World"); // create a GPIO controller final GpioController gpio = GpioFactory.getInstance(); // Get the No. 1 GPIO pin and set the high level state, which corresponds to the No. 12 pin on the Raspberry Pi. You can refer to the picture provided by pi4j. final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, "LED", PinState.HIGH); //final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_00, "REDLED", PinState.HIGH); while(true){ //set high level pin.high(); System.out.println("Turn off the light"); // sleep for 1 second Thread.sleep(1000); //set low level pin.low(); System.out.println("Turn on the light"); Thread.sleep(1000); // switch state pin.toggle(); } } }
Tree mold pie controls lights
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326530430&siteId=291194637
Recommended
Ranking