     velocity = velocity > 4 ? velocity : 0; // Force sensor uncertainty
 
     potentiometer_reading = analogRead(POTENTIOMETER_PIN);
+
+    if(!potentiometer_reading) {
+        return;
+    }
+
+    potentiometer_reading_average.add(potentiometer_reading);
+    potentiometer_reading = potentiometer_reading_average.average();
 
     note = potentiometer_reading * RANGE / 1023;
     pitch = 127 / 2 * (potentiometer_reading * (RANGE / 1023.0) - note) + 127 / 2;

#include <math.h>
#include "moving_average.h"

#define DEBUG

#define     FORCE_SENSOR_PIN 0
#define     POTENTIOMETER_PIN 1
#define 	MIDI_PITCHBEND_MIN   -8192.0
#define 	MIDI_PITCHBEND_MAX   8191.0


        last_midi_note = -1;
        last_midi_velocity = 0;
    }

    #ifdef DEBUG
    Serial.print("Playing note #");
    Serial.print((int) last_midi_note);
