# Lock layer without the LED?

**URL:** <https://community.keyboard.io/t/lock-layer-without-the-led/672>\
**Category:** Programming\
**Created:** [November 3, 2017, 7:57am UTC](https://community.keyboard.io/t/lock-layer-without-the-led/672 "2017-11-03T07:57:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![milkypostman](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/milkypostman/32/649_2.png) [@milkypostman](https://community.keyboard.io/u/milkypostman)\
**Post date:** [November 3, 2017, 7:57am UTC](https://community.keyboard.io/t/lock-layer-without-the-led/672/1 "2017-11-03T07:57:18Z")

</div>

i have been using `LockLayer` to implement multiple key layouts (qwerty and norman because on some systems i let the system implement the keymap and sometimes i want my keyboard to do the remapping.).

anyways, the problem is that when i go to my NORMAN layout, i don’t want the LED to stay lit all the time. it would be nice to have it blink at least to let me know that i have switched layouts but i don’t want it to stay lit.

for now i have implemented this with macros and using `Layout.move(...)`.

---

<div class="post-metadata">

**Author:** ![algernon](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/algernon/32/4404_2.png) [@algernon](https://community.keyboard.io/u/algernon)\
**Post date:** [November 3, 2017, 12:15pm UTC](https://community.keyboard.io/t/lock-layer-without-the-led/672/2 "2017-11-03T12:15:12Z")

</div>

A quick way to implement this would be a macro like this:

```auto
void togleNORMAN(uint8_t key_state) {
  static uint16_t blink_end;

  if (keyToggledOn(key_state)) {
    blink_end = millis() + 1000;
    if (Layer.isOn(NORMAN)) {
      Layer.off(NORMAN);
    } else {
      Layer.on(NORMAN);
    }
    LEDControl.setAllLedsTo(128, 0, 0);
    return;
  }

  if (blink_end && millis() > blink_end) {
    LEDControl.setAllLedsTo(0, 0, 0);
    blink_end = 0;
  }
}

```

The idea here is that when toggling the layer, we’ll set the leds, and record when the leds should turn off (1s after toggling on). When the key’s not toggled on, we check if we have an end time, and if we do and it is over, we turn the LEDs off. This does not blink, but show you a static color, mind you. Blinking can be implemented with reasonable ease. Or you could even add breathing… But those are left as an exercise for the reader! 😉

---

<div class="post-metadata">

**Author:** ![milkypostman](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/milkypostman/32/649_2.png) [@milkypostman](https://community.keyboard.io/u/milkypostman)\
**Post date:** [November 3, 2017, 1:53pm UTC](https://community.keyboard.io/t/lock-layer-without-the-led/672/3 "2017-11-03T13:53:38Z")

</div>

Oh of course! This all makes total sense now. Although based on your code I think the bottom if statement would need to go into the main macro loop otherwise it would only get triggered when the key is pressed.

So one off question, I looked through [layers.cc](http://layers.cc) and I couldn’t find what is actually turning the leds on. Did I miss it in there?

---

<div class="post-metadata">

**Author:** ![algernon](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/algernon/32/4404_2.png) [@algernon](https://community.keyboard.io/u/algernon)\
**Post date:** [November 3, 2017, 4:52pm UTC](https://community.keyboard.io/t/lock-layer-without-the-led/672/4 "2017-11-03T16:52:32Z")

</div>

> [@milkypostman](#):
>
> Although based on your code I think the bottom if statement would need to go into the main macro loop otherwise it would only get triggered when the key is pressed.

No, because macro actions are called even when there are no key events. This allows implementing macros that do something even with the key released!

> [@milkypostman](#):
>
> So one off question, I looked through layers.cc and I couldn’t find what is actually turning the leds on. Did I miss it in there?

No, you did not miss anything. The layer code does not touch LEDs at all by default. You may have some other plugin that does, though.
