Go Down

Topic: "Error Message" Interpretation (Read 2394 times) previous topic - next topic

Chez7

Hi folks, I am banging my head against a brick wall trying to interpret "error messages". Is there a straight forward dictionary of "error messages"? in my attempts at searching my "error messages" I get lots of good examples of other peoples projects with the same "error message" as mine, but does not help me as the answers are not relevant to my project. I am trying to "stop" or "end" my sketch after one run and was advised to use " void loop() { } ."  each attempt gave error message, " redefinition of void loop" or "unqualified-id", What exactly do they mean? Help would be much appreciated. Chez7.

ElectricWater

Put your main code in void setup() and then put nothing in void loop(). With nothing inside of void loop there will be no repeating code and it just loops forever.
Inconveniencing electrons one drop at a time

Chez7

Thanks ElectricWater, will try that Chez7.

Chez7

Hi Electric Water, Tried your suggestion, not working. When you say void loop() "put nothing in it " I assume you mean type "void loop() { } ". I have tried this where void loop currently sits, no go, I have shifted it to end of sketch, still no go. Where am I going wrong. Im sure theres a simple solution, Cheers
                                                                                                                                     Chez7.



//Example 01 : Blinking LED

# define LED 13  // LED connected to
                //digital pin 13
               
void setup ()

{
pinMode( LED, OUTPUT ) ;   // Sets the digital pin as output.
 
}

void loop()
{
  digitalWrite( LED, HIGH);  //Turn the Led on
 
  delay(4000);               // Waits for
 
  digitalWrite(LED, LOW);    // Turns led off
 
  delay (4000) ;             // Waits for 
 
   digitalWrite( LED, HIGH);  //Turn the Led on
   
   delay(500);               // Waits for

digitalWrite(LED, LOW);    // Turns led off

  delay(500);               // Waits for
 
}
 


RoyK

#4
May 17, 2011, 02:53 am Last Edit: May 17, 2011, 03:02 am by RoyK Reason: 1
There are a couple of ways to do what you want.
One way is to put all your code into setup like this:

Code: [Select]
void setup ()

{
  pinMode( LED, OUTPUT ) ;   // Sets the digital pin as output.
  digitalWrite( LED, HIGH);  //Turn the Led on

 delay(4000);               // Waits for

 digitalWrite(LED, LOW);    // Turns led off

 delay (4000) ;             // Waits for

  digitalWrite( LED, HIGH);  //Turn the Led on
 
  delay(500);               // Waits for

digitalWrite(LED, LOW);    // Turns led off

 delay(500);               // Waits for

}

void loop()
{

}


Another way is to add while(1)    or for( ; ; ) at the end of loop. Either of these is always satisfied so the code will hang at those lines.

Code: [Select]
# define LED 13  // LED connected to
               //digital pin 13
             
void setup ()

{
  pinMode( LED, OUTPUT ) ;   // Sets the digital pin as output.
}

void loop()
{
  digitalWrite( LED, HIGH);  //Turn the Led on

 delay(4000);               // Waits for

 digitalWrite(LED, LOW);    // Turns led off

 delay (4000) ;             // Waits for

  digitalWrite( LED, HIGH);  //Turn the Led on
 
  delay(500);               // Waits for

digitalWrite(LED, LOW);    // Turns led off

 delay(500);               // Waits for

 while(1);  // this will loop forever right here
}


Graynomad

This compiles just fine (sorry about the crap formatting)

Code: [Select]
//Example 01 : Blinking LED

# define LED 13  // LED connected to
                //digital pin 13
               
void setup ()

{
pinMode( LED, OUTPUT ) ;   // Sets the digital pin as output.
    digitalWrite( LED, HIGH);  //Turn the Led on
 
  delay(4000);               // Waits for
 
  digitalWrite(LED, LOW);    // Turns led off
 
  delay (4000) ;             // Waits for 
 
   digitalWrite( LED, HIGH);  //Turn the Led on
   
   delay(500);               // Waits for

digitalWrite(LED, LOW);    // Turns led off

  delay(500);               // Waits for
 
}

void loop()
{

}


______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Chez7

Thanks, Rob and RoyK, I see now where  I was going wrong, works spot on now. Cheers Chez7


Hi folks, I am banging my head against a brick wall trying to interpret "error messages". Is there a straight forward dictionary of "error messages"? in my attempts at searching my "error messages" I get lots of good examples of other peoples projects with the same "error message" as mine, but does not help me as the answers are not relevant to my project.


Just to touch on the original question...  The canonical solution is in fact to just search for the error message and work out what's happening to other folks.  I originally learned to program before this resource was available, and I'll say it's now MUCH faster to learn new tech because of it.

And then the other solution is to do just as you did -- post to a forum.  Usually it's best to include the actual code causing the error and the actual error you get.

Chez7

Thanks, Maniacbug, your advice noted,Chez7

Go Up