mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
Add LedBorg as a subclass of RGBLED
This commit is contained in:
committed by
Andrew Scheller
parent
9278a2f857
commit
3a7acbf89d
@@ -36,6 +36,13 @@ TrafficLights
|
||||
:inherited-members:
|
||||
:members:
|
||||
|
||||
LedBorg
|
||||
=======
|
||||
|
||||
.. autoclass:: LedBorg
|
||||
:inherited-members:
|
||||
:members:
|
||||
|
||||
PiLITEr
|
||||
=======
|
||||
|
||||
|
||||
@@ -21,5 +21,6 @@ digraph classes {
|
||||
PWMOutputDevice->OutputDevice;
|
||||
PWMLED->PWMOutputDevice;
|
||||
RGBLED->Device;
|
||||
LedBorg->RGBLED;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 22 KiB |
@@ -11,18 +11,18 @@
|
||||
<polygon fill="white" stroke="none" points="-4,4 -4,-328 255,-328 255,4 -4,4"/>
|
||||
<!-- Device -->
|
||||
<g id="node1" class="node"><title>Device</title>
|
||||
<polygon fill="#9ec6e0" stroke="#9ec6e0" points="204,-324 150,-324 150,-288 204,-288 204,-324"/>
|
||||
<text text-anchor="middle" x="177" y="-303.5" font-family="Sans" font-size="10.00" fill="#000000">Device</text>
|
||||
<polygon fill="#9ec6e0" stroke="#9ec6e0" points="206,-324 152,-324 152,-288 206,-288 206,-324"/>
|
||||
<text text-anchor="middle" x="179" y="-303.5" font-family="Sans" font-size="10.00" fill="#000000">Device</text>
|
||||
</g>
|
||||
<!-- GPIODevice -->
|
||||
<g id="node2" class="node"><title>GPIODevice</title>
|
||||
<polygon fill="#9ec6e0" stroke="#9ec6e0" points="172,-252 100,-252 100,-216 172,-216 172,-252"/>
|
||||
<text text-anchor="middle" x="136" y="-231.5" font-family="Sans" font-size="10.00" fill="#000000">GPIODevice</text>
|
||||
<polygon fill="#9ec6e0" stroke="#9ec6e0" points="173,-252 101,-252 101,-216 173,-216 173,-252"/>
|
||||
<text text-anchor="middle" x="137" y="-231.5" font-family="Sans" font-size="10.00" fill="#000000">GPIODevice</text>
|
||||
</g>
|
||||
<!-- GPIODevice->Device -->
|
||||
<g id="edge1" class="edge"><title>GPIODevice->Device</title>
|
||||
<path fill="none" stroke="black" d="M146.135,-252.303C150.852,-260.356 156.562,-270.106 161.782,-279.018"/>
|
||||
<polygon fill="black" stroke="black" points="158.908,-281.036 166.982,-287.896 164.948,-277.498 158.908,-281.036"/>
|
||||
<path fill="none" stroke="black" d="M147.382,-252.303C152.265,-260.441 158.187,-270.311 163.579,-279.299"/>
|
||||
<polygon fill="black" stroke="black" points="160.591,-281.121 168.737,-287.896 166.594,-277.52 160.591,-281.121"/>
|
||||
</g>
|
||||
<!-- OutputDevice -->
|
||||
<g id="node3" class="node"><title>OutputDevice</title>
|
||||
@@ -31,8 +31,8 @@
|
||||
</g>
|
||||
<!-- OutputDevice->GPIODevice -->
|
||||
<g id="edge2" class="edge"><title>OutputDevice->GPIODevice</title>
|
||||
<path fill="none" stroke="black" d="M136,-180.303C136,-188.017 136,-197.288 136,-205.888"/>
|
||||
<polygon fill="black" stroke="black" points="132.5,-205.896 136,-215.896 139.5,-205.896 132.5,-205.896"/>
|
||||
<path fill="none" stroke="black" d="M136.247,-180.303C136.357,-188.017 136.49,-197.288 136.613,-205.888"/>
|
||||
<polygon fill="black" stroke="black" points="133.113,-205.947 136.756,-215.896 140.112,-205.847 133.113,-205.947"/>
|
||||
</g>
|
||||
<!-- DigitalOutputDevice -->
|
||||
<g id="node4" class="node"><title>DigitalOutputDevice</title>
|
||||
@@ -86,13 +86,23 @@
|
||||
</g>
|
||||
<!-- RGBLED -->
|
||||
<g id="node9" class="node"><title>RGBLED</title>
|
||||
<polygon fill="#2980b9" stroke="#2980b9" points="246,-252 190,-252 190,-216 246,-216 246,-252"/>
|
||||
<text text-anchor="middle" x="218" y="-231.5" font-family="Sans" font-size="10.00" fill="#ffffff">RGBLED</text>
|
||||
<polygon fill="#2980b9" stroke="#2980b9" points="249,-252 193,-252 193,-216 249,-216 249,-252"/>
|
||||
<text text-anchor="middle" x="221" y="-231.5" font-family="Sans" font-size="10.00" fill="#ffffff">RGBLED</text>
|
||||
</g>
|
||||
<!-- RGBLED->Device -->
|
||||
<g id="edge8" class="edge"><title>RGBLED->Device</title>
|
||||
<path fill="none" stroke="black" d="M207.865,-252.303C203.148,-260.356 197.438,-270.106 192.218,-279.018"/>
|
||||
<polygon fill="black" stroke="black" points="189.052,-277.498 187.018,-287.896 195.092,-281.036 189.052,-277.498"/>
|
||||
<path fill="none" stroke="black" d="M210.618,-252.303C205.735,-260.441 199.813,-270.311 194.421,-279.299"/>
|
||||
<polygon fill="black" stroke="black" points="191.406,-277.52 189.263,-287.896 197.409,-281.121 191.406,-277.52"/>
|
||||
</g>
|
||||
<!-- LedBorg -->
|
||||
<g id="node10" class="node"><title>LedBorg</title>
|
||||
<polygon fill="#2980b9" stroke="#2980b9" points="251,-180 195,-180 195,-144 251,-144 251,-180"/>
|
||||
<text text-anchor="middle" x="223" y="-159.5" font-family="Sans" font-size="10.00" fill="#ffffff">LedBorg</text>
|
||||
</g>
|
||||
<!-- LedBorg->RGBLED -->
|
||||
<g id="edge9" class="edge"><title>LedBorg->RGBLED</title>
|
||||
<path fill="none" stroke="black" d="M222.506,-180.303C222.285,-188.017 222.02,-197.288 221.775,-205.888"/>
|
||||
<polygon fill="black" stroke="black" points="218.276,-205.8 221.489,-215.896 225.273,-206 218.276,-205.8"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 6.3 KiB |
@@ -106,6 +106,7 @@ from .boards import (
|
||||
LEDCollection,
|
||||
LEDBoard,
|
||||
LEDBarGraph,
|
||||
LedBorg,
|
||||
PiLiter,
|
||||
PiLiterBarGraph,
|
||||
TrafficLights,
|
||||
|
||||
@@ -21,7 +21,14 @@ from .exc import (
|
||||
OutputDeviceBadValue,
|
||||
)
|
||||
from .input_devices import Button
|
||||
from .output_devices import OutputDevice, LED, PWMLED, Buzzer, Motor
|
||||
from .output_devices import (
|
||||
OutputDevice,
|
||||
LED,
|
||||
PWMLED,
|
||||
RGBLED,
|
||||
Buzzer,
|
||||
Motor,
|
||||
)
|
||||
from .threads import GPIOThread
|
||||
from .devices import Device, CompositeDevice
|
||||
from .mixins import SharedMixin, SourceMixin
|
||||
@@ -431,6 +438,36 @@ class LEDBarGraph(LEDCollection):
|
||||
led.value = calc_value(index)
|
||||
|
||||
|
||||
class LedBorg(RGBLED):
|
||||
"""
|
||||
Extends :class:`RGBLED` for the `PiBorg LedBorg`_: an add-on board
|
||||
containing a very bright RGB LED.
|
||||
|
||||
The LedBorg pins are fixed and therefore there's no need to specify them
|
||||
when constructing this class. The following example turns the LedBorg
|
||||
purple::
|
||||
|
||||
from gpiozero import LedBorg
|
||||
|
||||
led = LedBorg()
|
||||
led.color = (1, 0, 1)
|
||||
|
||||
:param tuple initial_value:
|
||||
The initial color for the LedBorg. Defaults to black ``(0, 0, 0)``.
|
||||
|
||||
:param bool pwm:
|
||||
If ``True`` (the default), construct :class:`PWMLED` instances for
|
||||
each component of the LedBorg. If ``False``, construct regular
|
||||
:class:`LED` instances, which prevents smooth color graduations.
|
||||
|
||||
.. _PiBorg LedBorg: https://www.piborg.org/ledborg
|
||||
"""
|
||||
|
||||
def __init__(self, initial_value=(0, 0, 0), pwm=True):
|
||||
super(LedBorg, self).__init__(red=17, green=27, blue=22,
|
||||
initial_value=initial_value, pwm=pwm)
|
||||
|
||||
|
||||
class PiLiter(LEDBoard):
|
||||
"""
|
||||
Extends :class:`LEDBoard` for the `Ciseco Pi-LITEr`_: a strip of 8 very bright
|
||||
|
||||
@@ -18,7 +18,7 @@ from gpiozero import *
|
||||
def setup_function(function):
|
||||
import gpiozero.devices
|
||||
# dirty, but it does the job
|
||||
if function.__name__ in ('test_robot', 'test_ryanteck_robot', 'test_camjam_kit_robot'):
|
||||
if function.__name__ in ('test_robot', 'test_ryanteck_robot', 'test_camjam_kit_robot', 'test_led_borg'):
|
||||
gpiozero.devices.pin_factory = MockPWMPin
|
||||
else:
|
||||
gpiozero.devices.pin_factory = MockPin
|
||||
@@ -524,6 +524,11 @@ def test_led_bar_graph_pwm_initial_value():
|
||||
assert graph.value == -0.5
|
||||
assert (pin1.state, pin2.state, pin3.state) == (0, 0.5, 1)
|
||||
|
||||
def test_led_borg():
|
||||
pins = [MockPWMPin(n) for n in (17, 27, 22)]
|
||||
with LedBorg() as board:
|
||||
assert [device.pin for device in board._leds] == pins
|
||||
|
||||
def test_pi_liter():
|
||||
pins = [MockPin(n) for n in (4, 17, 27, 18, 22, 23, 24, 25)]
|
||||
with PiLiter() as board:
|
||||
|
||||
Reference in New Issue
Block a user