Using LEDs

LEDs are a fun and intuitive way to interact with a user of Relay. There are 12 configurable LEDs on a Relay.

The LEDs can be toggled by their index which range from 1 to 12 respectively. To configure colors, they have to be passed into the respective function as a string of Hex values.

There are currently 8 different LED functions within the Relay SDK:

Function

Description

switchLedOn(led: LedIndex, color: string)

This function toggles a single LED on at a certain index with a certain color.

passing in switchLedOn(3, '0000FF') would turn the 3rd LED on in a blue color

switchAllLedOn(color: string)

This function turns all 12 LEDs on with a single color.

passing in switchAllLedOn('FF0000') would turn ALL LEDs on with a red color

switchAllLedOff()

This functions turns off all LEDs.

rainbow(rotations=-1)

This functions causes the all LEDs to light up in a rainbow configuration and rotate. You can pass how many times you want the LEDs to rotate. By default, its -1 which means it will rotate indefinitely.

passing in rainbow(5) would mean all of the LEDs light up in a rainbow configuration and rotate 5 times

rotate(color="FFFFFF")

This function causes all the LEDs to rotate in a static color indefinitely. By default it's white.

calling rotate('#CCCCFF') would cause the LEDs to rotate in purple.

flash(color="0000FF")

This function causes all the LEDs to flash in a static color indefinitely. By default it's blue.

calling flash() would cause the LEDs to flash in blue.

breathe(color="0000FF")

This function causes all the LEDs to breathe slowly in a static color indefinitely. By default it's blue.

calling breathe("FF0000) would cause the LEDs to breathe red.

ledAction(effect: LedEffect, args: LedInfo)

This is the all encompassing function to program the LEDs to behave however you want. You can target exactly which LEDs you want on and what color.

The first input in the function (LedEffect) is the type of effect you want. there are 6 different types of string inputs accepted here: "off" | "breathe" | "flash" | "rotate" | "rainbow" | "static"

the second input (LedInfo) is an object of led index mappings to colors. Please refer to the Types file in the SDK for the full schema. As an example it would look like this

{
    colors: {
        1: '0000FF',
        2: '0000FF',
        3: '0000FF',
        4: '00FF00',
        5: '00FF00'
    }
}

This toggles the first 3 LEDs to red and the 4th and 5th LEDs to green. LEDs 6-12 will be off.