[F] Fix key timing logic

This commit is contained in:
Hykilpikonna
2023-04-20 20:47:09 -04:00
parent 2855d257c8
commit 1d0c3f7a8e
+11 -11
View File
@@ -39,27 +39,27 @@ void loop()
{ {
val pin = DRUMSTICK_PINS[i]; val pin = DRUMSTICK_PINS[i];
val value = analogRead(pin) / 8; val value = analogRead(pin) / 8;
val last = LAST_VALUES[i];
LAST_VALUES[i] = value;
// If the value is different from the last value, update it // If the value is different from the last value, update it
if (value != LAST_VALUES[i]) if (value != last)
{ {
// If it's less than the threshold // If it's greater than the threshold
if (value < threshold) if (value > threshold)
{ {
// If the last value was greater than the threshold, it means the drumstick was just hit send(";%d;%d", i, value);
if (LAST_VALUES[i] > threshold)
// If the last value was less than the threshold, it means the drumstick was just hit
if (last < threshold)
send("Hit:+%d", i); send("Hit:+%d", i);
} }
else else
{ {
send(";%d;%d", i, value); // If the last value was greater than the threshold, it means the drumstick was just released
if (last > threshold)
// If the last value was less than the threshold, it means the drumstick was just released
if (LAST_VALUES[i] < threshold)
send("Hit:-%d", i); send("Hit:-%d", i);
} }
} }
LAST_VALUES[i] = value;
} }
} }