[+] Run lights
This commit is contained in:
@@ -11,7 +11,7 @@ u64 last_hit_times[NUM_NOTES];
|
|||||||
u32 bounce_delay = 50; // Minimum time between two hits
|
u32 bounce_delay = 50; // Minimum time between two hits
|
||||||
|
|
||||||
let max_sensor = 4096;
|
let max_sensor = 4096;
|
||||||
let max_threshold = 2000;
|
let max_threshold = 3000;
|
||||||
let active_threshold = 400; // Minimum value to be considered as a hit
|
let active_threshold = 400; // Minimum value to be considered as a hit
|
||||||
|
|
||||||
let led_refresh_on = false;
|
let led_refresh_on = false;
|
||||||
@@ -19,6 +19,7 @@ let led_refresh_on = false;
|
|||||||
Adafruit_NeoPixel lk(LK_NUM_LIGHTS, LK_PIN, NEO_GRB + NEO_KHZ800);
|
Adafruit_NeoPixel lk(LK_NUM_LIGHTS, LK_PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
|
||||||
Panel panel;
|
Panel panel;
|
||||||
|
KeyboardLights keyboardLights;
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
@@ -35,6 +36,7 @@ void setup()
|
|||||||
Serial.printf("Initialized\r\n");
|
Serial.printf("Initialized\r\n");
|
||||||
|
|
||||||
panel.begin();
|
panel.begin();
|
||||||
|
keyboardLights.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 fps_last_update = 0;
|
u64 fps_last_update = 0;
|
||||||
@@ -109,7 +111,10 @@ void on_sensor_update(int id, u64 time, u32 last, u32 current)
|
|||||||
// Send MIDI message
|
// Send MIDI message
|
||||||
// /hit <note> <velocity>
|
// /hit <note> <velocity>
|
||||||
Serial.printf("/hit %d %d\r\n", notes[id].midi,
|
Serial.printf("/hit %d %d\r\n", notes[id].midi,
|
||||||
min((last - active_threshold) * 127 / (max_threshold - active_threshold), 127));
|
MIN((last - active_threshold) * 127 / (max_threshold - active_threshold), 127));
|
||||||
|
|
||||||
|
// Lights
|
||||||
|
keyboardLights.hit(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (last > active_threshold)
|
else if (last > active_threshold)
|
||||||
|
|||||||
@@ -62,13 +62,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
|
||||||
* Initialize panel pins, encoders, and start the panel thread
|
|
||||||
*/
|
|
||||||
void setupPanel()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void readPanel()
|
void readPanel()
|
||||||
{
|
{
|
||||||
const auto hue_interval = 512;
|
const auto hue_interval = 512;
|
||||||
@@ -120,7 +113,7 @@ private:
|
|||||||
onPotRead(i, pot);
|
onPotRead(i, pot);
|
||||||
|
|
||||||
// If the state is changed, call potentiometer callback
|
// If the state is changed, call potentiometer callback
|
||||||
if (abs(pot_states[i] - pot) > 4)
|
if (ABS(pot_states[i] - pot) > 4)
|
||||||
{
|
{
|
||||||
pot_states[i] = pot;
|
pot_states[i] = pot;
|
||||||
onPotChange(i, pot);
|
onPotChange(i, pot);
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
#define u16 uint16_t
|
#define u16 uint16_t
|
||||||
#define u32 uint32_t
|
#define u32 uint32_t
|
||||||
#define u64 uint64_t
|
#define u64 uint64_t
|
||||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
#define max(a, b) ((a) > (b) ? (a) : (b))
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
#define abs(a) ((a) < 0 ? -(a) : (a))
|
#define ABS(a) ((a) < 0 ? -(a) : (a))
|
||||||
#define let auto
|
#define let auto
|
||||||
|
|
||||||
#define pinModeSafe(pin, mode) do { if (pin != -1) pinMode(pin, mode); } while (false)
|
#define pinModeSafe(pin, mode) do { if (pin != -1) pinMode(pin, mode); } while (false)
|
||||||
|
|||||||
Reference in New Issue
Block a user