Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumProgramming Questions & HelpSyntax › The Wiring syntax difference from Arduino

Page Index Toggle Pages: 1
The Wiring syntax difference from Arduino (Read 14933 times)
09/13/08 at 14:26:06

Juraj   Offline
YaBB Newbies
still learning...
Czech republic, Brno

Posts: 11
*
 
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... Cry

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

Thanks a lot
 
IP Logged
 
Reply #1 - 09/14/08 at 02:49:37

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
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);
  }   
}
 
IP Logged
 
Reply #2 - 09/14/08 at 15:59:46

Juraj   Offline
YaBB Newbies
still learning...
Czech republic, Brno

Posts: 11
*
 
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
' ?


 
IP Logged
 
Reply #3 - 09/14/08 at 23:11:04

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
It is a syntax error, missing semicolon, etc. I can´t tell you without the complete program.
 
IP Logged
 
Reply #4 - 09/15/08 at 15:12:58

Titus   Offline
Full Member
Wiring Soccer Robot!
Amsterdam

Posts: 176
***
 
I remember having that a thousand times too!
It really irritated me. Try rewriting the program, are you using wiring 16?

Titus
 

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #5 - 09/21/08 at 11:03:18

Juraj   Offline
YaBB Newbies
still learning...
Czech republic, Brno

Posts: 11
*
 
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! Smiley
 
IP Logged
 
Reply #6 - 09/21/08 at 13:36:13

Titus   Offline
Full Member
Wiring Soccer Robot!
Amsterdam

Posts: 176
***
 
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
 

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #7 - 09/23/08 at 07:57:29

Juraj   Offline
YaBB Newbies
still learning...
Czech republic, Brno

Posts: 11
*
 
Uao!  Cheesy
((kompozice1 == HIGH) && (Xkompozice1 < 1))

Yes it works!
Thank you very much! Wink
 
IP Logged
 
Reply #8 - 09/23/08 at 15:45:41

Titus   Offline
Full Member
Wiring Soccer Robot!
Amsterdam

Posts: 176
***
 
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?
 

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #9 - 09/23/08 at 15:53:03

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
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?
 
IP Logged
 
Reply #10 - 09/24/08 at 07:09:42

Juraj   Offline
YaBB Newbies
still learning...
Czech republic, Brno

Posts: 11
*
 
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.
 
IP Logged
 
Page Index Toggle Pages: 1