#!/usr/bin/env python
# -*- coding: utf-8 -*-
import orangepi.zero
import OPi.GPIO as GPIO
import time
GPIO.setmode(orangepi.zero.BCM)
GPIO.setup(14, GPIO.IN)
GPIO.setup(15, GPIO.IN)
def callback(channel):
if (channel == 14):
print "Rising edge
detected. channel=",channel
if (channel == 15):
print "Falling edge
detected. channel=",channel
#You need external pulldown register
GPIO.add_event_detect(14, GPIO.RISING, callback=callback)
#You need external pullup register
GPIO.add_event_detect(15, GPIO.FALLING, callback=callback)
try:
print ("Press CTRL+C to exit")
while True:
time.sleep(0.1)
except KeyboardInterrupt:
GPIO.cleanup() # clean
up GPIO on CTRL+C exit
print ("Bye.")
|