Skip to content

Commit

Permalink
Merge pull request #177 from waveform80/misc-11
Browse files Browse the repository at this point in the history
Miscellaneous minor changes for 1.1
  • Loading branch information
waveform80 committed Feb 8, 2016
2 parents 0c2f750 + 006c10c commit c7ee499
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ release: $(PY_SOURCES) $(DOC_SOURCES) $(DEB_SOURCES)
dch --newversion $(VER)$(DEB_SUFFIX) --controlmaint
# commit the changes and add a new tag
git commit debian/changelog -m "Updated changelog for release $(VER)"
git tag -s release-$(VER) -m "Release $(VER)"
git tag -s v$(VER) -m "Release v$(VER)"
# update the package's registration on PyPI (in case any metadata's changed)
$(PYTHON) $(PYFLAGS) setup.py register

Expand Down
2 changes: 1 addition & 1 deletion docs/api_output.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ RGBLED
======

.. autoclass:: RGBLED(red, green, blue, active_high=True)
:members: on, off, blink, red, green, blue, value
:members: on, off, toggle, blink, red, green, blue, color

Motor
=====
Expand Down
31 changes: 23 additions & 8 deletions gpiozero/output_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,17 +520,22 @@ class RGBLED(SourceMixin, CompositeDevice):
The GPIO pin that controls the blue component of the RGB LED.
:param bool active_high:
If ``True`` (the default), the :meth:`on` method will set the GPIOs to
HIGH. If ``False``, the :meth:`on` method will set the GPIOs to LOW
(the :meth:`off` method always does the opposite).
Set to ``True`` (the default) for common cathode RGB LEDs. If you are
using a common anode RGB LED, set this to ``False``.
:param bool initial_value:
The initial color for the LED. Defaults to black ``(0, 0, 0)``.
"""
def __init__(self, red=None, green=None, blue=None, active_high=True):
def __init__(
self, red=None, green=None, blue=None, active_high=True,
initial_value=(0, 0, 0)):
self._leds = ()
self._blink_thread = None
if not all([red, green, blue]):
raise OutputDeviceError('red, green, and blue pins must be provided')
super(RGBLED, self).__init__()
self._leds = tuple(PWMLED(pin, active_high) for pin in (red, green, blue))
self.value = initial_value

red = _led_property(0)
green = _led_property(1)
Expand Down Expand Up @@ -563,18 +568,28 @@ def is_active(self):

def on(self):
"""
Turn the device on. This equivalent to setting the device color to
white ``(1, 1, 1)``.
Turn the LED on. This equivalent to setting the LED color to white
``(1, 1, 1)``.
"""
self.value = (1, 1, 1)

def off(self):
"""
Turn the device off. This is equivalent to setting the device color
to black ``(0, 0, 0)``.
Turn the LED off. This is equivalent to setting the LED color to black
``(0, 0, 0)``.
"""
self.value = (0, 0, 0)

def toggle(self):
"""
Toggle the state of the device. If the device is currently off
(:attr:`value` is ``(0, 0, 0)``), this changes it to "fully" on
(:attr:`value` is ``(1, 1, 1)``). If the device has a specific color,
this method inverts the color.
"""
r, g, b = self.value
self.value = (1 - r, 1 - g, 1 - b)

def close(self):
self._stop_blink()
for led in self._leds:
Expand Down

0 comments on commit c7ee499

Please sign in to comment.