> For the complete documentation index, see [llms.txt](https://guide.cronuszen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guide.cronuszen.com/gpcscripting/gpc-script-guide/gpc-developer-guide/functions/controller-functions/led-functions.md).

# LED Functions

| **Function Name** | **Description**                                             |
| ----------------- | ----------------------------------------------------------- |
| set\_led          | Sets the state of the LED on a controller.                  |
| get\_led          | Gets the state of the LED on a controller.                  |
| set\_ledx         | Blinks a LED a certain number of times.                     |
| get\_ledx         | Checks if a LED is being blinked by the set\_ledx function. |
| reset\_leds       | Reset the LEDs state to what was set by the console.        |
| get\_ps4\_lbar    | Gets PS4 indication bar color.                              |
| set\_ps4\_lbar    | Sets Zen indication color.                                  |

***

### set\_led

set\_led sets the state of an LED on the controller. The LEDs range from 0 to 3. Four constants have been created to make it easier to remember which value is assigned to which LED.

| **Name** | **Description**             | **Value** |
| -------- | --------------------------- | --------- |
| LED\_1   | LED 1 / Xbox 360 Quadrant 1 | 0         |
| LED\_2   | LED 2 / Xbox 360 Quadrant 2 | 1         |
| LED\_3   | LED 3 / Xbox 360 Quadrant 3 | 2         |
| LED\_4   | LED 4 / Xbox 360 Quadrant 4 | 3         |

An LED can be set to one of four states using this function which ranges from 0 to 3, as shown in the table below:

| **Value** | **Description**  |
| --------- | ---------------- |
| 0         | LED Off          |
| 1         | LED On           |
| 2         | LED Blink Fast   |
| 3         | LED Blink Slowly |

Code-Snippet

```
set_led(LED_1, 0); // turn the LED off
set_led(LED_1, 1); // turn the LED on
set_led(LED_1, 2); // make the LED blink fast
set_led(LED_1, 3); // make the LED blink slowly
```

Syntax

set\_led( \<led identifier>, \<led state> );

Parameters

\<led identifier> : the LED identifier

\<led state> : the state identifier of the controller LED

Returns

None

***

### get\_led

get\_led returns a value in the form of an int which represents the current state of the chosen LED. The return value from this function informs you of the current state of the selected LED. The function returns a value ranging from 0-3.

| **Return Value** | **Description**     |
| ---------------- | ------------------- |
| 0                | LED Off             |
| 1                | LED On              |
| 2                | LED Blinking Fast   |
| 3                | LED Blinking Slowly |

Example of usage

Code-Snippet

```
main {
    if(get_led(LED_2) == 1) { // if LED 2 is on
        // do something
    }
}
```

Syntax

get\_led ( \<led identifier> );

Parameters

\<led identifier> : the identifier of an LED

Returns

An int ranging from 0-3 which represents the current state.

***

### set\_ledx

set\_ledx is used to blink an LED a set amount of times. You can blink an LED from 0 to 255 times. 0 sets the LED to On.

Example of usage

Code-Snippet

```
main {
    if(!get_ledx()) { // if the LEDs are not blinking
        set_ledx(LED_1, 3); // blink LED 1 3 times
    }
}
```

Syntax

set\_ledx ( \<led identifier> , \<no of blinks> );

Parameters

\<led identifier> : the identifier of an LED

\<no of blinks> : the number of times to blink the LED

***

### get\_ledx

get\_ledx checks to see if an LED is currently being blinked by the set\_ledx function.

Example of usage

Code-Snippet

```
main {
    if(get_ledx()) { // if the LEDs are blinking
        // do something
    }
}
```

Syntax

get\_ledx ( );

Parameters

None

Returns

True if the LEDs are being blinked by the set\_ledx function, False if they are not.

***

### reset\_leds

reset\_leds returns control of the LEDs to the console and disables any current LED states which are being set by the virtual machine.

Example of usage

Code-Snippet

```
main {
    if(event_press(XB1_A)) { // if A / Cross is pressed
        reset_leds(); // reset LEDs
    }
}
```

Syntax

reset\_leds ( );

Parameters

None

***

### Setting DS4 Lightbar

The DualShock 4 controller has one lightbar instead of four LEDs. The color of the lightbar can be controlled by setting all four LED states simultaneously.

#### get\_ps4\_lbar

get\_ps4\_lbar gets the PlayStation 4 lightbar LED state from the console.

`get_ps4_lbar(color)` There are 3 colors: PS4\_RED, PS4\_GREEN, and PS4\_BLUE. They have a range from 0-255 (lower the number equals less brightness, higher the number equals more brighter).

Example

Code-Snippet

```
if(get_ps4_lbar(PS4_GREEN)){
    // will check if the console is sending green lightbar to controller
}
```

#### set\_ps4\_lbar

set\_ps4\_lbar sets the PlayStation 4 lightbar LED state on the controller and sets the color that will be sent to the controller. There are 3 colors: DS4\_RED, DS4\_GREEN, and DS4\_BLUE. They have a range from 0-255 (lower the number equals less brightness, higher the number equals more brighter).

Example

Code-Snippet

```
set_ps4_lbar(0, 0, 255); // will set the DS4 lightbar to bright green
set_ps4_lbar(0, 255, 0); // will set the DS4 lightbar to bright red
set_ps4_lbar(255, 0, 0); // will set the DS4 lightbar to bright blue
```

Example using both

Code-Snippet

```
main{
    if(get_ps4_lbar(PS4_GREEN)){ //checks if console sending green to controller
        set_ps4_lbar(0, 255, 0); // sets controller lightbar to red if console sending green to controller
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://guide.cronuszen.com/gpcscripting/gpc-script-guide/gpc-developer-guide/functions/controller-functions/led-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
