|
| 1 | +# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +""" |
| 6 | +`adafruit_is31fl3741.adafruit_rgbmatrixqt` |
| 7 | +==================================================== |
| 8 | +
|
| 9 | +CircuitPython driver for the Adafruit IS31FL3741 RGB Matrix QT board |
| 10 | +
|
| 11 | +
|
| 12 | +* Author(s): ladyada |
| 13 | +
|
| 14 | +Implementation Notes |
| 15 | +-------------------- |
| 16 | +
|
| 17 | +**Hardware:** |
| 18 | +
|
| 19 | +**Software and Dependencies:** |
| 20 | +
|
| 21 | +* Adafruit CircuitPython firmware for the supported boards: |
| 22 | + https://github.com/adafruit/circuitpython/releases |
| 23 | +
|
| 24 | +""" |
| 25 | + |
| 26 | +# imports |
| 27 | +from . import IS31FL3741 |
| 28 | + |
| 29 | +class Right_Ring(IS31FL3741): |
| 30 | + """The right eye ring of the LED glasses""" |
| 31 | + def __init__(self, is31_controller): |
| 32 | + self._is31 = is31_controller |
| 33 | + |
| 34 | + def __setitem__(self, led, color): |
| 35 | + if not 0 <= led <= 23: |
| 36 | + raise ValueError("led must be 0~23") |
| 37 | + |
| 38 | + ledmap = ((287, 31, 30), # 0 |
| 39 | + (278, 1, 0), # 1 |
| 40 | + (273, 274, 275), # 2 |
| 41 | + (282, 283, 284), # 3 |
| 42 | + (270, 271, 272), # 4 |
| 43 | + (27, 28, 29), # 5 |
| 44 | + (23, 24, 25), # 6 |
| 45 | + (276, 277, 22), # 7 |
| 46 | + (20, 21, 26), # 8 |
| 47 | + (50, 51, 56), # 9 |
| 48 | + (80, 81, 86), # 10 |
| 49 | + (110, 111, 116), #11 |
| 50 | + (140, 141, 146), #12 |
| 51 | + (170, 171, 176), #13 |
| 52 | + (200, 201, 206), #14 |
| 53 | + (230, 231, 236), #15 |
| 54 | + (260, 261, 266), #16 |
| 55 | + (348, 349, 262), #17 |
| 56 | + (233, 234, 235), #18 |
| 57 | + (237, 238, 239), #19 |
| 58 | + (339, 340, 232), #20 |
| 59 | + (327, 328, 329), #21 |
| 60 | + (305, 91, 90), #22 |
| 61 | + (296, 61, 60), # 23 |
| 62 | + ) |
| 63 | + rgb = ledmap[led] |
| 64 | + self._is31[rgb[0]] = (color >> 16) & 0xFF |
| 65 | + self._is31[rgb[1]] = (color >> 8) & 0xFF |
| 66 | + self._is31[rgb[2]] = color & 0xFF |
| 67 | + |
| 68 | +class Left_Ring: |
| 69 | + """The left eye ring of the LED glasses""" |
| 70 | + def __init__(self, is31_controller): |
| 71 | + self._is31 = is31_controller |
| 72 | + |
| 73 | + def __setitem__(self, led, color): |
| 74 | + if not 0 <= led <= 23: |
| 75 | + raise ValueError("led must be 0~23") |
| 76 | + |
| 77 | + ledmap = ( |
| 78 | + (341, 211, 210), #0 |
| 79 | + (332, 181, 180), #1 |
| 80 | + (323, 151, 150), #2 |
| 81 | + (127, 126, 125), #3 |
| 82 | + (154, 153, 152), #4 |
| 83 | + (163, 162, 161), #5 |
| 84 | + (166, 165, 164), #6 |
| 85 | + (244, 243, 242), #7 |
| 86 | + (259, 258, 257), #8 |
| 87 | + (169, 168, 167), #9 |
| 88 | + (139, 138, 137), #10 |
| 89 | + (109, 108, 107), #11 |
| 90 | + (79, 78, 77), #12 |
| 91 | + (49, 48, 47), #13 |
| 92 | + (199, 198, 197), #14 |
| 93 | + (229, 228, 227), #15 |
| 94 | + (19, 18, 17), #16 |
| 95 | + (4, 3, 2), #17 |
| 96 | + (16, 15, 14), #18 |
| 97 | + (13, 12, 11), #19 |
| 98 | + (10, 9, 8), #20 |
| 99 | + (217, 216, 215), #21 |
| 100 | + (7, 6, 5), #22 |
| 101 | + (350, 241, 240), #23 |
| 102 | + ) |
| 103 | + rgb = ledmap[led] |
| 104 | + self._is31[rgb[0]] = (color >> 16) & 0xFF |
| 105 | + self._is31[rgb[1]] = (color >> 8) & 0xFF |
| 106 | + self._is31[rgb[2]] = color & 0xFF |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | +class LED_Glasses(IS31FL3741): |
| 112 | + def __init__(self, i2c): |
| 113 | + super().__init__(i2c) |
| 114 | + self.set_led_scaling(0xFF) # turn on LEDs all the way |
| 115 | + self.global_current = 0xFE # set current to max |
| 116 | + self.enable = True # enable! |
| 117 | + |
| 118 | + self.right_ring = Right_Ring(self) |
| 119 | + self.left_ring = Left_Ring(self) |
0 commit comments