"exit status 1 'microsecondsToInches' was not declared in this scope"

Viewed 852

I'm trying to Program a Ultrasonic Sensor for a small project where I'm trying to design a level sensor. This is for a beginner mechatronic course that I'm taking right now. But it keeps giving me this error in line 42, bellow the void loop, that says:

"exit status 1'microsecondsToInches' was not declared in this scope"

#include <LiquidCrystal.h>
const int rs = 13, en = 12, d4 = 11, d5 = 10, d6 = 9, d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int LED1 = 7;
int LED2 = 6;
int LED3 = 5;
int LED4 = 4;
int Bocina = 3;
const int echoPin = 2;
const int trigPin = 1;

void setup() {

  pinMode (LED1, OUTPUT);
  digitalWrite(LED1, LOW);
  pinMode(LED2, OUTPUT);
  digitalWrite(LED2, LOW);
  pinMode(LED3, OUTPUT);
  digitalWrite(LED3, LOW);
  pinMode(LED4, OUTPUT);
  digitalWrite(LED4, LOW);
  pinMode(Bocina, OUTPUT);
  lcd.begin(16, 2);
}

void loop() {

  long duration;
  long inches;
  long cm;
  lcd.clear();
  pinMode(trigPin, OUTPUT);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
  //cm = ( duration / 29 ) / 2;
  //inches = cm * 0.393701;
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  lcd.setCursor(5, 0);
  lcd.print("Nivel:");
  lcd.setCursor(0, 1);
  lcd.print(inches);
  lcd.print(" in");
}

if (inches >= 4) {
  digitalWrite (LED1, HIGH);
  digitalWrite (LED2, HIGH);
  digitalWrite (LED3, HIGH);
  digitalWrite (LED4, LOW);
}

else if (inches >= 3) {
  digitalWrite (LED1, LOW);
  digitalWrite (LED2, HIGH);
  digitalWrite (LED3, HIGH);
  digitalWrite (LED4, LOW);
}

else if (inches >= 2) {
  digitalWrite (LED1, LOW);
  digitalWrite (LED2, LOW);
  digitalWrite (LED3, HIGH);
  digitalWrite (LED4, LOW);
  tone(3, 2000, 100);
  delay(1000);
}

else if (inches >= 1) {
  digitalWrite (LED1, LOW);
  digitalWrite (LED2, LOW);
  digitalWrite (LED3, LOW);
  digitalWrite (LED4, HIGH);
  tone(3, 2000);

}

}
long microsecondsToInches(long microseconds) {
  return (microseconds / 74) / 2;
}
long microsecondsToCentimeters(long microseconds) {
  return (microseconds / 29) / 2;
}

Can some explain me what's the problem here? And how to solve it?

Thanks in advance :)

1 Answers

Arduino didn't correctly generate the function prototypes, as you have a syntax error within the file.

You have an extra closing bracket }, right before you declare the microsecondsToInches function. Just remove it and you should be good to go

Also welcome to stack overflow!

Related