Skip to content

Commit 80ff2d7

Browse files
committed
Merge pull request gpiozero#333 from lurch/add_ledborg
Add LedBorg as a subclass of RGBLED
2 parents af84ed1 + 3a7acbf commit 80ff2d7

File tree

8 files changed

+75
-14
lines changed

8 files changed

+75
-14
lines changed

docs/api_boards.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ TrafficLights
3636
:inherited-members:
3737
:members:
3838

39+
LedBorg
40+
=======
41+
42+
.. autoclass:: LedBorg
43+
:inherited-members:
44+
:members:
45+
3946
PiLITEr
4047
=======
4148

docs/images/output_device_hierarchy.dot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ digraph classes {
2121
PWMOutputDevice->OutputDevice;
2222
PWMLED->PWMOutputDevice;
2323
RGBLED->Device;
24+
LedBorg->RGBLED;
2425
}
2526

349 Bytes
Binary file not shown.
1.33 KB
Loading

docs/images/output_device_hierarchy.svg

Lines changed: 22 additions & 12 deletions
Loading

gpiozero/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
LEDCollection,
107107
LEDBoard,
108108
LEDBarGraph,
109+
LedBorg,
109110
PiLiter,
110111
PiLiterBarGraph,
111112
TrafficLights,

gpiozero/boards.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@
2121
OutputDeviceBadValue,
2222
)
2323
from .input_devices import Button
24-
from .output_devices import OutputDevice, LED, PWMLED, Buzzer, Motor
24+
from .output_devices import (
25+
OutputDevice,
26+
LED,
27+
PWMLED,
28+
RGBLED,
29+
Buzzer,
30+
Motor,
31+
)
2532
from .threads import GPIOThread
2633
from .devices import Device, CompositeDevice
2734
from .mixins import SharedMixin, SourceMixin
@@ -431,6 +438,36 @@ def value(self, value):
431438
led.value = calc_value(index)
432439

433440

441+
class LedBorg(RGBLED):
442+
"""
443+
Extends :class:`RGBLED` for the `PiBorg LedBorg`_: an add-on board
444+
containing a very bright RGB LED.
445+
446+
The LedBorg pins are fixed and therefore there's no need to specify them
447+
when constructing this class. The following example turns the LedBorg
448+
purple::
449+
450+
from gpiozero import LedBorg
451+
452+
led = LedBorg()
453+
led.color = (1, 0, 1)
454+
455+
:param tuple initial_value:
456+
The initial color for the LedBorg. Defaults to black ``(0, 0, 0)``.
457+
458+
:param bool pwm:
459+
If ``True`` (the default), construct :class:`PWMLED` instances for
460+
each component of the LedBorg. If ``False``, construct regular
461+
:class:`LED` instances, which prevents smooth color graduations.
462+
463+
.. _PiBorg LedBorg: https://www.piborg.org/ledborg
464+
"""
465+
466+
def __init__(self, initial_value=(0, 0, 0), pwm=True):
467+
super(LedBorg, self).__init__(red=17, green=27, blue=22,
468+
initial_value=initial_value, pwm=pwm)
469+
470+
434471
class PiLiter(LEDBoard):
435472
"""
436473
Extends :class:`LEDBoard` for the `Ciseco Pi-LITEr`_: a strip of 8 very bright

tests/test_boards.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
def setup_function(function):
1919
import gpiozero.devices
2020
# dirty, but it does the job
21-
if function.__name__ in ('test_robot', 'test_ryanteck_robot', 'test_camjam_kit_robot'):
21+
if function.__name__ in ('test_robot', 'test_ryanteck_robot', 'test_camjam_kit_robot', 'test_led_borg'):
2222
gpiozero.devices.pin_factory = MockPWMPin
2323
else:
2424
gpiozero.devices.pin_factory = MockPin
@@ -524,6 +524,11 @@ def test_led_bar_graph_pwm_initial_value():
524524
assert graph.value == -0.5
525525
assert (pin1.state, pin2.state, pin3.state) == (0, 0.5, 1)
526526

527+
def test_led_borg():
528+
pins = [MockPWMPin(n) for n in (17, 27, 22)]
529+
with LedBorg() as board:
530+
assert [device.pin for device in board._leds] == pins
531+
527532
def test_pi_liter():
528533
pins = [MockPin(n) for n in (4, 17, 27, 18, 22, 23, 24, 25)]
529534
with PiLiter() as board:

0 commit comments

Comments
 (0)