Last active
February 18, 2020 13:09
-
-
Save Duckle29/58a8bdf101eea0c2e3d8c0a05ad6a052 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const uint8_t leds[] = { E6, B1, D0, D1, D2 }; | |
void set_leds(void); | |
void clear_leds(void); | |
void keyboard_post_init_user(){ | |
// Set all 5 LED pins as outputs | |
for(int i=0; i<sizeof(leds)/sizeof(leds[0]); i++) | |
{ | |
setPinOutput(leds[i]); | |
} | |
} | |
// Turn on all LEDs (active low LEDS) | |
void set_leds(){ | |
for(int i=0; i<sizeof(leds)/sizeof(leds[0]); i++) | |
{ | |
writePin(leds[i], 0); | |
} | |
} | |
// Turn off all LEDs (active low leds) | |
void clear_leds(){ | |
for(int i=0; i<sizeof(leds)/sizeof(leds[0]); i++) | |
{ | |
writePin(leds[i], 1); | |
} | |
} | |
bool led_update_kb(led_t led_state) | |
{ | |
bool res = led_update_user(led_state); | |
if(res) | |
{ | |
// writePin sets the pin high for 1 and low for 0. | |
// In this example the pins are inverted, setting | |
// it low/0 turns it on, and high/1 turns the LED off. | |
// This behavior depends on whether the LED is between the pin | |
// and VCC or the pin and GND. | |
clear_leds(); | |
uint8_t highest_layer = get_highest_layer(layer_state); | |
// If layer is less than 0 (how?!) turn off all leds | |
if (highest_layer < 0) | |
{ | |
clear_leds(); | |
} | |
else if(highest_layer < 5) | |
{ | |
clear_leds(); | |
writePin(leds[highest_layer], 0); // If layer is between 0 and 4 (inclusive) turn on corrosponding led | |
} else | |
{ | |
set_leds(); // If layer is higher than 4, turn on all LEDs | |
} | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment