Skip to content

Commit

Permalink
Merge pull request #928 from gpiozero/rotary
Browse files Browse the repository at this point in the history
Add RotaryEncoder support
  • Loading branch information
bennuttall committed Mar 3, 2021
2 parents 8beee82 + 29b4316 commit be7f898
Show file tree
Hide file tree
Showing 77 changed files with 6,230 additions and 790 deletions.
4 changes: 2 additions & 2 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ images/composite_device_hierarchy.dot: $(PY_SOURCES)
-x Motor \
-x PhaseEnableMotor \
-x Servo \
-o SourceMixin -o HoldMixin > $@
-o SourceMixin > $@

images/spi_device_hierarchy.dot: $(PY_SOURCES)
./images/class_graph -i SPIDevice > $@
Expand Down Expand Up @@ -224,7 +224,7 @@ images/input_device_hierarchy.dot: $(PY_SOURCES)
gnuplot -e "set term pngcairo size 640,480" $< > $@

%.png: %.svg
inkscape -e $@ $<
inkscape --export-dpi 150 -e $@ $<

%.pdf: %.svg
inkscape -A $@ $<
Expand Down
7 changes: 7 additions & 0 deletions docs/api_input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ DistanceSensor (HC-SR04)
:members: wait_for_in_range, wait_for_out_of_range, trigger, echo, when_in_range, when_out_of_range, max_distance, distance, threshold_distance, value


RotaryEncoder
-------------

.. autoclass:: RotaryEncoder(a, b, \*, bounce_time=None, max_steps=16, threshold_steps=(0, 0), wrap=False, pin_factory=None)
:members: wait_for_rotate, wait_for_rotate_clockwise, wait_for_rotate_counter_clockwise, when_rotated, when_rotated_clockwise, when_rotated_counter_clockwise, steps, value, max_steps, threshold_steps, wrap


Base Classes
============

Expand Down
30 changes: 30 additions & 0 deletions docs/examples/color_picker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from threading import Event
from colorzero import Color
from gpiozero import RotaryEncoder, RGBLED, Button

rotor = RotaryEncoder(16, 20, wrap=True, max_steps=180)
rotor.steps = -180
led = RGBLED(22, 23, 24, active_high=False)
btn = Button(21, pull_up=False)
led.color = Color('#f00')
done = Event()

def change_hue():
# Scale the rotor steps (-180..180) to 0..1
hue = (rotor.steps + 180) / 360
led.color = Color(h=hue, s=1, v=1)

def show_color():
print('Hue {led.color.hue.deg:.1f}° = {led.color.html}'.format(led=led))

def stop_script():
print('Exiting')
done.set()

print('Select a color by turning the knob')
rotor.when_rotated = change_hue
print('Push the button to see the HTML code for the color')
btn.when_released = show_color
print('Hold the button to exit')
btn.when_held = stop_script
done.wait()
Binary file modified docs/images/button_bb.pdf
Binary file not shown.
Binary file modified docs/images/button_bb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/button_robot_bb.pdf
Binary file not shown.
Binary file modified docs/images/button_robot_bb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/color_picker.fzz
Binary file not shown.
Binary file added docs/images/color_picker_bb.pdf
Binary file not shown.
Binary file added docs/images/color_picker_bb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4,632 changes: 4,632 additions & 0 deletions docs/images/color_picker_bb.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions docs/images/composed_devices.dot
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ digraph classes {
PhaseEnableMotor->PWMOutputDevice;

Servo->PWMOutputDevice;

RotaryEncoder->InputDevice;
}
Binary file modified docs/images/composed_devices.pdf
Binary file not shown.
Binary file modified docs/images/composed_devices.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
316 changes: 188 additions & 128 deletions docs/images/composed_devices.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion docs/images/composite_device_hierarchy.dot
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ digraph classes {
/* Mixin classes */
node [color="#c69ee0", fontcolor="#000000"]


EventsMixin;
HoldMixin;

/* Abstract classes */
node [color="#9ec6e0", fontcolor="#000000"]
Expand All @@ -20,11 +21,13 @@ digraph classes {
node [color="#2980b9", fontcolor="#ffffff"];

ButtonBoard->CompositeDevice;
ButtonBoard->HoldMixin;
CamJamKitRobot->Robot;
CompositeDevice->Device;
CompositeOutputDevice->CompositeDevice;
Energenie->Device;
FishDish->CompositeOutputDevice;
HoldMixin->EventsMixin;
JamHat->CompositeOutputDevice;
LEDBarGraph->LEDCollection;
LEDBoard->LEDCollection;
Expand All @@ -39,6 +42,8 @@ digraph classes {
PololuDRV8835Robot->PhaseEnableRobot;
PumpkinPi->LEDBoard;
Robot->CompositeDevice;
RotaryEncoder->CompositeDevice;
RotaryEncoder->EventsMixin;
RyanteckRobot->Robot;
SnowPi->LEDBoard;
StatusBoard->CompositeOutputDevice;
Expand Down
Binary file modified docs/images/composite_device_hierarchy.pdf
Binary file not shown.
Binary file modified docs/images/composite_device_hierarchy.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
400 changes: 221 additions & 179 deletions docs/images/composite_device_hierarchy.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions docs/images/device_hierarchy.dot
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ digraph classes {
RGBLED->SourceMixin;
Robot->CompositeDevice;
Robot->SourceMixin;
RotaryEncoder->CompositeDevice;
RotaryEncoder->EventsMixin;
RyanteckRobot->Robot;
SPIDevice->Device;
Servo->CompositeDevice;
Expand Down
Binary file modified docs/images/device_hierarchy.pdf
Binary file not shown.
Binary file modified docs/images/device_hierarchy.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
770 changes: 394 additions & 376 deletions docs/images/device_hierarchy.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/device_pin_flowchart.pdf
Binary file not shown.
Binary file modified docs/images/device_pin_flowchart.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/distance_sensor_bb.pdf
Binary file not shown.
Binary file modified docs/images/distance_sensor_bb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/input_device_hierarchy.pdf
Binary file not shown.
Binary file modified docs/images/input_device_hierarchy.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 18 additions & 18 deletions docs/images/input_device_hierarchy.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/internal_device_hierarchy.pdf
Binary file not shown.
Binary file modified docs/images/internal_device_hierarchy.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/led_bb.pdf
Binary file not shown.
Binary file modified docs/images/led_bb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/led_button_bb.pdf
Binary file not shown.
Binary file modified docs/images/led_button_bb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/ledbargraph_bb.pdf
Binary file not shown.
Binary file modified docs/images/ledbargraph_bb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/ledboard_bb.pdf
Binary file not shown.
Binary file modified docs/images/ledboard_bb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/light_sensor_bb.pdf
Binary file not shown.
Binary file modified docs/images/light_sensor_bb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/motion_robot_bb.pdf
Binary file not shown.
Binary file modified docs/images/motion_robot_bb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/motion_sensor_bb.pdf
Binary file not shown.
Binary file modified docs/images/motion_sensor_bb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/motor_bb.pdf
Binary file not shown.
Binary file modified docs/images/motor_bb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/music_box_bb.pdf
Binary file not shown.
Binary file modified docs/images/music_box_bb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/output_device_hierarchy.pdf
Binary file not shown.
Binary file modified docs/images/output_device_hierarchy.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit be7f898

Please sign in to comment.