2014-05-13 20:45:00 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
2014-06-24 14:41:41 +01:00
|
|
|
# Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
|
|
|
|
# Copyright (c) 2014 Intel Corporation.
|
|
|
|
|
#
|
2019-05-09 09:47:11 -07:00
|
|
|
# SPDX-License-Identifier: MIT
|
2018-01-30 11:32:18 +05:30
|
|
|
#
|
|
|
|
|
# Example Usage: Triggers ISR upon GPIO state change
|
2014-06-24 14:41:41 +01:00
|
|
|
|
2014-06-25 17:49:27 +01:00
|
|
|
import mraa
|
2014-09-19 01:06:59 +01:00
|
|
|
import time
|
2016-02-26 13:55:16 -08:00
|
|
|
import sys
|
2014-05-13 20:45:00 +00:00
|
|
|
|
2014-11-25 10:37:36 +00:00
|
|
|
class Counter:
|
2018-01-30 11:32:18 +05:30
|
|
|
count = 0
|
2014-11-25 10:37:36 +00:00
|
|
|
|
|
|
|
|
c = Counter()
|
|
|
|
|
|
2016-04-06 13:44:06 +03:00
|
|
|
# inside a python interrupt you cannot use 'basic' types so you'll need to use
|
2014-11-25 10:37:36 +00:00
|
|
|
# objects
|
2018-01-30 11:32:18 +05:30
|
|
|
def isr_routine(gpio):
|
|
|
|
|
print("pin " + repr(gpio.getPin(True)) + " = " + repr(gpio.read()))
|
|
|
|
|
c.count += 1
|
2014-05-13 20:45:00 +00:00
|
|
|
|
2018-01-30 11:32:18 +05:30
|
|
|
# GPIO
|
2016-02-26 13:55:16 -08:00
|
|
|
pin = 6;
|
2018-01-30 11:32:18 +05:30
|
|
|
|
2016-03-01 13:39:42 -08:00
|
|
|
try:
|
2018-01-30 11:32:18 +05:30
|
|
|
# initialise GPIO
|
|
|
|
|
x = mraa.Gpio(pin)
|
|
|
|
|
|
|
|
|
|
print("Starting ISR for pin " + repr(pin))
|
|
|
|
|
|
|
|
|
|
# set direction and edge types for interrupt
|
|
|
|
|
x.dir(mraa.DIR_IN)
|
|
|
|
|
x.isr(mraa.EDGE_BOTH, isr_routine, x)
|
|
|
|
|
|
|
|
|
|
# wait until ENTER is pressed
|
|
|
|
|
var = raw_input("Press ENTER to stop")
|
|
|
|
|
x.isrExit()
|
2016-03-01 13:39:42 -08:00
|
|
|
except ValueError as e:
|
|
|
|
|
print(e)
|