Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Programming Questions & Help >> Syntax >> The Wiring syntax difference from Arduino
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1221315967

Message started by Juraj on 09/13/08 at 14:26:06

Title: The Wiring syntax difference from Arduino
Post by Juraj on 09/13/08 at 14:26:06
Hi,

I am the newbie with wiring. I was working a little with arduino before I found the bigger possiblities of wiring so I decided to change the platform for my small project.
I have bought wiring board and I tried to use the program which I made for Arduino.
I thought the wiring language is the same in Wiring and Arduino hardware, but when I checked it in Wiring software some mistakes was found and actually I cannot find why... :'(

Here is the problematic part of the code:
--------------------------------------------------------------
if (average <= 700 && average > 600)
   { analogWrite (ledPin1, 0); }
else if (average <= 600 &&  average > 500)
   { led1val = map (average, 600, 500, 0, 255);
    analogWrite (ledPin1, led1val);
   }
else  if ( average <=500 && average >= 400 )
   { led1val = map ( average, 400, 500, 0, 255);
   analogWrite (ledPin1, led1val);
   }
   else
   {analogWrite (ledPin1, 0);}  
-------------------------------------------------------------
error: expected unqualified-id before 'else'

There is some problem with īelseī syntax but I checked it carefully and I couldnīt find the reason.

Please can anyone tell me where is the mistake?

(all variables are well defined and the whole program is working in Arduino hardware with no problem.... but wiring cant take it.)


Please help! :)

Thanks a lot

Title: Re: The Wiring syntax difference from Arduino
Post by barragan on 09/14/08 at 02:49:37
This code works fine, so it must be somewhere else:

int average;
int ledPin1;
int led1val;


void setup()
{
 pinMode(48, OUTPUT);
}

void loop()
{
 digitalWrite(48, HIGH);
 delay(10);                   // wait 100ms for next reading
 digitalWrite(48, LOW);
 delay(10);



 if (average <= 700 && average > 600)
 {
   analogWrite (ledPin1, 0);
 }
 else if (average <= 600 &&  average > 500)
 {
   led1val = map (average, 600, 500, 0, 255);
   analogWrite (ledPin1, led1val);  
 }
 else  if ( average <=500 && average >= 400 )
 {
   led1val = map ( average, 400, 500, 0, 255);
   analogWrite (ledPin1, led1val);  
 }
 else
 {
   analogWrite (ledPin1, 0);
 }    
}

Title: Re: The Wiring syntax difference from Arduino
Post by Juraj on 09/14/08 at 15:59:46
thanks. I will try to test it more.
But this error message  error: expected unqualified-id before 'else'  appears only when I put this part of code into the program. When I delete it the program is OK.

What does mean  error: expected unqualified-id before 'else' ?



Title: Re: The Wiring syntax difference from Arduino
Post by barragan on 09/14/08 at 23:11:04
It is a syntax error, missing semicolon, etc. I canīt tell you without the complete program.

Title: Re: The Wiring syntax difference from Arduino
Post by Titus on 09/15/08 at 15:12:58
I remember having that a thousand times too!
It really irritated me. Try rewriting the program, are you using wiring 16?

Titus

Title: Re: The Wiring syntax difference from Arduino
Post by Juraj on 09/21/08 at 11:03:18
Hi,
yes I use wiring 16.
I have the exactly same problem with another program:
here is the problematic part:
----------------------------------------------------------------------
if (kompozice1 == HIGH && Tkompozice1 < 10)
  {
   Tkompozice1 = millis ();
  }
else if (kompozice1 == HIGH && Xkompozice1 < 1)
    {
     digitalWrite (LED,HIGH);
     sendMessage ('K',1101);
     Xkompozice1 += 1;        
    }    
else
  {
  digitalWrite (LED,LOW);
  Xkompozice1= 0;  
  }
-------------------------------------------------

The mistake is always the same - error: expected unqualified-id before 'else'

When I delete just the part with the "else if"  the whole problem disapear.
(I delete exactly this part):
----------------------------------------------------------------
else if (kompozice1 == HIGH && Xkompozice1 < 1)
    {
     digitalWrite (LED,HIGH);
     sendMessage ('K',1101);
     Xkompozice1 += 1;        
    }    
--------------------------------------------------------------

Please, whats wrong?
I am really mad of it. I am looking for every semicolon etc. alway and always and everything looks OK.

And its just this part. All variables are declared and program is runnig without the if else condition.

THANK A LOT! :)

Title: Re: The Wiring syntax difference from Arduino
Post by Titus on 09/21/08 at 13:36:13
Hi there again,

yep I had that one too, as mentioned above,

but try to change this:
(kompozice1 == HIGH && Xkompozice1 < 1)
into this:
((kompozice1 == HIGH) && (Xkompozice1 < 1))
And that for all the statements with an &&  / an ||

And another thing to try:
make the first else if an if only
so your program will look like this

if()
{

}
if()
{

}
else
{

}

Good luck with both ways, give 'em a try

Titus

Title: Re: The Wiring syntax difference from Arduino
Post by Juraj on 09/23/08 at 07:57:29
Uao!  :D
((kompozice1 == HIGH) && (Xkompozice1 < 1))

Yes it works!
Thank you very much! ;)

Title: Re: The Wiring syntax difference from Arduino
Post by Titus on 09/23/08 at 15:45:41
Welcome,

@Barragan, perhaps in the example section/the reference, you could state with a little line at the else comment, that it has to be like this:
((kompozice1 == HIGH) && (Xkompozice1 < 1))  with the double () 's?

Title: Re: The Wiring syntax difference from Arduino
Post by barragan on 09/23/08 at 15:53:03
Thatīs weird, it should work both ways, both Wiring & Arduino use the avr-gcc to compile, perhaps the versions are different, Iīll lokk in more detail.
Titus letīs setup a mailing list for developers, could you help setting it up?

Title: Re: The Wiring syntax difference from Arduino
Post by Juraj on 09/24/08 at 07:09:42
Yes its strange.But Iam happy that the solutions is found!

What I can tell you is that I was using Arduino NG rev.c with software Arduino0011.
And  Wiring 16 with Wiring mini and also big black.
But the problem appears also with new written code as I mentioned above.
I can post the whole code also, but what I shown here was that problematic parts.

Hope it helps.

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.