Rotary Encoders

class pico_synth_sandbox.encoder.Encoder(board, index=0, value_when_pressed=False)[source]

Bases: Task

Use the on-board encoder to control your program with simple function callbacks. Supports increment, decrement, click, double click, and long press actions.

is_pressed() bool[source]

Get the current state of the button pin without debouncing.

Returns:

state of the button, True = pressed, False = released

Return type:

bool

set_click(callback)[source]

Set the callback method you would like to be called when the encoder is pressed with a short click (at least 200ms).

Parameters:

callback (function) – The callback method. No callback parameters are defined.

set_decrement(callback)[source]

Set the callback method you would like to be called when the encoder is decremented (turned left).

Parameters:

callback (function) – The callback method. No callback parameters are defined.

set_double_click(callback)[source]

Set the callback method you would like to be called when the encoder is pressed with two short clicks.

Parameters:

callback (function) – The callback method. No callback parameters are defined.

set_increment(callback)[source]

Set the callback method you would like to be called when the encoder is incremented (turned right).

Parameters:

callback (function) – The callback method. No callback parameters are defined.

set_long_press(callback)[source]

Set the callback method you would like to be called when the encoder is pressed with a single long press (at least 500ms).

Parameters:

callback (function) – The callback method. No callback parameters are defined.

async update()[source]

Update the encoder logic and call any pre-defined callbacks if triggered.