Pages: [1]   Go Down
Author Topic: NEED HELP FAST!!!!!  (Read 550 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
 
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18728
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Read this before posting a programming question
Logged


Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 219
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

oh and also he did this

if (blabla==blblblb); {  }
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;}
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

He was probably coding too fast, and is why he needs help fast.  smiley-grin

Lefty
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18728
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code tags and proper formatting would help with all that. Hint.
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18728
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  tension1 =analogRead(45);

Which Arduino has analog input on pin 45?
Logged


Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

CTRL-T
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  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
Logged

Saskatchewan
Offline Offline
Sr. Member
****
Karma: 19
Posts: 364
When the going gets weird, the weird turn pro. - Hunter S. Thompson
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 107
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Alternatively, you could use a couple of other variables:
Code:
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:
(90-((asin(((tension1+1)/2)/60))/2))
could be simplified using the distance1 variable to this:
Code:
(90-((asin(distance1/60))/2))
...and possibly further, but looking at it makes my brain hurt.
Logged

Pages: [1]   Go Up
Jump to: