how to add arguments in here?

  arduino-ultra-sonic, c++

I used two ultrasonic sensors and I want to compare their measured distance to activate the servo motor. The error says

too few arguments to function long int readUltrasonicDistance(int, int)

and I already searched in google but none of is the same with my error and i do some changes on it but still the same. I’m not that good in programming and this is a project.

just part of the code where error can be seen:

#include <Servo.h>

int pos = 0;
Servo servo_9;

//int inches = 0;
int cm1 = 0;
int cm2 = 0;

//first ultrasonic sensor
long readUltrasonicDistance1(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT);  // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}

//second ultrasonic sensor
long readUltrasonicDistance2(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT);  // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}

void setup()
{
Serial.begin(9600);
servo_9.attach(9);

}

void loop()
{
// measure the ping time in cm
cm1 = 0.01723 * readUltrasonicDistance1(7);
cm2 = 0.01723 * readUltrasonicDistance2(6);
// convert to inches by dividing by 2.54
//inches = (cm / 2.54);

if (cm1 <= 250 && cm2 >= 250){
//Serial.print(inches);
//Serial.print("in, ");
Serial.print(cm1);
Serial.print("cm");
Serial.print(cm2);
Serial.println("cm");
delay(100); // Wait for 100 millisecond(s)

//for (pos = 0; pos <= 180; pos += 1) {
// tell servo to go to position in variable 'pos'
servo_9.write(180);
// wait 15 ms for servo to reach the position
//delay(5); // Wait for 15 millisecond(s)
//}
 }

else  {
//Serial.print(inches);
//Serial.print("in, ");
Serial.print(cm1);
Serial.println("cm");
Serial.print(cm2);
Serial.println("cm");
delay(100); // Wait for 100 millisecond(s)

//for (pos = 0; pos <= 180; pos += 1) {
// tell servo to go to position in variable 'pos'
servo_9.write(0);
// wait 15 ms for servo to reach the position
// delay(1); // Wait for 15 millisecond(s)
//}
}

}

Source: Windows Questions C++

LEAVE A COMMENT