kopia lustrzana https://github.com/peterhinch/micropython-micro-gui
Update encoder examples to advise div ratio of 4.
rodzic
cef366f9de
commit
95af8c625f
|
@ -326,11 +326,13 @@ display = Display(ssd, nxt, sel, prev, increase, decrease)
|
||||||
Where an encoder replaces the `increase` and `decrease` buttons, only the final
|
Where an encoder replaces the `increase` and `decrease` buttons, only the final
|
||||||
line needs to be changed to provide an extra arg:
|
line needs to be changed to provide an extra arg:
|
||||||
```python
|
```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
|
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
|
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
|
The commented-out `quiet()` line provides a means of suppressing diagnostic
|
||||||
messages.
|
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
|
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
|
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
|
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
|
8 pulses per rev. A value of 4 matches most encoders with mechanical detents.
|
||||||
improved usability.
|
|
||||||
|
|
||||||
If an encoder is used but the `encoder` arg is `False`, response to the encoder
|
If an encoder is used but the `encoder` arg is `False`, response to the encoder
|
||||||
will be erratic.
|
will be erratic.
|
||||||
|
|
|
@ -15,7 +15,7 @@ class Encoder:
|
||||||
self._pin_y = pin_y
|
self._pin_y = pin_y
|
||||||
self._x = pin_x()
|
self._x = pin_x()
|
||||||
self._y = pin_y()
|
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
|
self._cv = v # Current (divided) value
|
||||||
if ((vmin is not None) and v < vmin) or ((vmax is not None) and v > vmax):
|
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')
|
raise ValueError('Incompatible args: must have vmin <= v <= vmax')
|
||||||
|
|
|
@ -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
|
prev = Pin(18, Pin.IN, Pin.PULL_UP) # Move to previous control
|
||||||
increase = Pin(20, Pin.IN, Pin.PULL_UP) # Increase control's value
|
increase = Pin(20, Pin.IN, Pin.PULL_UP) # Increase control's value
|
||||||
decrease = Pin(17, Pin.IN, Pin.PULL_UP) # Decrease 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
|
||||||
|
|
|
@ -101,7 +101,7 @@ from gui.core.ugui import Display
|
||||||
nxt = Pin(32, Pin.IN, Pin.PULL_UP) # Move to next control
|
nxt = Pin(32, Pin.IN, Pin.PULL_UP) # Move to next control
|
||||||
sel = Pin(36, Pin.IN, Pin.PULL_UP) # Operate current control
|
sel = Pin(36, Pin.IN, Pin.PULL_UP) # Operate current control
|
||||||
prev = Pin(38, Pin.IN, Pin.PULL_UP) # Move to previous 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:
|
if encoder:
|
||||||
increase = Pin(25, Pin.IN, Pin.PULL_UP) # Encoder x and y pins
|
increase = Pin(25, Pin.IN, Pin.PULL_UP) # Encoder x and y pins
|
||||||
decrease = Pin(33, Pin.IN, Pin.PULL_UP)
|
decrease = Pin(33, Pin.IN, Pin.PULL_UP)
|
||||||
|
|
Ładowanie…
Reference in New Issue