# Macro lighting control

**URL:** https://forum.sienci.com/t/macro-lighting-control/11958
**Category:** 📖Docs
**Created:** [April 14, 2024, 2:46pm UTC](https://forum.sienci.com/t/macro-lighting-control/11958 "2024-04-14T14:46:04Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![KGN](https://forum.sienci.com/letter_avatar_proxy/v4/letter/k/c77e96/32.png) [@KGN](https://forum.sienci.com/u/KGN)
#### Post date: [April 15, 2024, 8:07pm UTC](https://forum.sienci.com/t/macro-lighting-control/11958/7 "2024-04-15T20:07:07Z")

</div>

If you’re using gSender macros (not the e-stop button firmware macros) with a keybind, something like this should work:

```auto
%nextLight = global.lightState || 0
M356 P0 Q[nextLight % 3]
%global.lightState = Number(nextLight) + 1

```

It either retrieves the current lightState or sets it to 0 if it’s undefined, sets the light to the current state modulus 3 (so the value will never go above 2) and then stores the next state sequence.

Any variables stored in global persist until the application is closed.

From a cursory glance it seems to be working as expected to cycle between auto, white, and off.

 ![image](https://forum.sienci.com/uploads/default/original/2X/4/494cb0f772dcea3808d14fedb19e0face56a3941.png)

---

_[View the full topic](https://forum.sienci.com/t/macro-lighting-control/11958)._
