[+] Better animation
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#include <queue>
|
||||
|
||||
const int ANIM_QUEUE_SIZE = 100;
|
||||
const int FRAME_DELAY_MS = 10;
|
||||
const int FRAME_DELAY_MS = 20;
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -83,6 +83,8 @@ public:
|
||||
|
||||
void begin()
|
||||
{
|
||||
pinModeSafe(LK_PIN, OUTPUT);
|
||||
|
||||
led_key.begin();
|
||||
xTaskCreate(loop, "loopLights", 4096, this, 1, &thread);
|
||||
}
|
||||
@@ -95,9 +97,31 @@ public:
|
||||
Serial.printf("Key %d -> Light %d\n", key, start);
|
||||
|
||||
// 2. Start animation
|
||||
|
||||
// Fade out for one light
|
||||
// for (int i = 0; i < 50; i++)
|
||||
// {
|
||||
// animation[(anim_index + i) % ANIM_QUEUE_SIZE][start] = Adafruit_NeoPixel::ColorHSV(0, 255, (50 - i) * 2);
|
||||
// }
|
||||
|
||||
// Fade out from the center to both sides
|
||||
int hue = random(0, 255);
|
||||
for (int i = 0; i < 25; i++)
|
||||
{
|
||||
// Pick a random hue
|
||||
Serial.printf("Hue: %d\n", hue);
|
||||
int v = (25 - i) * 2;
|
||||
int s = 255;
|
||||
auto frame = animation[(anim_index + i) % ANIM_QUEUE_SIZE];
|
||||
|
||||
frame[start] = Adafruit_NeoPixel::ColorHSV(100, s, v);
|
||||
|
||||
// Sides
|
||||
for (int j = 1; j <= min(i, 10); j++)
|
||||
{
|
||||
frame[(start + j) % LK_NUM_LIGHTS] = Adafruit_NeoPixel::ColorHSV(100, s, MAX(v - j * 2, 0));
|
||||
frame[(start - j + LK_NUM_LIGHTS) % LK_NUM_LIGHTS] = Adafruit_NeoPixel::ColorHSV(100, s, MAX(v - j * 2, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -16,8 +16,6 @@ let active_threshold = 400; // Minimum value to be considered as a hit
|
||||
|
||||
let led_refresh_on = false;
|
||||
|
||||
Adafruit_NeoPixel lk(LK_NUM_LIGHTS, LK_PIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
Panel panel;
|
||||
KeyboardLights keyboardLights;
|
||||
|
||||
@@ -25,12 +23,9 @@ void setup()
|
||||
{
|
||||
// Initialize pins
|
||||
pinModeSafe(LED_REFRESH, OUTPUT);
|
||||
pinModeSafe(LK_PIN, OUTPUT);
|
||||
for (int pin: MUX_IN) pinModeSafe(pin, INPUT);
|
||||
for (int pin: MUX_SEL_OUT) pinModeSafe(pin, OUTPUT);
|
||||
|
||||
lk.begin();
|
||||
|
||||
// Initialize serial
|
||||
Serial.begin(115200);
|
||||
Serial.printf("Initialized\r\n");
|
||||
|
||||
@@ -169,7 +169,7 @@ private:
|
||||
|
||||
void onPotChange(int id, u8 value)
|
||||
{
|
||||
Serial.printf("Potentiometer changed - id: %d, value: %d\r\n", id, value);
|
||||
// Serial.printf("Potentiometer changed - id: %d, value: %d\r\n", id, value);
|
||||
}
|
||||
|
||||
[[noreturn]] static void loopPanel(void* pvParameters)
|
||||
|
||||
Reference in New Issue
Block a user