|
| 1 | +.. currentmodule:: m5ui |
| 2 | + |
| 3 | +M5LED |
| 4 | +===== |
| 5 | + |
| 6 | +.. include:: ../refs/m5ui.led.ref |
| 7 | + |
| 8 | +M5LED is a lightweight widget that simulates a light-emitting diode indicator in the user interface. |
| 9 | + |
| 10 | +UiFlow2 Example |
| 11 | +--------------- |
| 12 | + |
| 13 | +LED Basic Usage Example |
| 14 | +^^^^^^^^^^^^^^^^^^^^^^^ |
| 15 | + |
| 16 | +Open the |m5cores3_m5ui_led_example.m5f2| project in UiFlow2. |
| 17 | + |
| 18 | +This example demonstrates how to create and control an LED widget. |
| 19 | +It shows how to turn the LED on and off, change its color, adjust brightness. |
| 20 | + |
| 21 | +UiFlow2 Code Block: |
| 22 | + |
| 23 | + |m5cores3_m5ui_led_example.png| |
| 24 | + |
| 25 | +Example output: |
| 26 | + |
| 27 | + None. |
| 28 | + |
| 29 | +MicroPython Example |
| 30 | +------------------- |
| 31 | + |
| 32 | +LED Basic Usage Example |
| 33 | +^^^^^^^^^^^^^^^^^^^^^^^ |
| 34 | + |
| 35 | +This example demonstrates how to create and control an LED widget. |
| 36 | +It shows how to turn the LED on and off, change its color, adjust brightness. |
| 37 | + |
| 38 | +MicroPython Code Block: |
| 39 | + |
| 40 | + .. literalinclude:: ../../../examples/m5ui/led/m5cores3_m5ui_led_example.py |
| 41 | + :language: python |
| 42 | + :linenos: |
| 43 | + |
| 44 | +Example output: |
| 45 | + |
| 46 | + None. |
| 47 | + |
| 48 | +**API** |
| 49 | +------- |
| 50 | + |
| 51 | +M5LED |
| 52 | +^^^^^ |
| 53 | + |
| 54 | +.. autoclass:: m5ui.led.M5LED |
| 55 | + :members: |
| 56 | + |
| 57 | + .. py:method:: on() |
| 58 | +
|
| 59 | + Turn on the LED. |
| 60 | + |
| 61 | + :return: None |
| 62 | + |
| 63 | + UiFlow2 Code Block: |
| 64 | + |
| 65 | + |on.png| |
| 66 | + |
| 67 | + MicroPython Code Block: |
| 68 | + |
| 69 | + .. code-block:: python |
| 70 | +
|
| 71 | + led_0.on() |
| 72 | +
|
| 73 | + .. py:method:: off() |
| 74 | +
|
| 75 | + Turn off the LED. |
| 76 | + |
| 77 | + :return: None |
| 78 | + |
| 79 | + UiFlow2 Code Block: |
| 80 | + |
| 81 | + |set_state.png| |
| 82 | + |
| 83 | + MicroPython Code Block: |
| 84 | + |
| 85 | + .. code-block:: python |
| 86 | +
|
| 87 | + led_0.off() |
| 88 | +
|
| 89 | + .. py:method:: toggle() |
| 90 | +
|
| 91 | + Toggle the state of a LED. |
| 92 | + |
| 93 | + :return: None |
| 94 | + |
| 95 | + UiFlow2 Code Block: |
| 96 | + |
| 97 | + |toggle.png| |
| 98 | + |
| 99 | + MicroPython Code Block: |
| 100 | + |
| 101 | + .. code-block:: python |
| 102 | +
|
| 103 | + led_0.toggle() |
| 104 | +
|
| 105 | + .. py:method:: set_color(color) |
| 106 | +
|
| 107 | + Set the color of the LED. |
| 108 | + |
| 109 | + :param int color: The color of the LED (RGB888 format). |
| 110 | + :return: None |
| 111 | + |
| 112 | + UiFlow2 Code Block: |
| 113 | + |
| 114 | + |set_color.png| |
| 115 | + |
| 116 | + MicroPython Code Block: |
| 117 | + |
| 118 | + .. code-block:: python |
| 119 | +
|
| 120 | + led_0.set_color(color) |
| 121 | +
|
| 122 | + .. py:method:: set_brightness(brightness) |
| 123 | +
|
| 124 | + Set the brightness of the LED. |
| 125 | + |
| 126 | + :param int brightness: Brightness value, range: 80 ~ 255 (80 = dark, 255 = light). |
| 127 | + :return: None |
| 128 | + |
| 129 | + UiFlow2 Code Block: |
| 130 | + |
| 131 | + |set_brightness.png| |
| 132 | + |
| 133 | + MicroPython Code Block: |
| 134 | + |
| 135 | + .. code-block:: python |
| 136 | +
|
| 137 | + led_0.set_brightness(brightness) |
| 138 | +
|
| 139 | + .. py:method:: get_brightness() |
| 140 | +
|
| 141 | + Get the brightness of the LED. |
| 142 | + |
| 143 | + :return: The brightness value of the LED. |
| 144 | + :rtype: int |
| 145 | + |
| 146 | + UiFlow2 Code Block: |
| 147 | + |
| 148 | + |get_brightness.png| |
| 149 | + |
| 150 | + MicroPython Code Block: |
| 151 | + |
| 152 | + .. code-block:: python |
| 153 | +
|
| 154 | + brightness = led_0.get_brightness() |
| 155 | +
|
| 156 | + .. py:method:: set_pos(x, y) |
| 157 | +
|
| 158 | + Set the position of the LED. |
| 159 | + |
| 160 | + :param int x: The x position of the LED. |
| 161 | + :param int y: The y position of the LED. |
| 162 | + :return: None |
| 163 | + |
| 164 | + UiFlow2 Code Block: |
| 165 | + |
| 166 | + |set_pos.png| |
| 167 | + |
| 168 | + MicroPython Code Block: |
| 169 | + |
| 170 | + .. code-block:: python |
| 171 | +
|
| 172 | + led_0.set_pos(x, y) |
| 173 | +
|
| 174 | + .. py:method:: set_x(x) |
| 175 | +
|
| 176 | + Set the x position of the LED. |
| 177 | + |
| 178 | + :param int x: The x position of the LED. |
| 179 | + :return: None |
| 180 | + |
| 181 | + UiFlow2 Code Block: |
| 182 | + |
| 183 | + |set_x.png| |
| 184 | + |
| 185 | + MicroPython Code Block: |
| 186 | + |
| 187 | + .. code-block:: python |
| 188 | +
|
| 189 | + led_0.set_x(x) |
| 190 | +
|
| 191 | + .. py:method:: set_y(y) |
| 192 | +
|
| 193 | + Set the y position of the LED. |
| 194 | + |
| 195 | + :param int y: The y position of the LED. |
| 196 | + :return: None |
| 197 | + |
| 198 | + UiFlow2 Code Block: |
| 199 | + |
| 200 | + |set_y.png| |
| 201 | + |
| 202 | + MicroPython Code Block: |
| 203 | + |
| 204 | + .. code-block:: python |
| 205 | +
|
| 206 | + led_0.set_y(y) |
| 207 | +
|
| 208 | + .. py:method:: get_x() |
| 209 | +
|
| 210 | + Get the x position of the LED. |
| 211 | + |
| 212 | + :return: The x position of the LED. |
| 213 | + :rtype: int |
| 214 | + |
| 215 | + UiFlow2 Code Block: |
| 216 | + |
| 217 | + |get_x.png| |
| 218 | + |
| 219 | + MicroPython Code Block: |
| 220 | + |
| 221 | + .. code-block:: python |
| 222 | +
|
| 223 | + x = led_0.get_x() |
| 224 | +
|
| 225 | + .. py:method:: get_y() |
| 226 | +
|
| 227 | + Get the y position of the LED. |
| 228 | + |
| 229 | + :return: The y position of the LED. |
| 230 | + :rtype: int |
| 231 | + |
| 232 | + UiFlow2 Code Block: |
| 233 | + |
| 234 | + |get_y.png| |
| 235 | + |
| 236 | + MicroPython Code Block: |
| 237 | + |
| 238 | + .. code-block:: python |
| 239 | +
|
| 240 | + y = led_0.get_y() |
| 241 | +
|
| 242 | + .. py:method:: set_size(width, height) |
| 243 | +
|
| 244 | + Set the size of the LED. |
| 245 | + |
| 246 | + :param int width: The width of the LED. |
| 247 | + :param int height: The height of the LED. |
| 248 | + :return: None |
| 249 | + |
| 250 | + UiFlow2 Code Block: |
| 251 | + |
| 252 | + |set_size.png| |
| 253 | + |
| 254 | + MicroPython Code Block: |
| 255 | + |
| 256 | + .. code-block:: python |
| 257 | +
|
| 258 | + led_0.set_size(width, height) |
| 259 | +
|
| 260 | + .. py:method:: set_width(width) |
| 261 | +
|
| 262 | + Set the width of the LED. |
| 263 | + |
| 264 | + :param int width: The width of the LED. |
| 265 | + :return: None |
| 266 | + |
| 267 | + UiFlow2 Code Block: |
| 268 | + |
| 269 | + |set_width.png| |
| 270 | + |
| 271 | + MicroPython Code Block: |
| 272 | + |
| 273 | + .. code-block:: python |
| 274 | +
|
| 275 | + led_0.set_width(width) |
| 276 | +
|
| 277 | + .. py:method:: set_height(height) |
| 278 | +
|
| 279 | + Set the height of the LED. |
| 280 | + |
| 281 | + :param int height: The height of the LED. |
| 282 | + :return: None |
| 283 | + |
| 284 | + UiFlow2 Code Block: |
| 285 | + |
| 286 | + |set_height.png| |
| 287 | + |
| 288 | + MicroPython Code Block: |
| 289 | + |
| 290 | + .. code-block:: python |
| 291 | +
|
| 292 | + led_0.set_height(height) |
| 293 | +
|
| 294 | + .. py:method:: align_to(obj, align, x, y) |
| 295 | +
|
| 296 | + Align the LED relative to another object. |
| 297 | + |
| 298 | + :param obj: The reference object (e.g. page0). |
| 299 | + :param int align: Alignment option (see lv.ALIGN constants below). |
| 300 | + :param int x: X offset after alignment. |
| 301 | + :param int y: Y offset after alignment. |
| 302 | + :return: None |
| 303 | + |
| 304 | + UiFlow2 Code Block: |
| 305 | + |
| 306 | + |align_to.png| |
| 307 | + |
| 308 | + MicroPython Code Block: |
| 309 | + |
| 310 | + .. code-block:: python |
| 311 | +
|
| 312 | + led_0.align_to(page0, lv.ALIGN.CENTER, 0, 0) |
| 313 | +
|
| 314 | + .. py:data:: lv.ALIGN |
| 315 | +
|
| 316 | + Alignment options for positioning objects. |
| 317 | + |
| 318 | + - lv.ALIGN.DEFAULT |
| 319 | + - lv.ALIGN.TOP_LEFT |
| 320 | + - lv.ALIGN.TOP_MID |
| 321 | + - lv.ALIGN.TOP_RIGHT |
| 322 | + - lv.ALIGN.BOTTOM_LEFT |
| 323 | + - lv.ALIGN.BOTTOM_MID |
| 324 | + - lv.ALIGN.BOTTOM_RIGHT |
| 325 | + - lv.ALIGN.LEFT_MID |
| 326 | + - lv.ALIGN.RIGHT_MID |
| 327 | + - lv.ALIGN.CENTER |
| 328 | + - lv.ALIGN.OUT_TOP_LEFT |
| 329 | + - lv.ALIGN.OUT_TOP_MID |
| 330 | + - lv.ALIGN.OUT_TOP_RIGHT |
| 331 | + - lv.ALIGN.OUT_BOTTOM_LEFT |
| 332 | + - lv.ALIGN.OUT_BOTTOM_MID |
| 333 | + - lv.ALIGN.OUT_BOTTOM_RIGHT |
| 334 | + - lv.ALIGN.OUT_LEFT_TOP |
| 335 | + - lv.ALIGN.OUT_LEFT_MID |
| 336 | + - lv.ALIGN.OUT_LEFT_BOTTOM |
| 337 | + - lv.ALIGN.OUT_RIGHT_TOP |
| 338 | + - lv.ALIGN.OUT_RIGHT_MID |
| 339 | + - lv.ALIGN.OUT_RIGHT_BOTTOM |
0 commit comments