def test_high(): print('High detect test') GPIO.set_high_event(18) time.sleep(5) if GPIO.event_detected(18): print('Event detected') else: print('Event not detected')
if not pirState: pirState = True else: if pirState: pirState = False if pirState and (timeNow - initialTime).seconds / 60 == 5: # verific email din 5 in 5 minute initialTime = datetime.now() email.connect() if email.newEmails(): # afisez mesaj doar daca exista email-uri necitite lcd.clear() lcd.message("Email-uri necitite: %s" % (email.newEmails())) sleep(5) # afisez mesajul timp de 5 secunde lcd.clear() email.disconnect() if pirState: # daca este detectata miscare afisez email.connect() # numarul de mail-uri necitite, chiar daca acesta este 0 lcd.clear() lcd.message("Email-uri necitite: %s" % (email.newEmails())) sleep(5) # afisez mesajul timp de 5 secunde lcd.clear() email.disconnect() if (timeNowPIR - initialTimePIR).seconds / 60 == 2: # simulez schimbarea valorii senzorului PIR din 2 in 2 minute initialTimePIR = datetime.now() if GPIO.input(PIR): GPIO.set_low_event(PIR) else: GPIO.set_high_event(PIR)
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) pinBtn = 25 GPIO.setup(pinBtn,GPIO.IN, pull_up_down=GPIO.PUD_UP) pinLED = 18 GPIO.setup(pinLED,GPIO.OUT) LEDon = False GPIO.output(pinLED, LEDon) # Polling while(True): GPIO.output(pinLED,0) while(GPIO.input(pinBtn)==0): GPIO.output(pinLED,1) # Interrupt Driven """ GPIO.set_high_event(pinBtn) while(True): if(GPIO.event_detected(pinBtn)): print 'button pushed!' LEDon = not LEDon GPIO.output(pinLED,LEDon) """