Spline library, errors compiling example code

Hi All,

I tried adding the spline library GitHub - kerinin/arduino-splines: 1D splines for the arduino environment to my project and it doesn't want to compile.
The first error I got was undefined ref to WProgram.h, which I changed to Arduino.h in the cpp and h files.

I am just trying to compile the example pde

#include <spline.h>

Spline tempCurve;

void setup(void) {
  Serial.begin(9600);
  
  double x[7] = {-1,0,1,2,3,4, 5};
  double y[7] = { 0,0,8,5,2,10,10};
  tempCurve.setPoints(x,y,7);
  tempCurve.setDegree( Catmull );
  
  for( float i = 0; i <= 4; i+= .1 ) {
    float temp = tempCurve.value(i);
    Serial.print(i);
    for(float j=0; j<= temp; j += .2) {
      Serial.print( "*" );
    }
    Serial.print( "   " );
    Serial.println(temp);
  }
}

void loop(void) {

}

But now I try to compile and get: "no matching function for call to Spline..."

sketch_mar31a.cpp: In function 'void setup()':
sketch_mar31a:9: error: no matching function for call to 'Spline::setPoints(double [7], double [7], int)'
C:\Users\Public\Documents\arduino-1.0\libraries\spline/spline.h:21: note: candidates are: void Spline::setPoints(float*, float*, int)
C:\Users\Public\Documents\arduino-1.0\libraries\spline/spline.h:22: note: void Spline::setPoints(float*, float*, float*, int)

What can I do to get this library working?

Thanks in advance!

There is no function which takes double arrays - you have to use float arrays

double x[7] = {-1,0,1,2,3,4, 5};
  double y[7] = { 0,0,8,5,2,10,10};
  tempCurve.setPoints(x,y,7);

the example uses doubles for the x and y arrays, but the library wants float, see error output: "note: candidates are: void Spline::setPoints(float*, float*, int)"

try

float x[7] = {-1,0,1,2,3,4, 5};
  float y[7] = { 0,0,8,5,2,10,10};

It should be noted that floats and doubles, on the Arduino, are the same size, so no loss of precision will occur using floats instead of doubles.

THANKS!

Arduino error readouts are usually pretty intimidating :slight_smile: