Blending/Interpolating between array values


hi, guys, still pretty new whole arduino , programming thing, anyways background:

i've got mass-air-flow sensor, puts out 0-5v signal depending on rate of air flowing through it. has non-linear response, requiring use of array convert voltage kg/hr flow. i've setup so:
code: [select]

int maft[20]={3,11,20,45,83,113,190,280,380,520,750,960,1230,1600,1900,2500,3000,3600,4200,5000};
mafv = map(analogread(1),0, 1023, 0, 19);
maff = maft[mafv]; //creates kg/hr number later functions use calculations

it works enough, towards high end abrupt transitions. wondering how i'd go creating function allows "maff" blend between 2 adjacent maft values, preferably in weighted manner? ex: if remapped adc value "18.5", it'd average 4200 , 5000 together. if value 18.75, it'd blend 75% of 5000 25% of 4200. (i know map function generates whole integers, trying show example of i'm trying do)

if aren't in hurry use floating-ppoin math:
code: [select]

    float entry = (analogread(1) * 19 ) / 1024.0;  // value 0 18.999
    float fraction = entry - (int) entry;  // subtract out integer part
    float value =  maft[(int)entry] + (maft[(int)entry+1] - maft[(int)entry]) * fraction;


Arduino Forum > Using Arduino > Programming Questions > Blending/Interpolating between array values


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support