使用按钮开灯关灯 接线图非常简单,LED接GPIO17号口,按钮接GPIO2号口,负极接GND地线. 代码也非常简单: from gpiozero import LED, Button from signal import pause led = LED() button = Button() button.when_pressed = led.on button.when_released = led.off pause() 复制代码 执行代码,按下按钮,发光二极管就会亮,松开就会灭. 使用按…