[+] Run lights

This commit is contained in:
Hykilpikonna
2023-04-28 17:53:34 -04:00
parent 1823b0f5d2
commit 2258b7db6e
3 changed files with 11 additions and 13 deletions
+7 -2
View File
@@ -11,7 +11,7 @@ u64 last_hit_times[NUM_NOTES];
u32 bounce_delay = 50; // Minimum time between two hits
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 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);
Panel panel;
KeyboardLights keyboardLights;
void setup()
{
@@ -35,6 +36,7 @@ void setup()
Serial.printf("Initialized\r\n");
panel.begin();
keyboardLights.begin();
}
u64 fps_last_update = 0;
@@ -109,7 +111,10 @@ void on_sensor_update(int id, u64 time, u32 last, u32 current)
// Send MIDI message
// /hit <note> <velocity>
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)
+1 -8
View File
@@ -62,13 +62,6 @@ public:
}
private:
/**
* Initialize panel pins, encoders, and start the panel thread
*/
void setupPanel()
{
}
void readPanel()
{
const auto hue_interval = 512;
@@ -120,7 +113,7 @@ private:
onPotRead(i, pot);
// 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;
onPotChange(i, pot);
+3 -3
View File
@@ -5,9 +5,9 @@
#define u16 uint16_t
#define u32 uint32_t
#define u64 uint64_t
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) < 0 ? -(a) : (a))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define let auto
#define pinModeSafe(pin, mode) do { if (pin != -1) pinMode(pin, mode); } while (false)