Private
Public Access
2
0

examples: Updated python gpio isr example

Example now takes pin number from command line and displays gpio level
when it changes.

Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Henry Bruce
2016-02-26 13:55:16 -08:00
committed by Brendan Le Foll
parent bc1c3469f5
commit b1fd66c561

View File

@@ -24,6 +24,7 @@
import mraa
import time
import sys
class Counter:
count = 0
@@ -32,12 +33,19 @@ c = Counter()
# inside a python interupt you cannot use 'basic' types so you'll need to use
# objects
def test(args):
print("wooo")
def test(gpio):
print("pin " + repr(gpio.getPin(True)) + " = " + repr(gpio.read()))
c.count+=1
x = mraa.Gpio(6)
pin = 6;
if (len(sys.argv) == 2):
try:
pin = int(sys.argv[1], 10)
except ValueError:
printf("Invalid pin " + sys.argv[1])
print("Starting ISR for pin " + repr(pin))
x = mraa.Gpio(pin)
x.dir(mraa.DIR_IN)
x.isr(mraa.EDGE_BOTH, test, test)
time.sleep(500)
x.isr(mraa.EDGE_BOTH, test, x)
var = raw_input("Press ENTER to stop")
x.isrExit()