[+] Keyboard lights

This commit is contained in:
Hykilpikonna
2023-04-27 20:43:24 -04:00
parent 83d65430a7
commit ace84d0773
3 changed files with 49 additions and 0 deletions
+2
View File
@@ -24,6 +24,8 @@ const int MUX_SEL_OUT[NUM_MUX_SEL] = {14, 13, 12, 11};
const int LK_PIN = 2;
const int LK_LIGHTS_PER_METER = 60;
const float LK_NUM_METERS = 2;
const int LK_KEY_SPACING_MM = 7;
const int LK_KEY_LEN_MM = 15;
const int LK_NUM_LIGHTS = (int) round(LK_LIGHTS_PER_METER * LK_NUM_METERS);
// ========================================
+46
View File
@@ -0,0 +1,46 @@
//
// Created by Hykilpikonna on 4/21/23.
//
#include "config.h"
#include "Adafruit_NeoPixel.h"
class KeyboardLights
{
private:
Adafruit_NeoPixel led_key;
public:
KeyboardLights() : led_key(4, LK_PIN, NEO_GRB + NEO_KHZ800) {}
void begin()
{
led_key.begin();
}
/**
* Convert a key index to a light index
*
* The light strip's spacing doesn't match the keyboard's spacing, so we need to convert.
* Light strip info are defined by LK_LIGHTS_PER_METER and LK_NUM_LIGHTS.
* Key spacing info are defined by LK_KEY_SPACING_MM and LK_KEY_LEN_MM.
*
* @param key Key index from 0 to 60
* @return Light index
*/
static int keyToLight(int key)
{
return (int) (key * LK_KEY_SPACING_MM / LK_KEY_LEN_MM * LK_LIGHTS_PER_METER);
}
void hit(int key)
{
// 1. Calculate the starting index
int start = keyToLight(key);
Serial.printf("Key %d -> Light %d\n", key, start);
// 2. Set the color of the lights
led_key.setPixelColor(start, Adafruit_NeoPixel::ColorHSV(0, 255, 255));
}
};
+1
View File
@@ -4,6 +4,7 @@
#include "main.h"
#include "utils.h"
#include "panel.cpp"
#include "keyboard_lights.cpp"
u32 lasts[NUM_NOTES]; // variable to store the value coming from the sensor
u64 last_hit_times[NUM_NOTES];