error: 'too few arguments to function'

Hi there,

I am fairly new to coding and having a few issues trying to call a function. Would be very grateful if someone can explain why it wont compile, for when I try the error message appears: 'too few arguments to function ‘double discreteVal(int)’ and it highlights the line #define PUMPOUT 13? I have written this piece of code to convert a digital signal to a more analogous estimate.

#include <math.h>   //Used for the calculation of the discrete time filter

/*Glodal variables used for the discrete time filter*/
#define PUMPOUT 13 
int x, levelSensor; 
int levelSetting = 512;

void setup()
  pinMode (PUMPOUT, OUTPUT);    //sets pump as output

void loop()
  levelSensor = analogRead(0);
  if (levelSensor >= levelSetting)
    digitalWrite(PUMPOUT, HIGH);
    x = 1023;
    x = 0;
  /*A function to calculate a filtered value
for the flow rate of run-off*/
double discreteVal (int f) 
  int freq = 2000;
  int k = 1;  //Sets spring constant
  double omega_n = 2*M_PI/freq; 
  double m = k/(omega_n*omega_n);  // standard eq relating mass, stiffness and natural freq
  double c = 2*sqrt(m*k);  // standard eq relating mass, stiffness and damping
  int dt = 1;  // discrete time step
  double a = (m/(dt*dt) + c/dt + k);  //coeff of xi
  double b = (-2*m/(dt*dt) - c/dt);  // coeff of xi-1
  double cc = m/(dt*dt);  // coeff of xi-2
  double x_prev_prev, x_prev, x_now, dtfSignal;
  x_now = (f - (b*x_prev + cc*x_prev_prev))/a;  //rearranging EoM for any xi as a variable
  x_prev_prev = x_prev;   // cascade
  x_prev = x_now;  // cascade
  dtfSignal = x_now*2;
  return dtfSignal;

Many thanks

When you call discreteVal, you need to pass it your value of "f". However, you call it a couple of times correctly, but ignore the return value, so it isn't clear to me what your intentions are.

I thought I was doing this in the loop by saying:

x = 1023;

Doesnt that say to pass the value of x to the function and then in the function definition: double discreteVal (int f) The function takes x and assigns it to be an integer called f?

Im not sure I understand what your saying?

Iv also tried

f = 1023;

To the function

double discreteVal (int f)

But I get the same error.


How many arguments did you say this function needed?


I want to use the returned value later on to compare with another signal later on in the loop, ie:

if (discreteVal() <= value)  
    digitalWrite(PUMPIN, HIGH);
    digitalWrite(PUMPIN, LOW);

You've just done it again!

I want to use the returned value later on to compare with another signal later on in the loop, ie: You must still pass it a value!

Right so I think you can see Im a bit confused!

My intention (which is obviously not the case in my code) is to: 1) Check an analogue signal coming in and digitally write based on the comparison against the setting (I think that bit is Ok for me) 2) Depending on whether the digital is high or low, assign 'f' and then use that to calculate within 'double discreteVal()' 3)Then I want to use the value this function has just calculated later in the loop.

Does that make sense? From what your saying I can see that instead of using my calculated function variable instead im asking it to go back into the function? So how do you utilise the returned value?

Does that make sense?


So how do you utilise the returned value?

Just like you utilize the returned value from any other function, like analogRead, for instance.

double someVal = discreteVal(x);


So later on in the loop (after the calculation) must I assign a new variable: 'something' = discteteVal() and then use that 'something' (which is the returned value)?

Sorry PaulS, I seem to be writing my responses just after you have posted :blush:

So later on in the loop (after the calculation) must I assign a new variable

Not necessarily. You could do this:

if(discreteVal(x) > 185.0)
   // Do something

'something' = discteteVal()

The variable name does not go in quotes. And, it must be typed somewhere.

Right, many thanks for that, I will have a little tinker but might be back!