Go Down

Topic: NEED HELP FAST!!!!! (Read 662 times) previous topic - next topic

electro12345

hello!

I dont understand this error that i keep gettin while i verify .


Projet_canon2.ino: In function 'void loop()':
Projet_canon2:26: error: expected `)' before ';' token





#include <Servo.h>
#include <math.h>
Servo myservo;


void setup()

{
  myservo.attach(17);
  pinMode (45,INPUT);
  Serial.begin(9600);
 
}

int tension1;
int tension2;
int angle;
void loop()
{
 
  tension1 =analogRead(45);
  Serial.print("distance: ");
  Serial.println((tension1+1)/2);
  delay(3000);
  tension2 =analogRead(45);
  Serial.print("distance: ");
  Serial.println((tension2+1)/2);
if (((tension1+1)/2)==((tension2+1)/2);
{
myservo.write (90-((asin(((tension1+1)/2)/60))/2));   
delay(1000);
analogWrite(44,HIGH);
delay(10);
analogWrite(44,LOW);
delay(10000);
}
 

}




need help asap!
Thanks!
 

Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

retrolefty

You failed at matching the proper number of ('s  with the correct number of )'s

Try:  if (((tension1+1)/2)==((tension2+1)/2)); not: if (((tension1+1)/2)==((tension2+1)/2);


Lefty

PGT

oh and also he did this

if (blabla==blblblb)[font=Verdana];[/font] {  }
note that red ; is wrong


if (your logical test here){actions sperated by; like another one here;}

if you logical test is more complex you can nest them like this if((a==b)||(c==d)){do things;}

retrolefty

He was probably coding too fast, and is why he needs help fast.  :D

Lefty

Nick Gammon

Code tags and proper formatting would help with all that. Hint.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

Code: [Select]

  tension1 =analogRead(45);


Which Arduino has analog input on pin 45?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

tuxduino


retrolefty


Code: [Select]

  tension1 =analogRead(45);


Which Arduino has analog input on pin 45?


Maybe one of CrossRoads "Barb barb barb, barb barbra arand" boards?

Sorry, I can't help myself sometimes.

Lefty

Jimmy60


Maybe one of CrossRoads "Barb barb barb, barb barbra arand" boards?

Sorry, I can't help myself sometimes.

Lefty


Thought you'd take a chance.  :smiley-mr-green:

danb35

The mismatched parens would be a lot easier to catch if you simplified the expressions, too.  Instead of this:
Code: [Select]
if (((tension1+1)/2)==((tension2+1)/2);
do this:
Code: [Select]
if (tension1 == tension2)
{
  do stuff
}


Alternatively, you could use a couple of other variables:
Code: [Select]
int distance1;
int distance2;
distance1 = (tension1+1)/2;
distance2 = (tension2+1)/2;

and then directly compare distance1 and distance2.  This might be the better way to go, as you use the tension1 expression at least three times in the code you posted--use it once to define distance1, and then use distance1 in the other places.

Similarly, this monstrosity:
Code: [Select]
(90-((asin(((tension1+1)/2)/60))/2))
could be simplified using the distance1 variable to this:
Code: [Select]
(90-((asin(distance1/60))/2))
...and possibly further, but looking at it makes my brain hurt.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy