Ribbon Pot Midi Generation

hello,

I have been working on creating midi notes and other midi commands from a softPot ribbon potentiometer. The only issue I am having, is that it is not very accurate. I achieve precise accuracy with rotary pots; however, I am having difficulty with optimizing my code for a softpot. Essentially, I wish to know exactly where middle C is everytime and have equal intervals between each note (this right now is a bit erratic)...

As seen in the code below, I am attempting to define a starting note and an ending note for an interval range on a 500mm pot. I have seen this quote from tom scarff: "For a 18 inch (500 mm) long ribbon controller with 3/4" finger, number of notes would be 24"

This statement makes sense, but I need to figure out some equation or subroutine to calibrate this. For now I am using a -1 to t range so that I don't hit notes too close to each other; however, this is not musically accurate.

#include <ardumidi.h>

/* Pin constants */
const int positionSensorPin = A0;

#define START_NOTE                60
#define END_NOTE                   84 //24 note range
#define RIBBON_MIDI_CHANNEL_0     1

//----------VARIABLES----------//
int note; //0-1023 position from positionSensorPin
int notePrev = 0;
int velocity = 100;

//int noteStateFlag = 0;
/* 0= noNote 1=midi_on 2=pitch_bend 3=noteOff */

void setup() {
  Serial.begin(115200);
}

void loop() {

  note = analogRead(positionSensorPin) / 8;
  note = map(note, 0, 127, 50, 100);

  // potentiometer could be too sensitive and give different (+-1) values.
  if ((note - notePrev) > 1 || (note - notePrev) < -1) {
    // has the value changed?
    if (note != notePrev) {
      midi_note_on(RIBBON_MIDI_CHANNEL_0, note, velocity);
      notePrev = note;
    }
    else {
      midi_note_off(RIBBON_MIDI_CHANNEL_0, note, velocity);
    }
  }
}[code]

So, with more testing, I am realizing that the Ribbon returns to its starting note after a note is released. Furthermore, my DAW software is not registering all of the incoming MIDI messages as they are not being played consistently even though I see that they are sent in Hairless MIDI.
With this code, I am able to define the the midi note off -

  if (note != notePrev) {
    midi_note_on(RIBBON_MIDI_CHANNEL_0, note, velocity);
    //register the last note played to stop it later
    notePrev = note;
    midi_note_off(RIBBON_MIDI_CHANNEL_0, note, velocity);
  }

The only issue is that it returns to the starting note, plays it and then turns it off. I need to eliminate this somehow.