Loading...
Searching...
No Matches
Encoder Class Reference

The shield's rotary encoder (ENC1) and its push switch. More...

Public Member Functions

 position (self)
 Gets the number of clicks turned since the start or set_position().
 steps (self)
 Gets the raw count: four steps per click.
 set_position (self, clicks=0)
 Sets the count, e.g.
 pressed (self)
 Reads the push switch now.
 on_press (self, callback)
 Calls a function each time the knob is pressed.

Detailed Description

The shield's rotary encoder (ENC1) and its push switch.

A and B (D3, D4) and the switch (D2) have pull-ups and RC filters on the shield, so the pins are inputs with no pull of their own. Pin interrupts count each change of A and B, so no turn is missed while your program does something else. Use encoder() to get the shield's instance rather than making another.

Turning clockwise counts up, one per click.

Member Function Documentation

◆ position()

position ( self)

Gets the number of clicks turned since the start or set_position().

Returns
Clicks, positive clockwise and negative anticlockwise.

◆ steps()

steps ( self)

Gets the raw count: four steps per click.

Returns
Steps since the start or set_position().

◆ set_position()

set_position ( self,
clicks = 0 )

Sets the count, e.g.

back to 0.

Parameters
clicksThe new position() value.

◆ pressed()

pressed ( self)

Reads the push switch now.

Returns
True while the knob is pressed in.

◆ on_press()

on_press ( self,
callback )

Calls a function each time the knob is pressed.

The function runs soon after the press, between lines of your program (MicroPython's micropython.schedule()), and takes no arguments. A press within 100 ms of the switch last changing, pressed or released, is taken as switch bounce.

Parameters
callbackA function, or None to stop.
Example
def pressed():
shield.encoder().set_position(0)
shield.encoder().on_press(pressed)

The documentation for this class was generated from the following file:
  • analog_shield.py