Python machine.Pin.IRQ_RISING Examples

The following are 21 code examples of machine.Pin.IRQ_RISING(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module machine.Pin , or try the search function .
Example #1
Source File: trigger.py    From ulnoiot-upy with MIT License 10 votes vote down vote up
def __init__(self, name, pin,
                 rising=False, falling=False,
                 pullup=True, on_change=None, report_change=True):
        if pullup:
            pin.init(Pin.IN, Pin.PULL_UP)
        else:
            pin.init(Pin.IN, Pin.OPEN_DRAIN)
        if rising and falling:
            trigger = Pin.IRQ_RISING | Pin.IRQ_FALLING
        elif not rising and falling:
            trigger = Pin.IRQ_FALLING
        else:  # also if both all false
            trigger = Pin.IRQ_RISING
        pin.irq(trigger=trigger, handler=self._cb)
        self.counter = 0
        self.report_counter = 0
        self.triggered = False
        Device.__init__(self, name, pin, on_change=on_change,
                        report_change=report_change)
        self.getters[""] = self.value 
Example #2
Source File: button.py    From 1ZLAB_MicroPython_ESP32_Tutorial with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self,button_idx, callback=None):
        # 按键字典
        # 数据结构: (GPIO编号,按键抬起的电平, 按键按下的电平)
        button_list = [(39, False, True)]

        if button_idx < 0 or button_idx >= len(button_list):
            print("ERROR: Wrong Button Index")
            print("Valid Button Index: {} - {}".format(0, len(button_list)-1))
            return None

        gpio_id, self.BUTTON_RELEASE, self.BUTTON_PRESS, = button_list[button_idx]
        # 按键
        self.pin = Pin(gpio_id, Pin.IN)
        # 回调函数
        self.callback = callback
        # 设置外部中断
        if self.BUTTON_PRESS == True:
            self.pin.irq(trigger=Pin.IRQ_RISING, handler=self.irq_handler)
        else:
            self.pin.irq(trigger=Pin.IRQ_FALLING, handler=self.irq_handler)
        
        # 标志位 当前是否可以相应按键中断
        self.flag = True 
Example #3
Source File: button.py    From 1ZLAB_MicroPython_ESP32_Tutorial with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self,button_idx, callback=None):
        # 按键字典
        # 数据结构: (GPIO编号,按键抬起的电平, 按键按下的电平)
        button_list = [(39, False, True)]

        if button_idx < 0 or button_idx >= len(button_list):
            print("ERROR: Wrong Button Index")
            print("Valid Button Index: {} - {}".format(0, len(button_list)-1))
            return None

        gpio_id, self.BUTTON_RELEASE, self.BUTTON_PRESS, = button_list[button_idx]
        # 按键
        self.pin = Pin(gpio_id, Pin.IN)
        # 回调函数
        self.callback = callback
        # 设置外部中断
        if self.BUTTON_PRESS == True:
            self.pin.irq(trigger=Pin.IRQ_RISING, handler=self.irq_handler)
        else:
            self.pin.irq(trigger=Pin.IRQ_FALLING, handler=self.irq_handler)
        
        # 标志位 当前是否可以相应按键中断
        self.flag = True 
Example #4
Source File: aremote.py    From micropython-async with MIT License 6 votes vote down vote up
def __init__(self, pin, callback, extended, *args):  # Optional args for callback
        self._ev_start = Event()
        self._callback = callback
        self._extended = extended
        self._addr = 0
        self.block_time = 80 if extended else 73  # Allow for some tx tolerance (?)
        self._args = args
        self._times = array('i',  (0 for _ in range(_EDGECOUNT + 1)))  # +1 for overrun
        if platform == 'pyboard':
            ExtInt(pin, ExtInt.IRQ_RISING_FALLING, Pin.PULL_NONE, self._cb_pin)
        else:  # PR5962 ESP8266 hard IRQ's not supported
            pin.irq(handler = self._cb_pin, trigger = (Pin.IRQ_FALLING | Pin.IRQ_RISING))
        #elif ESP32:
            #pin.irq(handler = self._cb_pin, trigger = (Pin.IRQ_FALLING | Pin.IRQ_RISING))
        #else:
            #pin.irq(handler = self._cb_pin, trigger = (Pin.IRQ_FALLING | Pin.IRQ_RISING), hard = True)
        self._edge = 0
        self._ev_start.clear()
        loop = asyncio.get_event_loop()
        loop.create_task(self._run()) 
Example #5
Source File: button.py    From 1ZLAB_PyEspCar with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self,button_idx, callback=None):
        # 按键字典
        # 数据结构: (GPIO编号,按键抬起的电平, 按键按下的电平)
        button_list = [(39, False, True)]

        if button_idx < 0 or button_idx >= len(button_list):
            print("ERROR: Wrong Button Index")
            print("Valid Button Index: {} - {}".format(0, len(button_list)-1))
            return None

        gpio_id, self.BUTTON_RELEASE, self.BUTTON_PRESS, = button_list[button_idx]
        # 按键
        self.pin = Pin(gpio_id, Pin.IN)
        # 回调函数
        self.callback = callback
        # 设置外部中断
        if self.BUTTON_PRESS == True:
            self.pin.irq(trigger=Pin.IRQ_RISING, handler=self.irq_handler)
        else:
            self.pin.irq(trigger=Pin.IRQ_FALLING, handler=self.irq_handler)
        
        # 标志位 当前是否可以相应按键中断
        self.flag = True 
Example #6
Source File: trigger.py    From ulnoiot-upy with MIT License 6 votes vote down vote up
def __init__(self, name, pin,
                 rising=False, falling=False,
                 pullup=True, on_change=None, report_change=True):
        if pullup:
            pin.init(Pin.IN, Pin.PULL_UP)
        else:
            pin.init(Pin.IN, Pin.OPEN_DRAIN)
        if rising and falling:
            trigger = Pin.IRQ_RISING | Pin.IRQ_FALLING
        elif not rising and falling:
            trigger = Pin.IRQ_FALLING
        else:  # also if both all false
            trigger = Pin.IRQ_RISING
        pin.irq(trigger=trigger, handler=self._cb)
        self.counter = 0
        self.report_counter = 0
        self.triggered = False
        Device.__init__(self, name, pin, on_change=on_change,
                        report_change=report_change)
        self.getters[""] = self.value 
Example #7
Source File: trigger.py    From ulnoiot-upy with MIT License 6 votes vote down vote up
def __init__(self, name, pin,
                 rising=False, falling=False,
                 pullup=True, on_change=None, report_change=True):
        if pullup:
            pin.init(Pin.IN, Pin.PULL_UP)
        else:
            pin.init(Pin.IN, Pin.OPEN_DRAIN)
        if rising and falling:
            trigger = Pin.IRQ_RISING | Pin.IRQ_FALLING
        elif not rising and falling:
            trigger = Pin.IRQ_FALLING
        else:  # also if both all false
            trigger = Pin.IRQ_RISING
        pin.irq(trigger=trigger, handler=self._cb)
        self.counter = 0
        self.report_counter = 0
        self.triggered = False
        Device.__init__(self, name, pin, on_change=on_change,
                        report_change=report_change)
        self.getters[""] = self.value 
Example #8
Source File: trigger.py    From ulnoiot-upy with MIT License 6 votes vote down vote up
def __init__(self, name, pin,
                 rising=False, falling=False,
                 pullup=True, on_change=None, report_change=True):
        if pullup:
            pin.init(Pin.IN, Pin.PULL_UP)
        else:
            pin.init(Pin.IN, Pin.OPEN_DRAIN)
        if rising and falling:
            trigger = Pin.IRQ_RISING | Pin.IRQ_FALLING
        elif not rising and falling:
            trigger = Pin.IRQ_FALLING
        else:  # also if both all false
            trigger = Pin.IRQ_RISING
        pin.irq(trigger=trigger, handler=self._cb)
        self.counter = 0
        self.report_counter = 0
        self.triggered = False
        Device.__init__(self, name, pin, on_change=on_change,
                        report_change=report_change)
        self.getters[""] = self.value 
Example #9
Source File: trigger.py    From ulnoiot-upy with MIT License 6 votes vote down vote up
def __init__(self, name, pin,
                 rising=False, falling=False,
                 pullup=True, on_change=None, report_change=True):
        if pullup:
            pin.init(Pin.IN, Pin.PULL_UP)
        else:
            pin.init(Pin.IN, Pin.OPEN_DRAIN)
        if rising and falling:
            trigger = Pin.IRQ_RISING | Pin.IRQ_FALLING
        elif not rising and falling:
            trigger = Pin.IRQ_FALLING
        else:  # also if both all false
            trigger = Pin.IRQ_RISING
        pin.irq(trigger=trigger, handler=self._cb)
        self.counter = 0
        self.report_counter = 0
        self.triggered = False
        Device.__init__(self, name, pin, on_change=on_change,
                        report_change=report_change)
        self.getters[""] = self.value 
Example #10
Source File: m5stack.py    From micropython-m5stack with MIT License 5 votes vote down vote up
def __init__(self, callback=None, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING):
        pin = Pin(BUTTON_C_PIN, Pin.IN)
        DigitalInput.__init__(self, pin, callback=callback, trigger=trigger) 
Example #11
Source File: aremote.py    From micropython-async with MIT License 5 votes vote down vote up
def __init__(self, pin, callback, extended, *args):  # Optional args for callback
        self._ev_start = Message()
        self._callback = callback
        self._extended = extended
        self._addr = 0
        self.block_time = 80 if extended else 73  # Allow for some tx tolerance (?)
        self._args = args
        self._times = array('i',  (0 for _ in range(_EDGECOUNT + 1)))  # +1 for overrun
        if platform == 'pyboard':
            ExtInt(pin, ExtInt.IRQ_RISING_FALLING, Pin.PULL_NONE, self._cb_pin)
        else:  # PR5962 ESP8266 hard IRQ's not supported
            pin.irq(handler = self._cb_pin, trigger = (Pin.IRQ_FALLING | Pin.IRQ_RISING))
        self._edge = 0
        self._ev_start.clear()
        asyncio.create_task(self._run()) 
Example #12
Source File: sx127x.py    From uPyLoRaWAN with Apache License 2.0 5 votes vote down vote up
def on_receive(self, callback):
        self._on_receive = callback

        if self._pin_rx_done:
            if callback:
                self.write_register(REG_DIO_MAPPING_1, 0x00)
                self._pin_rx_done.irq(
                    trigger=Pin.IRQ_RISING, handler = self.handle_on_receive
                )
            else:
                self._pin_rx_done.detach_irq() 
Example #13
Source File: encoder.py    From micropython-stm-lib with MIT License 5 votes vote down vote up
def set_callbacks(self, callback=None):
        mode = Pin.IRQ_RISING | Pin.IRQ_FALLING
        self.irq_clk = self.pin_clk.irq(trigger=mode, handler=callback)
        self.irq_dt = self.pin_dt.irq(trigger=mode, handler=callback) 
Example #14
Source File: m5stack.py    From micropython-m5stack with MIT License 5 votes vote down vote up
def __init__(self, callback=None, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING):
        pin = Pin(BUTTON_B_PIN, Pin.IN)
        DigitalInput.__init__(self, pin, callback=callback, trigger=trigger) 
Example #15
Source File: m5stack.py    From micropython-m5stack with MIT License 5 votes vote down vote up
def __init__(self, callback=None, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING):
        pin = Pin(BUTTON_A_PIN, Pin.IN)
        DigitalInput.__init__(self, pin, callback=callback, trigger=trigger) 
Example #16
Source File: input.py    From micropython-m5stack with MIT License 5 votes vote down vote up
def __init__(self, pin, callback=None, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING):
        self._register = bytearray([0b11111111])
        self._user_callback = callback
        self._current_state = False
        self._previous_state = False
        self._pin = pin
        self._pin.init(self._pin.IN, trigger=trigger, handler=self._callback) 
Example #17
Source File: encoder_portable.py    From micropython-samples with MIT License 5 votes vote down vote up
def __init__(self, pin_x, pin_y, reverse, scale):
        self.reverse = reverse
        self.scale = scale
        self.forward = True
        self.pin_x = pin_x
        self.pin_y = pin_y
        self._pos = 0
        self.x_interrupt = pin_x.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=self.x_callback)
        self.y_interrupt = pin_y.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=self.y_callback) 
Example #18
Source File: esp_8266.py    From python_banyan with GNU Affero General Public License v3.0 5 votes vote down vote up
def set_mode_digital_input(self,payload):
  pin=payload['pin']
  pin_in=Pin(pin,Pin.IN,Pin.PULL_UP)
  pin_in.irq(trigger=Pin.IRQ_RISING|Pin.IRQ_FALLING,handler=self.digital_input_callback)
  self.input_pin_objects[pin]=pin_in 
Example #19
Source File: esp_8266Full.py    From python_banyan with GNU Affero General Public License v3.0 5 votes vote down vote up
def set_mode_digital_input(self, payload):
        """
        Set a pin as a digital input with pull_up and
        enable interrupts for a change on either edge.
        :param payload:
        :return:
        """
        pin = payload['pin']
        pin_in = Pin(pin, Pin.IN, Pin.PULL_UP)
        pin_in.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=self.digital_input_callback)
        self.input_pin_objects[pin] = pin_in 
Example #20
Source File: controller_esp.py    From SX127x_driver_for_MicroPython_on_ESP8266 with GNU General Public License v3.0 5 votes vote down vote up
def prepare_irq_pin(self, pin_id):
        pin = self.prepare_pin(pin_id, Pin.IN)
        if pin:
            pin.set_handler_for_irq_on_rising_edge = lambda handler: pin.irq(handler = handler,
                                                                             trigger = Pin.IRQ_RISING)
            pin.detach_irq = lambda: pin.irq(handler = None, trigger = 0)
            return pin 
Example #21
Source File: controller_esp.py    From SX127x_driver_for_MicroPython_on_ESP8266 with GNU General Public License v3.0 5 votes vote down vote up
def prepare_irq_pin(self, pin_id): 
        pin = self.prepare_pin(pin_id, Pin.IN) 
        if pin:
            pin.set_handler_for_irq_on_rising_edge = lambda handler: pin.irq(handler = handler, trigger = Pin.IRQ_RISING)
            pin.detach_irq = lambda : pin.irq(handler = None, trigger = 0)
            return pin