Using Multi Map (multiMap)

Trying to create a little program to monitor a few things on a treadmill and having a problem. Here is the code I have come up with:

My code should be attached if I did that much correctly. Least I forget this is for an Arduino Uno.

The multiMsp relates to a PWM percentage in. The PWM to the motor relates to the MPH (Miles Per Hour) of the belt and as can be seen it is a non linear function. I want a Serial.print at the bottom to read out my MPH and for the love of me can't get it. Everything else reads out fine. I am aware many of the math functions could have been shortened but left it as is so the person who uses this may better understand all the steps. Eventually the data will be displayed on a 4 X 20 LCD but for now I just am happy with the serial monitor.

I am not a programmer type, I am a 70 year old retired EE who years ago, at best, wrote a few small software routines for data acquisition using VB 6.0. Playing around with micro-controllers keeps me busy in old age, not that 70 is old.

So if any of you kind people could tell me how to get that last step I would most appreciate it.

One more question. I attached my .ino file using attach. Can code tags be used as

Thank You
Ron

Freq_Count4.ino (1.52 KB)

Hi , have a look at the top post re using code tags ( link in that post “ how to ...”) , that should get you started for posting code .

I am not familiar with the multiMap() function so I cannot advise you there.

One obvious mistake is in regards to datatype's. specifically your out[] array

 int out[] = {0.0,0.3,0.5,0.7,1.0,1.3,1.6,1.95,2.3,2.7,3.1,3.5,3.9,4.2,4.65,5.1,5.5,5.0,6.3,6.65,7.1,7.5,7.9,8.3,8.65,9.05,9.45,9.75,10.05,10.55};

you have it designated as an array of int's which can only contain whole numbers(for ex. 5 ,6 ,7)
For numbers with a decimal component you need to use float(for ex. 5.0 ,6.1 ,7.25)
This will also require a change in the parameters for multiMap()

float multiMap(float val, int* _in, float* _out, uint8_t size);

finally MPH will also have to be a float.
This compiles with these changes but is untested. I do not know if multiMap() is capable of working with floats.

Thanks for the replies. OK as to whole numbers so I'll get some floats in there, much appreciated on that.

I will also do more reading. :slight_smile:

Ron