Prérequis : Installation de Raspbian et Installation de Python
Ici j’ai choisi le GPIO 17, mais vous pouvez choisir celui qui vous convient.
Code :
sudo nano tstBtn.py
#button interaction :
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.IN)
input = GPIO.input(17)
prev_input = 0
while True:
#take a reading
input = GPIO.input(17)
#if the last reading was low and this one high, print
if ((not prev_input) and input):
print("Button pressed")
#update previous input
prev_input = input
#slight pause to debounce
time.sleep(0.05)
Execution : sudo python tstBtn.py
Quiter le programme : ctrl+c