Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
|
LED code is based on Espressif's RMT Transmit Example - LED Strip.
Each LED has a red, green, and blue component. Each component ranges from 0 to 255.
LED brightness is not linear, so differences in brightness are more noticeable between small values (like 1 and 10) than between large values (like 240 and 250).
The number of LEDs are configurable by "idf.py menuconfig" and is accessible in code with the CONFIG_NUM_LEDS macro.
You don't need to call initLeds() or deinitLeds(). The system does so at the appropriate time.
You should call setLeds() any time you want to set the LEDs. There is no buffer, so the LEDs are immediately set to the values given. setLeds() takes a pointer to an array of led_t as an argument. These structs each have a red, green, and blue field.
setLedBrightness() may be called to adjust overall LED brightness. Brightness is adjusted per-color-channel, so dimming may produce different colors. setLedBrightnessSetting() should be called instead if the brightness change should be persistent through reboots.
flushLeds() may be called to wait until all pending LED transactions are completed. This does not need to be called under normal operation. The RMT peripheral handles updating LEDs in the background automatically, but transactions must be flushed before entering light sleep. If they are not, garbage data may be sent after light sleep begins, resulting in indeterminate LED behavior.
Set the LEDs to a rough rainbow:
Go to the source code of this file.
Data Structures | |
struct | led_t |
LED colors, with red, green, and blue components. More... | |
Macros | |
#define | MAX_LED_BRIGHTNESS 8 |
The maximum LED brightness setting. | |
Functions | |
esp_err_t | initLeds (gpio_num_t gpio, gpio_num_t gpioAlt, uint8_t brightness) |
Initialize the RGB LEDs. | |
esp_err_t | deinitLeds (void) |
Deinitialize LEDs. | |
esp_err_t | setLeds (led_t *leds, uint8_t numLeds) |
Set the RGB LEDs to the given values. | |
void | setLedBrightness (uint8_t brightness) |
Set the global LED brightness. setLedBrightnessSetting() should be called instead if the new volume should be persistent through a reboot. | |
uint8_t | getLedState (led_t *leds, uint8_t numLeds) |
Write the current LED state into the given array. | |
void | flushLeds (void) |
Wait until any pending LED transactions are finished, then return. | |
struct led_t |
#define MAX_LED_BRIGHTNESS 8 |
The maximum LED brightness setting.
esp_err_t initLeds | ( | gpio_num_t | gpio, |
gpio_num_t | gpioAlt, | ||
uint8_t | brightness ) |
Initialize the RGB LEDs.
gpio | The GPIO the LEDs are attached to |
gpioAlt | A GPIO to mirror the LED output to |
brightness | The brightness to start the LEDs at |
esp_err_t deinitLeds | ( | void | ) |
Deinitialize LEDs.
esp_err_t setLeds | ( | led_t * | leds, |
uint8_t | numLeds ) |
Set the RGB LEDs to the given values.
leds | A pointer to an array of led_t structs to set the LEDs to. The array must have at least numLeds elements |
numLeds | The number of LEDs to set, probably CONFIG_NUM_LEDS |
void setLedBrightness | ( | uint8_t | brightness | ) |
Set the global LED brightness. setLedBrightnessSetting() should be called instead if the new volume should be persistent through a reboot.
brightness | 0 (off) to MAX_LED_BRIGHTNESS (max bright) |
uint8_t getLedState | ( | led_t * | leds, |
uint8_t | numLeds ) |
Write the current LED state into the given array.
[out] | leds | The LED array to write the state into |
numLeds | The maximum number of LEDs to write |
void flushLeds | ( | void | ) |
Wait until any pending LED transactions are finished, then return.