|
8 | 8 |
|
9 | 9 | CircuitPython driver for the IS31FL3731 charlieplex IC.
|
10 | 10 |
|
| 11 | +Base library. |
11 | 12 |
|
12 |
| -* Author(s): Tony DiCola, Melissa LeBlanc-Williams |
| 13 | +* Author(s): Tony DiCola, Melissa LeBlanc-Williams, David Glaude |
13 | 14 |
|
14 | 15 | Implementation Notes
|
15 | 16 | --------------------
|
|
22 | 23 | * `Adafruit 15x7 CharliePlex LED Matrix Display FeatherWings
|
23 | 24 | <https://www.adafruit.com/product/2965>`_
|
24 | 25 |
|
25 |
| -* Pimoroni LED SHIM |
26 |
| - <https://shop.pimoroni.com/products/led-shim>_ |
| 26 | +* `Adafruit 16x8 CharliePlex LED Matrix Bonnets |
| 27 | + <https://www.adafruit.com/product/4127>`_ |
27 | 28 |
|
28 |
| -* Pimoroni Keybow 2040 |
29 |
| - <https://shop.pimoroni.com/products/keybow-2040>_ |
| 29 | +* `Pimoroni 17x7 Scroll pHAT HD |
| 30 | + <https://www.adafruit.com/product/3473>`_ |
| 31 | +
|
| 32 | +* `Pimoroni 28x3 (r,g,b) Led Shim |
| 33 | + <https://www.adafruit.com/product/3831>`_ |
| 34 | +
|
| 35 | +* `Pimoroni LED SHIM |
| 36 | + <https://shop.pimoroni.com/products/led-shim>`_ |
| 37 | +
|
| 38 | +* `Pimoroni Keybow 2040 |
| 39 | + <https://shop.pimoroni.com/products/keybow-2040>`_ |
| 40 | +
|
| 41 | +* `Pimoroni 11x7 LED Matrix Breakout |
| 42 | + <https://shop.pimoroni.com/products/11x7-led-matrix-breakout>`_ |
30 | 43 |
|
31 | 44 | **Software and Dependencies:**
|
32 | 45 |
|
33 |
| -* Adafruit CircuitPython firmware (2.2.0+) for the ESP8622 and M0-based boards: |
| 46 | +* Adafruit CircuitPython firmware for the supported boards: |
34 | 47 | https://github.com/adafruit/circuitpython/releases
|
| 48 | +
|
35 | 49 | """
|
36 | 50 |
|
37 | 51 | # imports
|
|
66 | 80 | _COLOR_OFFSET = const(0x24)
|
67 | 81 |
|
68 | 82 |
|
69 |
| -class Matrix: |
| 83 | +class IS31FL3731: |
70 | 84 | """
|
71 |
| - The Matrix class support the main function for driving the 16x9 matrix Display |
| 85 | + The IS31FL3731 is an abstract class contain the main function related to this chip. |
| 86 | + Each board needs to define width, height and pixel_addr. |
72 | 87 |
|
73 | 88 | :param ~adafruit_bus_device.i2c_device i2c_device: the connected i2c bus i2c_device
|
74 | 89 | :param address: the device address; defaults to 0x74
|
@@ -283,6 +298,7 @@ def fill(self, color=None, blink=None, frame=None):
|
283 | 298 | for col in range(18):
|
284 | 299 | self._register(frame, _BLINK_OFFSET + col, data)
|
285 | 300 |
|
| 301 | + # This function must be replaced for each board |
286 | 302 | @staticmethod
|
287 | 303 | def pixel_addr(x, y):
|
288 | 304 | """Calulate the offset into the device array for x,y pixel"""
|
@@ -348,192 +364,3 @@ def image(self, img, blink=None, frame=None):
|
348 | 364 | for x in range(self.width): # yes this double loop is slow,
|
349 | 365 | for y in range(self.height): # but these displays are small!
|
350 | 366 | self.pixel(x, y, pixels[(x, y)], blink=blink, frame=frame)
|
351 |
| - |
352 |
| - |
353 |
| -class CharlieWing(Matrix): |
354 |
| - """Supports the Charlieplexed feather wing""" |
355 |
| - |
356 |
| - width = 15 |
357 |
| - height = 7 |
358 |
| - |
359 |
| - @staticmethod |
360 |
| - def pixel_addr(x, y): |
361 |
| - """Calulate the offset into the device array for x,y pixel""" |
362 |
| - if x > 7: |
363 |
| - x = 15 - x |
364 |
| - y += 8 |
365 |
| - else: |
366 |
| - y = 7 - y |
367 |
| - return x * 16 + y |
368 |
| - |
369 |
| - |
370 |
| -class CharlieBonnet(Matrix): |
371 |
| - """Supports the Charlieplexed bonnet""" |
372 |
| - |
373 |
| - width = 16 |
374 |
| - height = 8 |
375 |
| - |
376 |
| - @staticmethod |
377 |
| - def pixel_addr(x, y): |
378 |
| - """Calulate the offset into the device array for x,y pixel""" |
379 |
| - if x >= 8: |
380 |
| - return (x - 6) * 16 - (y + 1) |
381 |
| - return (x + 1) * 16 + (7 - y) |
382 |
| - |
383 |
| - |
384 |
| -class ScrollPhatHD(Matrix): |
385 |
| - """Supports the Scroll pHAT HD by Pimoroni""" |
386 |
| - |
387 |
| - width = 17 |
388 |
| - height = 7 |
389 |
| - |
390 |
| - @staticmethod |
391 |
| - def pixel_addr(x, y): |
392 |
| - """Translate an x,y coordinate to a pixel index.""" |
393 |
| - if x <= 8: |
394 |
| - x = 8 - x |
395 |
| - y = 6 - y |
396 |
| - else: |
397 |
| - x = x - 8 |
398 |
| - y = y - 8 |
399 |
| - return x * 16 + y |
400 |
| - |
401 |
| - |
402 |
| -class LedShim(Matrix): |
403 |
| - """Supports the LED SHIM by Pimoroni""" |
404 |
| - |
405 |
| - width = 28 |
406 |
| - height = 3 |
407 |
| - |
408 |
| - def __init__(self, i2c, address=0x75): |
409 |
| - super().__init__(i2c, address) |
410 |
| - |
411 |
| - # pylint: disable-msg=too-many-arguments |
412 |
| - def pixelrgb(self, x, r, g, b, blink=None, frame=None): |
413 |
| - """ |
414 |
| - Blink or brightness for x-pixel |
415 |
| -
|
416 |
| - :param x: horizontal pixel position |
417 |
| - :param r: red brightness value 0->255 |
418 |
| - :param g: green brightness value 0->255 |
419 |
| - :param b: blue brightness value 0->255 |
420 |
| - :param blink: True to blink |
421 |
| - :param frame: the frame to set the pixel |
422 |
| - """ |
423 |
| - super().pixel(x, 0, r, blink, frame) |
424 |
| - super().pixel(x, 1, g, blink, frame) |
425 |
| - super().pixel(x, 2, b, blink, frame) |
426 |
| - |
427 |
| - # pylint: disable=inconsistent-return-statements |
428 |
| - # pylint: disable=too-many-return-statements |
429 |
| - # pylint: disable=too-many-branches |
430 |
| - |
431 |
| - @staticmethod |
432 |
| - def pixel_addr(x, y): |
433 |
| - """Translate an x,y coordinate to a pixel index.""" |
434 |
| - if y == 0: |
435 |
| - if x < 7: |
436 |
| - return 118 - x |
437 |
| - if x < 15: |
438 |
| - return 141 - x |
439 |
| - if x < 21: |
440 |
| - return 106 + x |
441 |
| - if x == 21: |
442 |
| - return 15 |
443 |
| - return x - 14 |
444 |
| - |
445 |
| - if y == 1: |
446 |
| - if x < 2: |
447 |
| - return 69 - x |
448 |
| - if x < 7: |
449 |
| - return 86 - x |
450 |
| - if x < 12: |
451 |
| - return 28 - x |
452 |
| - if x < 14: |
453 |
| - return 45 - x |
454 |
| - if x == 14: |
455 |
| - return 47 |
456 |
| - if x == 15: |
457 |
| - return 41 |
458 |
| - if x < 21: |
459 |
| - return x + 9 |
460 |
| - if x == 21: |
461 |
| - return 95 |
462 |
| - if x < 26: |
463 |
| - return x + 67 |
464 |
| - return x + 50 |
465 |
| - |
466 |
| - if x == 0: |
467 |
| - return 85 |
468 |
| - if x < 7: |
469 |
| - return 102 - x |
470 |
| - if x < 11: |
471 |
| - return 44 - x |
472 |
| - if x < 14: |
473 |
| - return 61 - x |
474 |
| - if x == 14: |
475 |
| - return 63 |
476 |
| - if x < 17: |
477 |
| - return 42 + x |
478 |
| - if x < 21: |
479 |
| - return x + 25 |
480 |
| - if x == 21: |
481 |
| - return 111 |
482 |
| - if x < 27: |
483 |
| - return x + 83 |
484 |
| - return 93 |
485 |
| - |
486 |
| - |
487 |
| -class Keybow2040(Matrix): |
488 |
| - """Supports the Pimoroni Keybow 2040 with 4x4 matrix of RGB LEDs """ |
489 |
| - |
490 |
| - width = 16 |
491 |
| - height = 3 |
492 |
| - |
493 |
| - # pylint: disable=too-many-arguments |
494 |
| - |
495 |
| - def pixelrgb(self, x, y, r, g, b, blink=None, frame=None): |
496 |
| - """ |
497 |
| - Blink or brightness for x, y-pixel |
498 |
| -
|
499 |
| - :param x: horizontal pixel position |
500 |
| - :param y: vertical pixel position |
501 |
| - :param r: red brightness value 0->255 |
502 |
| - :param g: green brightness value 0->255 |
503 |
| - :param b: blue brightness value 0->255 |
504 |
| - :param blink: True to blink |
505 |
| - :param frame: the frame to set the pixel |
506 |
| - """ |
507 |
| - x = x + (4 * y) |
508 |
| - |
509 |
| - super().pixel(x, 0, r, blink, frame) |
510 |
| - super().pixel(x, 1, g, blink, frame) |
511 |
| - super().pixel(x, 2, b, blink, frame) |
512 |
| - |
513 |
| - # pylint: disable=inconsistent-return-statements |
514 |
| - # pylint: disable=too-many-return-statements |
515 |
| - # pylint: disable=too-many-branches |
516 |
| - |
517 |
| - @staticmethod |
518 |
| - def pixel_addr(x, y): |
519 |
| - |
520 |
| - lookup = [ |
521 |
| - (120, 88, 104), # 0, 0 |
522 |
| - (136, 40, 72), # 1, 0 |
523 |
| - (112, 80, 96), # 2, 0 |
524 |
| - (128, 32, 64), # 3, 0 |
525 |
| - (121, 89, 105), # 0, 1 |
526 |
| - (137, 41, 73), # 1, 1 |
527 |
| - (113, 81, 97), # 2, 1 |
528 |
| - (129, 33, 65), # 3, 1 |
529 |
| - (122, 90, 106), # 0, 2 |
530 |
| - (138, 25, 74), # 1, 2 |
531 |
| - (114, 82, 98), # 2, 2 |
532 |
| - (130, 17, 66), # 3, 2 |
533 |
| - (123, 91, 107), # 0, 3 |
534 |
| - (139, 26, 75), # 1, 3 |
535 |
| - (115, 83, 99), # 2, 3 |
536 |
| - (131, 18, 67), # 3, 3 |
537 |
| - ] |
538 |
| - |
539 |
| - return lookup[x][y] |
0 commit comments