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:
committed by
Brendan Le Foll
parent
bc1c3469f5
commit
b1fd66c561
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
import mraa
|
import mraa
|
||||||
import time
|
import time
|
||||||
|
import sys
|
||||||
|
|
||||||
class Counter:
|
class Counter:
|
||||||
count = 0
|
count = 0
|
||||||
@@ -32,12 +33,19 @@ c = Counter()
|
|||||||
|
|
||||||
# inside a python interupt you cannot use 'basic' types so you'll need to use
|
# inside a python interupt you cannot use 'basic' types so you'll need to use
|
||||||
# objects
|
# objects
|
||||||
def test(args):
|
def test(gpio):
|
||||||
print("wooo")
|
print("pin " + repr(gpio.getPin(True)) + " = " + repr(gpio.read()))
|
||||||
c.count+=1
|
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.dir(mraa.DIR_IN)
|
||||||
x.isr(mraa.EDGE_BOTH, test, test)
|
x.isr(mraa.EDGE_BOTH, test, x)
|
||||||
|
var = raw_input("Press ENTER to stop")
|
||||||
time.sleep(500)
|
x.isrExit()
|
||||||
|
|||||||
Reference in New Issue
Block a user