experimental.a_to_d

Utilities for converting analogue signals to digital inputs

class experimental.a_to_d.AnalogReaderDigitalWrapper(ain, debounce=1, high_low_cutoff=0.8, cb_rising=<function AnalogReaderDigitalWrapper.<lambda>>, cb_falling=<function AnalogReaderDigitalWrapper.<lambda>>)

Wraps an AnalogReader to allow it to simulate a DigitalReader.

The EuroPiScript class using the AnalogReaderDigitalWrapper must call .update() to read the current state of the analogue input and trigger any rising/falling edge callbacks.

The value returned by .value() is accurate to the last time .update() was called.

Parameters
  • ain – The AnalogReader we’re wrapping

  • debounce – The number of consecutive high/low signals needed to flip the digital state

  • high_low_cutoff – The threshold at which the analog signal is considered high

  • cb_rising – A function to call on the rising edge of the signal

  • cb_falling – A function to call on the falling edge of the signal

handler(func)

Define the callback function to call when rising edge detected.

handler_falling(func)

Define the callback function to call when falling edge detected.

update()

Reads the current value of the analogue input and updates the internal state

value()

Returns europi.HIGH or europi.LOW depending on the state of the input