Go Down

Topic: expected constructor, destructor, or type conversion before '(' token (Read 200 times) previous topic - next topic

T-Mobile

Ok, so I'm not quit sure what's wrong here...

If someone could point out all my errors


Code: [Select]
int normalDistance = 200;
boolean triggered = false;
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
 pinMode(piezoPin, OUTPUT);
 pinMode(redLed, OUTPUT);
 pinMode(greenLed, OUTPUT);
 
 
void setup()
{
  Serial.begin (9600);
 
  long duration, distance;

  digitalWrite(redLed, HIGH);
  digitalWrite(greenPin);

  digitalWrite(piezoPin, HIGH);

  while(millis() < 5000)  {
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = (duration / 2) / 29.1;
    if (distance < normalDistance)  {
     
    }
  }

  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, LOW);
  digitalWrite(greenPin, LOW);
 
}

 void loop()  {
  if (triggered)  {
    digitalWrite(redLed, HIGH);
    digitalWrite(greenLed, LOW;
    tone(piezoPin, 635);
    delay(500);
    digitalWrite(redLed, LOW);
    digitalWrite(green, HIGH);
    tone(piezoPin, 912);
    delay(500);
  } else {
    long duration, distance;
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = (duration/2) / 29.1;
    if (distance < normalDistance - 10) {
      trigggered = true;
    }
    delay(20);
  }
 }

groundFungus

The pinMode statements belong in setup().  You can't use variables until after they are declared.  The pins need numbers, too (const byte echoPin = 3).  That is a start.  In the future, please include the full text of the error message(s).

Kudos for using code tags on your first post. 

There are a lot of other errors.  You have a greenLed variable then use greenPin or green.   

Code: [Select]
digitalWrite(greenPin);
Is there something missing there?

T-Mobile

Code: [Select]
int normalDistance = 200;
boolean triggered = false;

void setup()
{
  Serial.begin (9600);
 pinMode(trigPin, OUTPUT) = 13;
 pinMode (echoPin, INPUT) = 12;
 pinMode(piezoPin, OUTPUT) = 11;
 pinMode(redLed, OUTPUT) = 10;
 pinMode(greenLed, OUTPUT) = 8;
 
  long duration, distance;

  digitalWrite(redLed, HIGH);
  digitalWrite(greenPin);

  digitalWrite(piezoPin, HIGH);

  while(millis() < 5000)  {
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = (duration / 2) / 29.1;
    if (distance < normalDistance)  {
     
    }
  }

  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, LOW);
  digitalWrite(greenPin, LOW);
 
}

 void loop()  {
  if (triggered)  {
    digitalWrite(redLed, HIGH);
    digitalWrite(greenLed, LOW;
    tone(piezoPin, 635);
    delay(500);
    digitalWrite(redLed, LOW);
    digitalWrite(green, HIGH);
    tone(piezoPin, 912);
    delay(500);
  } else {
    long duration, distance;
    digitalWrite( trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite( trigPin, HIGH
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = (duration/2) / 29.1;
    if (distance < normalDistance - 10) {
      trigggered = true;
    }
    delay(20);
  }
 }


Hey I applied what you said in to the code. But there are still some errors
Quote
exit status 1
'trigPin' was not declared in this scope

groundFungus

You must declare a variable before you use it so the compiler knows how much memory to set aside.  In the case of variables that name pins, a pin number needs to be assigned.  Put the declaration and initialization in the space above setup(), like so, for all of your variables.

Code: [Select]
const byte trigPin = 13;  // or the pin number of your choice

Code: [Select]
pinMode(trigPin, OUTPUT) = 13;
Is just wrong.  You can't make up your own syntax.  Here for setting up pins.

There are still a lot of errors related to using variable that are not declared (grren, greenLed) and missing parameters from function calls.  Add to that list missing punctuation and typos.

T-Mobile

Code: [Select]
Like this????

//trigPin 13
//define echoPin 12
//define redLed 11
//define blueLed 10
//define piezoPin 8

int normalDistance = 200;
boolean triggered = false;

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(redLed, OUTPUT);
  pinMode(blueLed, OUTPUT);
  pinMode(piezoPin, OUTPUT);

  long duration, distance;

  digitalWrite(redLed, HIGH); // to indicate that the calibration is in process
  digitalWrite(blueLed, HIGH);

  digitalWrite(piezoPin, HIGH);

  while (millis() < 5000) {
      digitalWrite(trigPin, LOW);
      delayMicroseconds(2);
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin, LOW);
      duration = pulseIn(echoPin, HIGH);
      distance = (duration / 2) / 29.1;
      if (distance < normalDistance) {
        normalDistance = distance;
      }
   }

   digitalWrite(redLed, LOW); // finish calibration
   digitalWrite(blueLed, LOW);
   digitalWrite(piezoPin, LOW);
}

void loop() {
  if (triggered) {
    digitalWrite(redLed, HIGH);
    digitalWrite(blueLed, LOW);
    tone(piezoPin, 635);
    delay(500);
    digitalWrite(redLed, LOW);
    digitalWrite(blueLed, HIGH);
    tone(piezoPin, 912);
    delay(500);
  } else {
    long duration, distance;
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = (duration/2) / 29.1;
    if (distance < normalDistance - 10) {
      triggered = true;
    }
    delay(20);
  }
}

groundFungus

Code: [Select]
//trigPin 13
//define echoPin 12
//define redLed 11
//define blueLed 10
//define piezoPin 8

Not even close.

Code: [Select]
const byte trigPin = 13;
const byte echoPin = 12;
const byte piezoPin = 8;
const byte redLed = 11;
const byte blueLed = 10;

Is how to declare and initialize pin variables. Or you can use #define, but look up the syntax before you do.

Fix the pin declarations like I showed and the code will compile.  Good job fixing the variable, typo and punctuation problems.

T-Mobile

#6
Sep 13, 2017, 06:09 pm Last Edit: Sep 13, 2017, 06:35 pm by T-Mobile
I feel suuuper stupid right now!
Save me!


Code: [Select]
int trigPin 13
int  echoPin 12
int redLed 11
int blueLed 10
int piezoPin 8

int normalDistance = 200;
boolean triggered = false;

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(redLed, OUTPUT);
  pinMode(blueLed, OUTPUT);
  pinMode(piezoPin, OUTPUT);

  long duration, distance;

  digitalWrite(redLed, HIGH); // to indicate that the calibration is in process
  digitalWrite(blueLed, HIGH);

  digitalWrite(piezoPin, HIGH);

  while (millis() < 5000) {
      digitalWrite(trigPin, LOW);
      delayMicroseconds(2);
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin, LOW);
      duration = pulseIn(echoPin, HIGH);
      distance = (duration / 2) / 29.1;
      if (distance < normalDistance) {
        normalDistance = distance;
      }
   }

   digitalWrite(redLed, LOW); // finish calibration
   digitalWrite(blueLed, LOW);
   digitalWrite(piezoPin, LOW);
}

void loop() {
  if (triggered) {
    digitalWrite(redLed, HIGH);
    digitalWrite(blueLed, LOW);
    tone(piezoPin, 635);
    delay(500);
    digitalWrite(redLed, LOW);
    digitalWrite(blueLed, HIGH);
    tone(piezoPin, 912);
    delay(500);
  } else {
    long duration, distance;
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = (duration/2) / 29.1;
    if (distance < normalDistance - 10) {
      triggered = true;
    }
    delay(20);
  }
}


exit status 1
expected initializer before numeric constant

AWOL

#7
Sep 13, 2017, 06:14 pm Last Edit: Sep 13, 2017, 06:14 pm by AWOL
Code: [Select]
int trigPin 13
int  echoPin 12
int redLed 11
int blueLed 10
int piezoPin 8
Semicolons.
Assignments.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

groundFungus

Code: [Select]

const byte trigPin = 13;
const byte echoPin = 12;
const byte piezoPin = 8;
const byte redLed = 11;
const byte blueLed = 10;

int normalDistance = 200;
boolean triggered = false;


I showed how to declare and initialize the pins in reply #5.

T-Mobile

I have some problems with getting my door alarm to work.
Code: [Select]
const byte trigPin 13;
const byte  echoPin 12;
const byte redLed 11;
const byte greenLed 10;
1const byte piezoPin 8;

int normalDistance = 200;
boolean triggered = false;

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(redLed, OUTPUT);
  pinMode(blueLed, OUTPUT);
  pinMode(piezoPin, OUTPUT);

  long duration, distance;

  digitalWrite(redLed, HIGH); // to indicate that the calibration is in process
  digitalWrite(blueLed, HIGH);

  digitalWrite(piezoPin, HIGH);

  while (millis() < 5000) {
      digitalWrite(trigPin, LOW);
      delayMicroseconds(2);
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin, LOW);
      duration = pulseIn(echoPin, HIGH);
      distance = (duration / 2) / 29.1;
      if (distance < normalDistance) {
        normalDistance = distance;
      }
   }

   digitalWrite(redLed, LOW); // finish calibration
   digitalWrite(blueLed, LOW);
   digitalWrite(piezoPin, LOW);
}

void loop() {
  if (triggered) {
    digitalWrite(redLed, HIGH);
    digitalWrite(blueLed, LOW);
    tone(piezoPin, 635);
    delay(500);
    digitalWrite(redLed, LOW);
    digitalWrite(blueLed, HIGH);
    tone(piezoPin, 912);
    delay(500);
  } else {
    long duration, distance;
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = (duration/2) / 29.1;
    if (distance < normalDistance - 10) {
      triggered = true;
    }
    delay(20);
  }
}


I get these errors:
Quote
exit status 1
expected initializer before numeric constant,
exit status 1
'trigPin' was not declared in this scope

kenwood120s

Lines like this need an =

Code: [Select]
const byte trigPin 13; //wrong
const byte trigPin=13; //right

T-Mobile

thank!
It works, but when i tried to upload it this happend
Quote
Problemer ved opplasting til kortet. Se http://www.arduino.cc/en/Guide/Troubleshooting#upload for forslag.
is this normal?

AWOL

Quote
is this normal?
Yes, but starting THREE threads on the same topic isn't.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

PaulS

Quote
Se http://www.arduino.cc/en/Guide/Troubleshooting#upload for forslag.
Why didn't you? "Whine on the wrong part of the forum" is NOT one of the recommendations on that site.
The art of getting good answers lies in asking good questions.

TomGeorge

Hi,
Is this associated with this

https://forum.arduino.cc/index.php?topic=499978.0

What Arduino board are you using and have you got the correct com port selected?

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

Go Up