WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
AddressableLED.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <stdint.h>
8
10#include "hal/Types.h"
11
12/**
13 * @defgroup hal_addressable Addressable LED Functions
14 * @ingroup hal_capi
15 * @{
16 */
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22/**
23 * Initialize Addressable LED using a PWM Digital handle.
24 *
25 * @param[in] outputPort handle of the digital port for PWM
26 * @param[out] status the error code, or 0 for success
27 * @return Addressable LED handle
28 */
30 HAL_DigitalHandle outputPort, int32_t* status);
31
32/**
33 * Free the Addressable LED Handle.
34 *
35 * @param[in] handle the Addressable LED handle to free
36 */
38
39/**
40 * Sets the color order for the addressable LED output. The default order is
41 * GRB. This will take effect on the next call to HAL_WriteAddressableLEDData().
42 * @param[in] handle the Addressable LED handle
43 * @param[in] colorOrder the color order
44 * @param[out] status the error code, or 0 for success
45 */
48 int32_t* status);
49
50/**
51 * Set the Addressable LED PWM Digital port.
52 *
53 * @param[in] handle the Addressable LED handle
54 * @param[in] outputPort The digital handle of the PWM port
55 * @param[out] status the error code, or 0 for success
56 */
58 HAL_DigitalHandle outputPort,
59 int32_t* status);
60
61/**
62 * Sets the length of the LED strip.
63 *
64 * <p>The max length is 5460 LEDs.
65 *
66 * @param[in] handle the Addressable LED handle
67 * @param[in] length the strip length
68 * @param[out] status the error code, or 0 for success
69 */
71 int32_t length, int32_t* status);
72
73/**
74 * Sets the led output data.
75 *
76 * <p>If the output is enabled, this will start writing the next data cycle.
77 * It is safe to call, even while output is enabled.
78 *
79 * @param[in] handle the Addressable LED handle
80 * @param[in] data the buffer to write
81 * @param[in] length the strip length
82 * @param[out] status the error code, or 0 for success
83 */
85 const struct HAL_AddressableLEDData* data,
86 int32_t length, int32_t* status);
87
88/**
89 * Sets the bit timing.
90 *
91 * <p>By default, the driver is set up to drive WS2812B and WS2815, so nothing
92 * needs to be set for those.
93 *
94 * @param[in] handle the Addressable LED handle
95 * @param[in] highTime0NanoSeconds high time for 0 bit (default 400ns)
96 * @param[in] lowTime0NanoSeconds low time for 0 bit (default 900ns)
97 * @param[in] highTime1NanoSeconds high time for 1 bit (default 900ns)
98 * @param[in] lowTime1NanoSeconds low time for 1 bit (default 600ns)
99 * @param[out] status the error code, or 0 for success
100 */
102 int32_t highTime0NanoSeconds,
103 int32_t lowTime0NanoSeconds,
104 int32_t highTime1NanoSeconds,
105 int32_t lowTime1NanoSeconds,
106 int32_t* status);
107
108/**
109 * Sets the sync time.
110 *
111 * <p>The sync time is the time to hold output so LEDs enable. Default set for
112 * WS2812B and WS2815.
113 *
114 * @param[in] handle the Addressable LED handle
115 * @param[in] syncTimeMicroSeconds the sync time (default 280us)
116 * @param[out] status the error code, or 0 for success
117 */
119 int32_t syncTimeMicroSeconds,
120 int32_t* status);
121
122/**
123 * Starts the output.
124 *
125 * <p>The output writes continuously.
126 *
127 * @param[in] handle the Addressable LED handle
128 * @param[out] status the error code, or 0 for success
129 */
131 int32_t* status);
132
133/**
134 * Stops the output.
135 *
136 * @param[in] handle the Addressable LED handle
137 * @param[out] status the error code, or 0 for success
138 */
140 int32_t* status);
141
142#ifdef __cplusplus
143} // extern "C"
144#endif
145/** @} */
HAL_AddressableLEDColorOrder
Order that color data is sent over the wire.
Definition AddressableLEDTypes.h:24
void HAL_SetAddressableLEDSyncTime(HAL_AddressableLEDHandle handle, int32_t syncTimeMicroSeconds, int32_t *status)
Sets the sync time.
void HAL_SetAddressableLEDOutputPort(HAL_AddressableLEDHandle handle, HAL_DigitalHandle outputPort, int32_t *status)
Set the Addressable LED PWM Digital port.
void HAL_SetAddressableLEDLength(HAL_AddressableLEDHandle handle, int32_t length, int32_t *status)
Sets the length of the LED strip.
void HAL_WriteAddressableLEDData(HAL_AddressableLEDHandle handle, const struct HAL_AddressableLEDData *data, int32_t length, int32_t *status)
Sets the led output data.
void HAL_StopAddressableLEDOutput(HAL_AddressableLEDHandle handle, int32_t *status)
Stops the output.
void HAL_StartAddressableLEDOutput(HAL_AddressableLEDHandle handle, int32_t *status)
Starts the output.
void HAL_SetAddressableLEDColorOrder(HAL_AddressableLEDHandle handle, HAL_AddressableLEDColorOrder colorOrder, int32_t *status)
Sets the color order for the addressable LED output.
HAL_AddressableLEDHandle HAL_InitializeAddressableLED(HAL_DigitalHandle outputPort, int32_t *status)
Initialize Addressable LED using a PWM Digital handle.
void HAL_FreeAddressableLED(HAL_AddressableLEDHandle handle)
Free the Addressable LED Handle.
void HAL_SetAddressableLEDBitTiming(HAL_AddressableLEDHandle handle, int32_t highTime0NanoSeconds, int32_t lowTime0NanoSeconds, int32_t highTime1NanoSeconds, int32_t lowTime1NanoSeconds, int32_t *status)
Sets the bit timing.
HAL_Handle HAL_DigitalHandle
Definition Types.h:31
HAL_Handle HAL_AddressableLEDHandle
Definition Types.h:61
structure for holding one LED's color data.
Definition AddressableLEDTypes.h:14