2,425
社区成员
发帖
与我相关
我的任务
分享
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
PeripheralManager pio = PeripheralManager.getInstance();
try {
inputPin = pio.openGpio("BCM4");
inputPin.setDirection(Gpio.DIRECTION_IN);//设置该引脚为输入
inputPin.setActiveType(Gpio.ACTIVE_HIGH);//设置该引脚悬空时 为高电平
outputPin = pio.openGpio("BCM17");
outputPin.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
inputPin.setEdgeTriggerType(Gpio.EDGE_FALLING);
inputPin.registerGpioCallback(new GpioCallback() {
@Override
public boolean onGpioEdge(Gpio gpio) {
try {
boolean callbackStste = gpio.getValue();
if (callbackStste){
outputPin.setValue(false);
}else {
outputPin.setValue(true);
}
} catch (IOException e) {
e.printStackTrace();
}
return true;
}
});