Examples

KTD2061 Simple test

Ensure KTD2061 works with this simple test. It can be modified for other KTD2061 variants.

examples/kinetic_rgb_ktd2061_simpletest.py
  1# SPDX-FileCopyrightText: 2026 Alexander Huey for Kinetic Technologies, Inc.
  2#
  3# SPDX-License-Identifier: MIT
  4
  5"""
  6#################################################
  7# README ########################################
  8#################################################
  9# KTD2061 Line Example Software
 10#     by Alexander Huey, Kinetic Technologies
 11#     Revision 1.00 - March 12th, 2026
 12#
 13# This file contains example QTPY RP2040 code using the
 14#   Kinetic RGB driver for the KTD2061 Product Line.
 15#
 16# Refer to Kinetic_RGB.py for all definitions for KineticRGB.<FunctionName>
 17# Additionally, Kinetic_RGB.py handles all input validation for function inputs
 18# For quick modifications, search up "##"
 19#   All important lines to be changed are marked with said symbol
 20"""
 21
 22# module imports
 23import time
 24
 25import board
 26import busio
 27
 28from kinetic_rgb import *
 29from kinetic_rgb import KTD2061  ## Import Product Class
 30
 31_i2cbus = busio.I2C(board.SCL1, board.SDA1, frequency=100000)
 32KineticRGB = KTD2061(_i2cbus)  ## Assign Bus to Class
 33
 34
 35# Functions Begin =================================================================================
 36def allrgb_normalmode(fade_rate0):
 37    # KineticRGB.global_control(
 38    # enableMode=EnableMode.MODE_DAY,
 39    # brightExtend=1,
 40    # coolExtend=CoolExtend_Temp.DEGREES_105C,
 41    # fadeRate=fadeRate
 42    # )
 43    KineticRGB.global_control(EnableMode.MODE_DAY, fade_rate0=fade_rate0)
 44
 45
 46def allrgb_nightmode(fade_rate0):
 47    # KineticRGB.global_control(
 48    # enableMode=EnableMode.MODE_NIGHT,
 49    # brightExtend=1,
 50    # coolExtend=CoolExtend_Temp.DEGREES_105C,
 51    # fadeRate=fadeRate
 52    # )
 53    KineticRGB.global_control(EnableMode.MODE_NIGHT, fade_rate0=fade_rate0)
 54
 55
 56def allrgb_off(fade_rate0):
 57    # KineticRGB.global_control(
 58    #     enableMode=EnableMode.MODE_GLOBAL_OFF,
 59    #     brightExtend=1,
 60    #     coolExtend=CoolExtend_Temp.DEGREES_105C,
 61    #     fadeRate=fadeRate
 62    # )
 63    KineticRGB.global_control(EnableMode.MODE_GLOBAL_OFF, fade_rate0=fade_rate0)
 64    KineticRGB.set_rgb_module_to_off(KTD2061RGBModuleSelect.RGB_MODULE_ALL)
 65
 66
 67def global_reset():
 68    KineticRGB.global_reset_to_defaults()
 69
 70
 71def color_mix_example(fade, delay, r0, g0, b0, r1, g1, b1):  # noqa: PLR0917, PLR0913
 72    color0 = r0 << 16 | g0 << 8 | b0  # create the RGB hex code
 73    color1 = r1 << 16 | g1 << 8 | b1  # create the RGB hex code
 74
 75    allrgb_off(fade)  # Have all LEDs off
 76    for i in range(8):  # Set up all 8 color options
 77        blu_option = (i >> 0) & 1
 78        grn_option = (i >> 1) & 1
 79        red_option = (i >> 2) & 1
 80
 81        module_num = i + 2 if (i < 4) else i + 4  # 8 Options -> Modules 2, 3, 4, 5, 8, 9, 10, 11
 82        KineticRGB.set_rgb_module_color_mix(module_num, red_option, grn_option, blu_option)
 83        KineticRGB.set_rgb_module_to_on(module_num)
 84
 85    print("Showing SRGB Adjustment")
 86    KineticRGB.set_color0(color0, True)
 87    KineticRGB.set_color1(color1, True)
 88    allrgb_normalmode(fade)  # Show SRGB colors in normal mode
 89    time.sleep(delay)
 90    allrgb_nightmode(fade)  # Show SRGB colors in night mode
 91    time.sleep(delay)
 92
 93    print("Showing no SRGB Adjustment")
 94    allrgb_normalmode(fade)
 95    KineticRGB.set_color0(color0, False)
 96    KineticRGB.set_color1(color1, False)
 97    time.sleep(delay)
 98    allrgb_nightmode(fade)
 99    time.sleep(delay)
100
101    allrgb_off(fade)
102
103
104def brightness_adjustment_example(fade, delay):
105    allrgb_off(fade)
106    KineticRGB.set_color1(0xFFFFFF)
107    KineticRGB.set_rgb_module_color_mix(KTD2061RGBModuleSelect.RGB_MODULE_ALL, 1, 1, 1)
108    KineticRGB.set_rgb_module_to_on(KTD2061RGBModuleSelect.RGB_MODULE_ALL, fade_rate=fade)
109    allrgb_normalmode(fade)
110
111    # remember, blue > green > red in terms of intensity/strength
112    print("Decrease current blue brightness by 50%")
113    for _ in range(3):
114        KineticRGB.set_color1_led_brightness(RGBSelectLed.BLUE, 50)
115        time.sleep(delay)
116
117    print("Decrease current green brightness by 50%")
118    for _ in range(3):
119        KineticRGB.set_color1_led_brightness(RGBSelectLed.GREEN, 50)
120        time.sleep(delay)
121
122    print("Decrease current red brightness by 50%")
123    for _ in range(3):
124        KineticRGB.set_color1_led_brightness(RGBSelectLed.RED, 50)
125        time.sleep(delay)
126
127    print("Restore to original color by increasing brightness")
128    for _ in range(3):
129        KineticRGB.set_color1_led_brightness(RGBSelectLed.MODULE, 150)
130        time.sleep(delay)
131
132    allrgb_off(fade)
133
134
135# SetUp Defaults
136global_reset()
137KineticRGB.global_control(
138    enable_mode=EnableMode.MODE_DAY,
139    bright_ext=1,
140    cool_ext=CoolExtendTemp.DEGREES_105C,
141    fade_rate0=None,
142)
143KineticRGB.check_device_status()
144allrgb_off(FadeRate.RATE_63MS)
145while True:
146    print("All Combinations of Color0 and Color1 Example (with and without SRGB)")
147    color_mix_example(FadeRate.RATE_63MS, 2, 127, 127, 127, 255, 255, 255)
148    time.sleep(5)
149    print("Brightness Adjustment Example")
150    brightness_adjustment_example(FadeRate.RATE_63MS, 1)

KTD2052A Simple test

Ensure KTD2052A works with this simple test. It can be modified for other KTD2052 variants.

examples/kinetic_rgb_ktd2052_simpletest.py
  1# SPDX-FileCopyrightText: 2026 Alexander Huey for Kinetic Technologies, Inc.
  2#
  3# SPDX-License-Identifier: MIT
  4
  5"""
  6#################################################
  7# README ########################################
  8#################################################
  9# KTD2052 Line Example Software
 10#     by Alexander Huey, Kinetic Technologies
 11#     Revision 1.00 - March 12th, 2026
 12#
 13# This file contains example QTPY RP2040 code using the
 14#   Kinetic RGB driver for the KTD2052 Product Line.
 15#
 16# Refer to Kinetic_RGB.py for all definitions for KineticRGB.<FunctionName>
 17# Additionally, Kinetic_RGB.py handles all input validation for function inputs
 18# For quick modifications, search up "##"
 19#   All important lines to be changed are marked with said symbol
 20"""
 21
 22# module imports
 23import time
 24
 25import board
 26import busio
 27
 28from kinetic_rgb import *
 29from kinetic_rgb import KTD2052A  ## Import Product Class
 30
 31_i2cbus = busio.I2C(board.SCL1, board.SDA1, frequency=100000)
 32ktd2052 = KTD2052A(_i2cbus)  ## Assign Bus to Class
 33
 34
 35# Functions Begin =================================================================================
 36def allrgb_normalmode(fade_rate0):
 37    # KineticRGB.global_control(
 38    # enableMode=EnableMode.MODE_DAY,
 39    # brightExtend=1,
 40    # coolExtend=CoolExtendTemp.DEGREES_105C,
 41    # fadeRate=fade_rate0
 42    # )
 43    ktd2052.global_control(EnableMode.MODE_DAY, fade_rate0=fade_rate0)
 44
 45
 46def allrgb_nightmode(fade_rate0):
 47    # KineticRGB.global_control(
 48    # enableMode=EnableMode.MODE_NIGHT,
 49    # brightExtend=1,
 50    # coolExtend=CoolExtendTemp.DEGREES_105C,
 51    # fadeRate=fade_rate0
 52    # )
 53    ktd2052.global_control(EnableMode.MODE_NIGHT, fade_rate0=fade_rate0)
 54
 55
 56def allrgb_off(fade_rate0):
 57    # KineticRGB.global_control(
 58    # enableMode=EnableMode.MODE_GLOBAL_OFF,
 59    # brightExtend=1,
 60    # coolExtend=CoolExtendTemp.DEGREES_105C,
 61    # fadeRate=fade_rate0
 62    # )
 63    ktd2052.global_control(EnableMode.MODE_GLOBAL_OFF, fade_rate0=fade_rate0)
 64
 65
 66def global_reset():
 67    ktd2052.global_reset_to_defaults()
 68
 69
 70def srgb_example(r0, g0, b0, r1, g1, b1):  # noqa: PLR0917, PLR0913
 71    color0 = r0 << 16 | g0 << 8 | b0  # create the RGB hexcode
 72    color1 = r1 << 16 | g1 << 8 | b1  # create the RGB hexcode
 73    allrgb_off(FadeRate.RATE_125MS)
 74    # color 0 and color 1 with/without SRGB
 75    ktd2052.set_rgbx_color(color0, KTD2052RGBModuleSelect.RGB_MODULE_1, True)
 76    ktd2052.set_rgbx_color(color0, KTD2052RGBModuleSelect.RGB_MODULE_2, False)
 77    ktd2052.set_rgbx_color(color1, KTD2052RGBModuleSelect.RGB_MODULE_3, True)
 78    ktd2052.set_rgbx_color(color1, KTD2052RGBModuleSelect.RGB_MODULE_4, False)
 79    allrgb_normalmode(FadeRate.RATE_125MS)
 80
 81    time.sleep(2)
 82    for _ in range(5):
 83        r0 = min(255, r0 + 10)  # show behavior when increasing (max 255)
 84        g0 = min(255, g0 + 10)  # show behavior when increasing (max 255)
 85        b0 = min(255, b0 + 10)  # show behavior when increasing (max 255)
 86        color0 = r0 << 16 | g0 << 8 | b0
 87
 88        r1 = max(0, r1 - 10)  # show behavior when decreasing (min 0)
 89        g1 = max(0, g1 - 10)  # show behavior when decreasing (min 0)
 90        b1 = max(0, b1 - 10)  # show behavior when decreasing (min 0)
 91        color1 = r1 << 16 | g1 << 8 | b1
 92
 93        ktd2052.set_rgbx_color(color0, KTD2052RGBModuleSelect.RGB_MODULE_1, True)
 94        ktd2052.set_rgbx_color(color0, KTD2052RGBModuleSelect.RGB_MODULE_2, False)
 95        ktd2052.set_rgbx_color(color1, KTD2052RGBModuleSelect.RGB_MODULE_3, True)
 96        ktd2052.set_rgbx_color(color1, KTD2052RGBModuleSelect.RGB_MODULE_4, False)
 97        time.sleep(1)
 98
 99
100def brightness_adjustment_example(fade, delay):
101    allrgb_off(FadeRate.RATE_125MS)
102    ktd2052.set_rgbx_color(0xFFFFFF)  # default is all LEDs
103
104    allrgb_normalmode(fade)
105    time.sleep(5)
106    for _ in range(5):
107        ktd2052.set_colorx_led_brightness(
108            RGBSelectLed.MODULE, KTD2052RGBModuleSelect.RGB_MODULE_1, 50
109        )  # decrease blue current brightness by 50%
110        ktd2052.set_colorx_led_brightness(
111            RGBSelectLed.RED, KTD2052RGBModuleSelect.RGB_MODULE_2, 50
112        )  # decrease red current brightness by 50%
113        ktd2052.set_colorx_led_brightness(
114            RGBSelectLed.GREEN, KTD2052RGBModuleSelect.RGB_MODULE_3, 50
115        )  # decrease green current brightness by 50%
116        ktd2052.set_colorx_led_brightness(
117            RGBSelectLed.BLUE, KTD2052RGBModuleSelect.RGB_MODULE_4, 50
118        )  # decrease blue current brightness by 50%
119        time.sleep(delay)
120
121    for _ in range(5):
122        ktd2052.set_colorx_led_brightness(
123            RGBSelectLed.MODULE, KTD2052RGBModuleSelect.RGB_MODULE_1, 150
124        )  # Restore decreased overall current brightness by 50%
125        ktd2052.set_colorx_led_brightness(
126            RGBSelectLed.RED, KTD2052RGBModuleSelect.RGB_MODULE_2, 150
127        )  # Restore decreased red current brightness by 50%
128        ktd2052.set_colorx_led_brightness(
129            RGBSelectLed.GREEN, KTD2052RGBModuleSelect.RGB_MODULE_3, 150
130        )  # Restore decreased green current brightness by 50%
131        ktd2052.set_colorx_led_brightness(
132            RGBSelectLed.BLUE, KTD2052RGBModuleSelect.RGB_MODULE_4, 150
133        )  # Restore decreased blue current brightness by 50%
134        time.sleep(delay)
135
136    allrgb_off(fade)
137
138
139def pattern_generator_example(cycles, fade1):
140    allrgb_off(FadeRate.RATE_125MS)
141    ktd2052.set_rgbx_color(0xFFFFFF)  # default is all LEDs
142    ktd2052.pattern_gen_control(
143        patterngen_mode=KTD2052PatternGenModes.GENERATE_8_PATTERNS,
144        pattern_duration=KTD2052PatternTimeLen.DURATION_188MS,
145        patterngen_fade_rate1=fade1,
146    )
147    # use fade1 for all 8 pattern slots, can also use fade0 if desired
148    ktd2052.pattern_slot_fade_selection(0b11111111)
149
150    ktd2052.pattern_configuration_rgb(
151        rgb_module=KTD2052RGBModuleSelect.RGB_MODULE_1, pattern_config=0b10000001
152    )  # control RGB1 on/off in each patern slot (7 -> 0)
153    ktd2052.pattern_configuration_rgb(
154        rgb_module=KTD2052RGBModuleSelect.RGB_MODULE_2, pattern_config=0b01000010
155    )  # control RGB2 on/off in each patern slot (7 -> 0)
156    ktd2052.pattern_configuration_rgb(
157        rgb_module=KTD2052RGBModuleSelect.RGB_MODULE_3, pattern_config=0b00100100
158    )  # control RGB3 on/off in each patern slot (7 -> 0)
159    ktd2052.pattern_configuration_rgb(
160        rgb_module=KTD2052RGBModuleSelect.RGB_MODULE_4, pattern_config=0b00011000
161    )  # control RGB4 on/off in each patern slot (7 -> 0)
162
163    # Alternate way to configure the patterns by slot for visualization/convenience
164    # KineticRGB.pattern_configuration_slot(
165    #   patternSlot = 7,
166    #   rgb1On = True,
167    #   rgb2On = False,
168    #   rgb3On = False,
169    #   rgb4On = False
170    # )
171    # KineticRGB.pattern_configuration_slot(
172    #   patternSlot = 6,
173    #   rgb1On = False,
174    #   rgb2On = True,
175    #   rgb3On = False,
176    #   rgb4On = False
177    # )
178    # KineticRGB.pattern_configuration_slot(
179    #   patternSlot = 5,
180    #   rgb1On = False,
181    #   rgb2On = False,
182    #   rgb3On = True,
183    #   rgb4On = False
184    # )
185    # KineticRGB.pattern_configuration_slot(
186    #   patternSlot = 4,
187    #   rgb1On = False,
188    #   rgb2On = False,
189    #   rgb3On = False,
190    #   rgb4On = True
191    # )
192    # KineticRGB.pattern_configuration_slot(
193    #   patternSlot = 3,
194    #   rgb1On = False,
195    #   rgb2On = False,
196    #   rgb3On = False,
197    #   rgb4On = True)
198    #   # Config RGB Status for Slot 3
199    # KineticRGB.pattern_configuration_slot(
200    #   patternSlot = 2,
201    #   rgb1On = False,
202    #   rgb2On = False,
203    #   rgb3On = True,
204    #   rgb4On = False
205    # )
206    # KineticRGB.pattern_configuration_slot(
207    #   patternSlot = 1,
208    #   rgb1On = False,
209    #   rgb2On = True,
210    #   rgb3On = False,
211    #   rgb4On = False
212    # )
213    # KineticRGB.pattern_configuration_slot(
214    #   patternSlot = 0,
215    #   rgb1On = True,
216    #   rgb2On = False,
217    #   rgb3On = False,
218    #   rgb4On = False
219    # )
220
221    # WDT must be set BEFORE control On -> otherwise cycle count will be off
222    ktd2052.pattern_cycles_config_wdt(cycles)  # (255 = continue forever)
223    allrgb_normalmode(FadeRate.RATE_125MS)  # sets fade0 (global Fade) & sets to normal Enable
224
225    while 1:  # pattern generator will independently run cycles
226        time.sleep(5)
227        cycles_left = ktd2052.check_pattern_cycles_remaining()
228        if cycles_left == 0:
229            global_reset()  # clean regs
230            break
231        elif cycles_left == 40:
232            ktd2052.set_rgbx_color(0x0000FF)  # colors can be changed mid cycle
233
234
235global_reset()
236ktd2052.global_control(
237    enable_mode=EnableMode.MODE_DAY,
238    bright_ext=1,
239    cool_ext=CoolExtendTemp.DEGREES_105C,
240    fade_rate0=None,
241)
242
243ktd2052.check_device_status()
244allrgb_normalmode(FadeRate.RATE_125MS)  # sets fade0 (global Fade) & sets to normal Enable
245allrgb_off(FadeRate.RATE_125MS)
246while True:
247    print("No Pattern Generatior, SRGB (Standard Red Green Blue) Adjustment Example")
248    srgb_example(127, 127, 127, 90, 70, 60)
249    time.sleep(5)
250    print("No Pattern Generatior, Brightness Adjustment Example")
251    brightness_adjustment_example(FadeRate.RATE_63MS, 3)
252    time.sleep(5)
253    print("Pattern Generator Example")
254    pattern_generator_example(50, FadeRate.RATE_63MS)
255    time.sleep(5)