diff --git a/README.md b/README.md index 754ab26..a5258d8 100644 --- a/README.md +++ b/README.md @@ -326,11 +326,13 @@ display = Display(ssd, nxt, sel, prev, increase, decrease) Where an encoder replaces the `increase` and `decrease` buttons, only the final line needs to be changed to provide an extra arg: ```python -display = Display(ssd, nxt, sel, prev, increase, decrease, 5) +display = Display(ssd, nxt, sel, prev, increase, decrease, 4) ``` The final arg specifies the sensitivity of the attached encoder, the higher the value the more the knob has to be turned for a desired effect. A value of 1 -provides the highest sensitivity, being the native rate of the encoder. +provides the highest sensitivity, being the native rate of the encoder. Many +encoders have mechanical detents: a value of 4 matches the click rate of most +devices. The commented-out `quiet()` line provides a means of suppressing diagnostic messages. @@ -816,8 +818,7 @@ To specify to the GUI that an encoder is in use an integer should be passed to the `Display` constructor `encoder` arg. Its value represents the division ratio. A value of 1 defines the native rate of the encoder; if the native rate is 32 pulses per revolution, a value of 4 would yield a virtual device with -8 pulses per rev. I found the Adafruit encoder to be too sensitive. A value of 5 -improved usability. +8 pulses per rev. A value of 4 matches most encoders with mechanical detents. If an encoder is used but the `encoder` arg is `False`, response to the encoder will be erratic. diff --git a/gui/primitives/encoder.py b/gui/primitives/encoder.py index 8370c5d..266e2ea 100644 --- a/gui/primitives/encoder.py +++ b/gui/primitives/encoder.py @@ -15,7 +15,7 @@ class Encoder: self._pin_y = pin_y self._x = pin_x() self._y = pin_y() - self._v = 0 # Hardware value always starts at 0 + self._v = 0 # Initialise hardware value self._cv = v # Current (divided) value if ((vmin is not None) and v < vmin) or ((vmax is not None) and v > vmax): raise ValueError('Incompatible args: must have vmin <= v <= vmax') diff --git a/setup_examples/ili9341_pico_encoder.py b/setup_examples/ili9341_pico_encoder.py index 5f9e15c..222ec1d 100644 --- a/setup_examples/ili9341_pico_encoder.py +++ b/setup_examples/ili9341_pico_encoder.py @@ -51,4 +51,4 @@ sel = Pin(16, Pin.IN, Pin.PULL_UP) # Operate current control prev = Pin(18, Pin.IN, Pin.PULL_UP) # Move to previous control increase = Pin(20, Pin.IN, Pin.PULL_UP) # Increase control's value decrease = Pin(17, Pin.IN, Pin.PULL_UP) # Decrease control's value -display = Display(ssd, nxt, sel, prev, increase, decrease, 5) # Encoder +display = Display(ssd, nxt, sel, prev, increase, decrease, 4) # Encoder diff --git a/setup_examples/st7789_ttgo.py b/setup_examples/st7789_ttgo.py index 8da5ad7..602956e 100644 --- a/setup_examples/st7789_ttgo.py +++ b/setup_examples/st7789_ttgo.py @@ -101,7 +101,7 @@ from gui.core.ugui import Display nxt = Pin(32, Pin.IN, Pin.PULL_UP) # Move to next control sel = Pin(36, Pin.IN, Pin.PULL_UP) # Operate current control prev = Pin(38, Pin.IN, Pin.PULL_UP) # Move to previous control -encoder = 5 # Divide by 5 +encoder = 4 # Divide by 4 if encoder: increase = Pin(25, Pin.IN, Pin.PULL_UP) # Encoder x and y pins decrease = Pin(33, Pin.IN, Pin.PULL_UP)