diff --git a/examples/python/hello_isr.py b/examples/python/hello_isr.py index cb02488..b5aaff4 100644 --- a/examples/python/hello_isr.py +++ b/examples/python/hello_isr.py @@ -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()