Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self._value = value
def on(self):
"""
Turns the socket on.
"""
self.value = True
def off(self):
"""
Turns the socket off.
"""
self.value = False
class PumpkinPi(LEDBoard):
"""
Extends :class:`LEDBoard` for the `ModMyPi PumpkinPi`_ board.
There are twelve LEDs connected up to individual pins, so for the PumpkinPi
the pins are fixed. For example::
from gpiozero import PumpkinPi
pumpkin = PumpkinPi(pwm=True)
pumpkin.sides.pulse()
pumpkin.off()
:param bool pwm:
If :data:`True`, construct :class:`PWMLED` instances to represent each
LED. If :data:`False` (the default), construct regular :class:`LED`
instances
raise ValueError("Duplicate label %s" % dup)
super(StatusBoard, self).__init__(
_order=labels, pin_factory=pin_factory, **{
label: CompositeOutputDevice(
button=Button(button, pin_factory=pin_factory),
lights=LEDBoard(
red=red, green=green, _order=('red', 'green'),
pin_factory=pin_factory, **kwargs
), _order=('button', 'lights'), pin_factory=pin_factory
)
for (green, red, button), label in zip(pins, labels)
}
)
class SnowPi(LEDBoard):
"""
Extends :class:`LEDBoard` for the `Ryanteck SnowPi`_ board.
The SnowPi pins are fixed and therefore there's no need to specify them
when constructing this class. The following example turns on the eyes, sets
the nose pulsing, and the arms blinking::
from gpiozero import SnowPi
snowman = SnowPi(pwm=True)
snowman.eyes.on()
snowman.nose.pulse()
snowman.arms.blink()
:param bool pwm:
If :data:`True`, construct :class:`PWMLED` instances to represent each
def __init__(self, pwm=False, initial_value=False, pin_factory=None):
super(PumpkinPi, self).__init__(
sides=LEDBoard(
left=LEDBoard(
bottom=18, midbottom=17, middle=16, midtop=13, top=24,
pwm=pwm, initial_value=initial_value,
_order=('bottom', 'midbottom', 'middle', 'midtop', 'top'),
pin_factory=pin_factory),
right=LEDBoard(
bottom=19, midbottom=20, middle=21, midtop=22, top=23,
pwm=pwm, initial_value=initial_value,
_order=('bottom', 'midbottom', 'middle', 'midtop', 'top'),
pin_factory=pin_factory),
pwm=pwm, initial_value=initial_value,
_order=('left', 'right'),
pin_factory=pin_factory
),
eyes=LEDBoard(
left=12, right=6,
def __init__(self, pwm=False, initial_value=False, pin_factory=None):
super(SnowPi, self).__init__(
arms=LEDBoard(
left=LEDBoard(
top=17, middle=18, bottom=22,
pwm=pwm, initial_value=initial_value,
_order=('top', 'middle', 'bottom'),
pin_factory=pin_factory),
right=LEDBoard(
top=7, middle=8, bottom=9,
pwm=pwm, initial_value=initial_value,
_order=('top', 'middle', 'bottom'),
pin_factory=pin_factory),
_order=('left', 'right'),
pin_factory=pin_factory
),
eyes=LEDBoard(
left=23, right=24,
pwm=pwm, initial_value=initial_value,
def __init__(self, pwm=False, pin_factory=None):
super(JamHat, self).__init__(
lights_1=LEDBoard(red=5, yellow=12, green=16,
pwm=pwm, _order=('red', 'yellow', 'green'),
pin_factory=pin_factory),
lights_2=LEDBoard(red=6, yellow=13, green=17,
pwm=pwm, _order=('red', 'yellow', 'green'),
pin_factory=pin_factory),
button_1=Button(19, pull_up=False, pin_factory=pin_factory),
button_2=Button(18, pull_up=False, pin_factory=pin_factory),
buzzer=TonalBuzzer(20, pin_factory=pin_factory),
_order=('lights_1', 'lights_2', 'button_1', 'button_2', 'buzzer'),
pin_factory=pin_factory
)
super(SnowPi, self).__init__(
arms=LEDBoard(
left=LEDBoard(
top=17, middle=18, bottom=22,
pwm=pwm, initial_value=initial_value,
_order=('top', 'middle', 'bottom'),
pin_factory=pin_factory),
right=LEDBoard(
top=7, middle=8, bottom=9,
pwm=pwm, initial_value=initial_value,
_order=('top', 'middle', 'bottom'),
pin_factory=pin_factory),
_order=('left', 'right'),
pin_factory=pin_factory
),
eyes=LEDBoard(
left=23, right=24,
pwm=pwm, initial_value=initial_value,
_order=('left', 'right'),
pin_factory=pin_factory
),
nose=25,
pwm=pwm, initial_value=initial_value,
_order=('eyes', 'nose', 'arms'),
pin_factory=pin_factory
)
:type pin_factory: Factory or None
:param pin_factory:
See :doc:`api_pins` for more information (this is an advanced feature
which most users can ignore).
.. _Ciseco Pi-LITEr: http://shop.ciseco.co.uk/pi-liter-8-led-strip-for-the-raspberry-pi/
"""
def __init__(self, pwm=False, initial_value=0.0, pin_factory=None):
pins = (4, 17, 27, 18, 22, 23, 24, 25)
super(PiLiterBarGraph, self).__init__(
*pins, pwm=pwm, initial_value=initial_value, pin_factory=pin_factory
)
class TrafficLights(LEDBoard):
"""
Extends :class:`LEDBoard` for devices containing red, yellow, and green
LEDs.
The following example initializes a device connected to GPIO pins 2, 3,
and 4, then lights the amber (yellow) LED attached to GPIO 3::
from gpiozero import TrafficLights
traffic = TrafficLights(2, 3, 4)
traffic.amber.on()
:type red: int or str
:param red:
The GPIO pin that the red LED is attached to. See :ref:`pin-numbering`
for valid pin numbers.
leds.on(1, 2) # turn on the middle LEDs (pins 3 and 4)
leds.off() # turn off all LEDs
leds.on() # turn on all LEDs
If :meth:`blink` is currently active, it will be stopped first.
:param int args:
The index(es) of the LED(s) to turn on. If no indexes are specified
turn on all LEDs.
"""
self._stop_blink()
if args:
for index in args:
self[index].on()
else:
super(LEDBoard, self).on()
:type pin_factory: Factory or None
:param pin_factory:
See :doc:`api_pins` for more information (this is an advanced feature
which most users can ignore).
.. _PiBorg LedBorg: https://www.piborg.org/ledborg
"""
def __init__(self, initial_value=(0, 0, 0), pwm=True, pin_factory=None):
super(LedBorg, self).__init__(red=17, green=27, blue=22,
pwm=pwm, initial_value=initial_value,
pin_factory=pin_factory)
class PiLiter(LEDBoard):
"""
Extends :class:`LEDBoard` for the `Ciseco Pi-LITEr`_: a strip of 8 very
bright LEDs.
The Pi-LITEr pins are fixed and therefore there's no need to specify them
when constructing this class. The following example turns on all the LEDs
of the Pi-LITEr::
from gpiozero import PiLiter
lite = PiLiter()
lite.on()
:param bool pwm:
If :data:`True`, construct :class:`PWMLED` instances for each pin. If
:data:`False` (the default), construct regular :class:`LED` instances.
"""
The number of LEDs on the bar graph actually lit up. Note that just
like :attr:`value`, this can be negative if the LEDs are lit from last
to first.
"""
lit_value = self.value * len(self)
if not isinstance(self[0], PWMLED):
lit_value = int(lit_value)
return lit_value
@lit_count.setter
def lit_count(self, value):
self.value = value / len(self)
class PiHutXmasTree(LEDBoard):
"""
Extends :class:`LEDBoard` for `The Pi Hut's Xmas board`_: a 3D Christmas
tree board with 24 red LEDs and a white LED as a star on top.
The 24 red LEDs can be accessed through the attributes led0, led1, led2,
and so on. The white star LED is accessed through the :attr:`star`
attribute. Alternatively, as with all descendents of :class:`LEDBoard`,
you can treat the instance as a sequence of LEDs (the first element is the
:attr:`star`).
The Xmas Tree board pins are fixed and therefore there's no need to specify
them when constructing this class. The following example turns all the LEDs
on one at a time::
from gpiozero import PiHutXmasTree
from time import sleep