Exponential smoothing on expression pedal ADC (factor 8) to filter noise
This commit is contained in:
@@ -29,6 +29,7 @@ private:
|
||||
uint32_t last_read_time;
|
||||
|
||||
uint16_t current_raw;
|
||||
uint16_t smoothed_raw;
|
||||
uint16_t cal_min;
|
||||
uint16_t cal_max;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ 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)
|
||||
{
|
||||
@@ -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,7 +36,8 @@ 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);
|
||||
|
||||
if (new_value > current_value + HYSTERESIS ||
|
||||
new_value + HYSTERESIS < current_value ||
|
||||
|
||||
Reference in New Issue
Block a user