2017-02-01 7 views

Antwort

1

Ich gehe davon aus, dass die Schaltfläche, die Sie verwenden, in GPIO18 ist, so dass Sie diesen Code verwenden können.

import RPi.GPIO as GPIO 
import time 

GPIO.setmode(GPIO.BCM) 

GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) 

while True: 
    input_state = GPIO.input(18) 
    while not input_state: 
     # as soon as your button is pressed you 
     # will be inside this loop 
     print('Button is being pressed') 

Alternativ können Sie auch versuchen:

import time 
import RPi.GPIO as GPIO 

PIN = 18 

GPIO.setmode(GPIO.BCM) 
GPIO.setup(PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) 

while True: 
    GPIO.wait_for_edge(PIN, GPIO.FALLING) 
    print "Pressed" 
    # your code 

denke ich, die zweite Ziele genauer Ihre Anfrage.

Verwandte Themen