Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add+doc percent() to Rotary #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ Examples:
* `set(min_val=0, max_val=59)` change encoder bounds - useful to set minutes on a clock display
* `set(value=6)` change encoder value to `6`. calling `value()` will now return `6`
***
`percent(scale=100.0)` Return the encoder value in percent

Examples:
* `percent()` Return the encoder value in percent (0.0 through 100.0)
* `percent(scale=1.0)` Return the encoder value in the range 0.0 through 1.0
***
`reset()` set encoder value to `min_val`. Redundant with the addition of the `set()` method. Retained for backwards compatibility)
***
`add_listener(function)` add a callback function that will be called on each change of encoder count
Expand Down
3 changes: 3 additions & 0 deletions rotary.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ def set(self, value=None, min_val=None, incr=None,
def value(self):
return self._value

def percent(self, scale=100.0):
return scale * (self._value - self._min_val) / (self._max_val - self._min_val)

def reset(self):
self._value = 0

Expand Down