Compare commits
9
Commits
dfa339a9b9
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20e9d4a08d | ||
|
|
8aad6fdccd | ||
|
|
3558bb1050 | ||
|
|
cadb29f234 | ||
|
|
f055bad4ac | ||
|
|
1dec81e329 | ||
|
|
17def39f93 | ||
|
|
4f58d4b8e6 | ||
|
|
33c9dd10c0 |
@@ -24,11 +24,11 @@ private:
|
||||
uint8_t midi_channel;
|
||||
uint8_t midi_cc;
|
||||
|
||||
static const uint8_t HYSTERESIS = 3;
|
||||
static const uint16_t READ_INTERVAL_MS = 5;
|
||||
uint32_t last_read_time;
|
||||
|
||||
uint16_t current_raw;
|
||||
uint16_t smoothed_raw;
|
||||
uint16_t cal_min;
|
||||
uint16_t cal_max;
|
||||
|
||||
|
||||
+1
-4
@@ -144,10 +144,7 @@ void AppTask::process_switch_event(uint8_t switch_id, bool pressed) {
|
||||
uint8_t cc_num = cc_map[i];
|
||||
// Use palette index 127 (magenta) for visible feedback
|
||||
uint8_t value = pressed ? 127 : 0;
|
||||
|
||||
if (pressed) {
|
||||
midi_transport->send_cc(channel, cc_num, value);
|
||||
}
|
||||
midi_transport->send_cc(channel, cc_num, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+16
-13
@@ -10,8 +10,9 @@ ExpressionPedal::ExpressionPedal(uint8_t adc_pin)
|
||||
, midi_cc(4)
|
||||
, last_read_time(0)
|
||||
, current_raw(0)
|
||||
, smoothed_raw(0)
|
||||
, cal_min(36)
|
||||
, cal_max(1180)
|
||||
, cal_max(950)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -21,7 +22,8 @@ void ExpressionPedal::begin() {
|
||||
pinMode(adc_pin, INPUT);
|
||||
delay(10);
|
||||
current_raw = analogRead(adc_pin);
|
||||
current_value = adc_to_midi(current_raw);
|
||||
smoothed_raw = current_raw;
|
||||
current_value = adc_to_midi(smoothed_raw);
|
||||
last_sent_value = current_value;
|
||||
Serial.printf("[EXP] Starting: raw ADC=%d -> MIDI=%d (cal: %d-%d)\n",
|
||||
current_raw, current_value, cal_min, cal_max);
|
||||
@@ -34,18 +36,19 @@ void ExpressionPedal::update(UsbMidiTransport& midi) {
|
||||
last_read_time = now;
|
||||
|
||||
current_raw = analogRead(adc_pin);
|
||||
uint8_t new_value = adc_to_midi(current_raw);
|
||||
smoothed_raw = (smoothed_raw * 7 + current_raw + 4) / 8;
|
||||
uint8_t new_value = adc_to_midi(smoothed_raw);
|
||||
current_value = new_value;
|
||||
|
||||
if (new_value > current_value + HYSTERESIS ||
|
||||
new_value + HYSTERESIS < current_value ||
|
||||
(new_value != current_value && (new_value == 0 || new_value == 127))) {
|
||||
current_value = new_value;
|
||||
}
|
||||
|
||||
if (current_value != last_sent_value) {
|
||||
last_sent_value = current_value;
|
||||
midi.send_cc(midi_channel, midi_cc, current_value);
|
||||
Serial.printf("[EXP] CC%d: %d (raw ADC: %d)\n", midi_cc, current_value, current_raw);
|
||||
// Proportional catch-up: send midpoint rounded up each update.
|
||||
// Rejects ±1 stationary jitter but converges to exact value on movement
|
||||
// (e.g., 0→127 converges in ~35ms).
|
||||
if (current_value > last_sent_value + 1) {
|
||||
last_sent_value = (last_sent_value + current_value + 1) / 2;
|
||||
midi.send_cc(midi_channel, midi_cc, last_sent_value);
|
||||
} else if (current_value < last_sent_value - 1) {
|
||||
last_sent_value = (last_sent_value + current_value) / 2;
|
||||
midi.send_cc(midi_channel, midi_cc, last_sent_value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ UsbMidiTransport midi_transport;
|
||||
AppTask controller(&led_driver, &switch_driver, &midi_transport);
|
||||
ExpressionPedal exp_pedal(4);
|
||||
|
||||
volatile uint32_t flash_latency = 55; // ms delay to compensate for Loopy Pro rendering
|
||||
volatile uint32_t flash_latency = 0;
|
||||
volatile uint8_t beats_per_bar = 4; // change to match your project's time signature
|
||||
|
||||
TaskHandle_t midi_task_handle = NULL;
|
||||
|
||||
Reference in New Issue
Block a user