experimental.thread

Additional classes and utilities for multi-threading support using _thread

class experimental.thread.DigitalInputHelper(on_din_rising=<function DigitalInputHelper.<lambda>>, on_din_falling=<function DigitalInputHelper.<lambda>>, on_b1_rising=<function DigitalInputHelper.<lambda>>, on_b1_falling=<function DigitalInputHelper.<lambda>>, on_b2_rising=<function DigitalInputHelper.<lambda>>, on_b2_falling=<function DigitalInputHelper.<lambda>>)

Helper class for reading digital inputs & outputs without using ISRs

_thread can lock up if ISRs fire too frequently (e.g. pressing B1 repeatedly to select a mode). To avoid using ISRs this class can be used in your main thread to simulate the behaviour of ISRs by running a callback function when the state of the digital input changes.

In your main loop you must call .update() to read the current state of the inputs & invoke the callback functions

Calling .update() will populate the following fields of the DigitalInputHelper: * b1_last_pressed: the ms tick time that b1 was last pressed * b1_last_released: the ms tick time that b1 was last released * b1_pressed: True if b1 is currently pressed down, otherwise False * b1_rising: True if b1 transitioned to the pressed state during the last update() call, otherwise False * b1_falling: True if b1 transitioned to the released state during the last update() call, otherwise False * b2_last_pressed: the ms tick time that b2 was last pressed * b2_last_released: the ms tick time that b2 was last released * b2_pressed: True if b2 is currently pressed down, otherwise False * b2_rising: True if b1 transitioned to the pressed state during the last update() call, otherwise False * b2_falling: True if b1 transitioned to the released state during the last update() call, otherwise False * din_last_rise: the ms tick time that din last received a rising signal * din_last_fall: the ms tick time that din last received a falling signal * din_high: True if din is currently high, otherwise False * din_rising: True if din transitioned to the high state during the last update() call, otherwise False * din_falling: True if b1 transitioned to the low state during the last update() call, otherwise False

Parameters
  • on_din_rising – Callback function to invoke when din detects a rising edge

  • on_din_falling – Callback function to invoke when din detects a falling edge

  • on_b1_rising – Callback function to invoke when b1 detects a rising edge

  • on_b1_falling – Callback function to invoke when b1 detects a falling edge

  • on_b2_rising – Callback function to invoke when b2 detects a rising edge

  • on_b2_falling – Callback function to invoke when b2 detects a falling edge

update()

Check the state of the digital inputs, call the callback functions when appropriate

This function should be called inside the main loop of your program