以下是代码
@Controller
public class TestController {
private static final int PIN_LED = 21; // BCM引脚点亮LED灯
@RequestMapping("/")
@ResponseBody
public String test() {
System.out.println("连接成功!" + new Date());
return "测试成功呀ya!re" + new Date();
}
@RequestMapping(path = {"/led"})
@ResponseBody
public String getParamDemo1() throws InterruptedException {
final Console console = new Console();
console.title("<-- The Pi4J Project Of Raspberry -->", "点亮一盏LED灯");
Context pi4j = Pi4J.newAutoContext();
DigitalOutputConfigBuilder ledConfig = DigitalOutput.newConfigBuilder(pi4j)
.id("led")
.name("LED shine")
.address(PIN_LED)
.shutdown(DigitalState.LOW)
.initial(DigitalState.LOW)
.provider("pigpio-digital-output");
DigitalOutput led = pi4j.create(ledConfig);
for (int i = 0; i < 100; i++) {
led.high();
System.out.println("点亮成功!");
Thread.sleep(400);
led.low();
Thread.sleep(400);
}
pi4j.shutdown();
System.out.println("------test success!-------");
return "success led shine!";
}
}
评论