Led Module
This module help you to manage single rgb led (internal or external).
Examples:
>>> from pybox.led import LED
>>> from pybox.color import *
# drive internal led
>>> led = LED()
>>> led.color = BLUE
# turn on the led
>>> led.on()
# turn off the led
>>> led.off()
The user basically should use only the LED
class inside it.
Classes
LED
Led class.
Parameters:
-
target
(str
, default:'internal'
) –led to drive, 'internal', 'external' or a board string (i.e. board.GP18).
-
color
(tuple[int]
, default:RED
) –color in (r, g, b) format.
-
brightness
(float
, default:0.25
) –value between 0.0 and 1.0.
Examples:
>>> led = LED('external')
>>> led.color = BLUE
>>> led.on()
Source code in pybox/led.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
Attributes
color
property
writable
Get or set the color.
Examples:
>>> led.color = GREEN
>>> led.on()
Returns:
-
tuple
–color in tuple format
brightness: float
property
writable
Get or set the brightness
Examples:
>>> # fade in brightness starting from 0 to 1
>>> import time
>>> led.on()
>>> led.brightness = 0
>>> for i in range(101):
>>> led.brightness = i / 100
>>> time.sleep(0.01)
Returns:
-
float
–brightness value as a float between 0.0 and 1.0
Functions
write(value: int, color: tuple = None) -> None
Write digital value on led.
Examples:
>>> # turn on the led with color RED
>>> led.write(1, RED)
>>> # turn off the led
>>> led.write(0)
Parameters:
-
value
(int
) –value to write: 1 to turn on the led, 0 otherwise
-
color
(tuple
, default:None
) –color in tuple (r, g, b) format
Source code in pybox/led.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
on()
turn on the led
Source code in pybox/led.py
81 82 83 84 |
|
off()
turn off the led
Source code in pybox/led.py
86 87 88 89 |
|
toggle()
switch between on and off on the led.
Examples:
>>> led.on()
>>> # turn off the led
>>> led.toggle()
>>> # turn on
>>> led.toggle()
Source code in pybox/led.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
deinit()
deinitialize led.
Source code in pybox/led.py
107 108 109 110 |
|