Help with function declaration

Hello, so I’m having some problem with my arduino code. I’m trying to use a variable from reading values from an ultrasonic range finder (referred to as newval in my code) and then using this as input for a void type function (specifically the function ‘blink1’ or ‘blink2’). But I get the error: variable or field ‘blink1’ declared void

The following is my code:

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 

const int pingPin = 7;  // set ping pin
const int led1 = 11;   // set led pin
const int led2 = 10;   // set led pin

int minval = 8000;     // initialize variable
int oldval = 6000;     // initialize variable
int newval = 7000;    // initialize variable
int savpos = 90;      // initialize position variable
int savpos2 = 90;     // initialize position variable
int i = 0;           // initialize variable
int k = 0;          // initialize variable
int turnonoff = 0;  // on-off switch for the leds
 
void setup() 
{ 
  Serial.begin(9600);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
} 
 
 
void loop() 
{ 
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(2);
    newval = ping();
    Serial.print("new value ");
    Serial.print(newval);
    Serial.print("old value ");
    Serial.print(oldval);
    Serial.print("saved pos is: ");
    Serial.print(savpos);
    Serial.println();
    if(newval == 0){
      newval = 5000;
    }
    turnonoff = turnonoff(newval,turnonoff);
    if(turnonoff == 1){
      blink1(newval);
      blink2(newval);
    }
    minval = min(newval,oldval);
    if(minval == newval){
      oldval = newval;
      savpos = pos;
    }
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
  
  savpos2 = savpos;
  
  myservo.write(savpos);
  
  delay(4000+i*2000);
  
  oldval = 5000; //reinitalize
  
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(2);
    newval = ping();
    Serial.print("new value ");
    Serial.print(newval);
    Serial.print("old value ");
    Serial.print(oldval);
    Serial.print("saved pos is: ");
    Serial.print(savpos);
    Serial.println();
    if(newval == 0){
      newval = 5000;
    }
    turnonoff = turnonoff(newval,turnonoff);
    if(turnonoff == 1){
      blink1(newval);
      blink2(newval);
    }
    minval = min(newval,oldval);
    if(minval == newval){
      oldval = newval;
      savpos = pos;
    } 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
  
  if(savpos2 == savpos){
    i = i + 1;
    i = max(i,28);
  }
  else{
    i = 0;
  }
  
  myservo.write(savpos);
  
  delay(4000+i*2000);
} 

int ping()
{
  // establish variables for duration of the ping, 
  // and the distance result in inches and centimeters:
  long duration, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

  // convert the time into a distance
  cm = microsecondsToCentimeters(duration);
  delay(100);
  return cm;
}

long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
} 

void blink1(newval){
  if(newval > 20){
    k = map(newval,1,400,0,255);
    analogWrite(led1,k);
    analogWrite(led2,k); 
  }
}

void blink2(newval){
  if(newval > 9 && newval < 20){
    analogWrite(led1, 0);
    analogWrite(led2, 255);
    delay(500);
    analogWrite(led1, 255);
    analogWrite(led2, 0);
  }
}

int OffOn(newval, turnonoff){
  if(newval < 9 && newval > 1){
    if(turnonoff == 0){
      turnonoff = 1;
    }
    else{
      turnonoff = 0;
    }
  }
  return turnonoff;
}

I think I’m just making a small simple mistake. Maybe I should be using something other than void to declare this function.
Thanks for any help.

a small simple mistake

I would call it a big simple mistake, and I realize that the error message isn't particularly informative unless you have seen something like that a few hundred times.

There is nothing wrong with declaring a function to have a "void" return data type if it doesn't return anything. That's what "void" is for.

However...

When you define/declare a function with parameters, you must give the data type of the parameters.

For example:

void blink1(int newval){
.
.
.

Same for blink2, OffOn.

Regards,

Dave

Okay, that worked. Thank you very much. :)

In the example you posted, it says:turnonoff = turnonoff(newval,turnonoff);Should that be:turnonoff = OffOn(newval,turnonoff); ?

-Mike

Yeah, it should be. I caught that mistake when I was adding the int's. good catch and thanks though.