arduino codes {{{{

1,711 views
Skip to first unread message

khmern...@aim.com

unread,
Dec 10, 2010, 5:04:07 PM12/10/10
to wsu-e...@googlegroups.com
not sure what i did wrong, or how to fix it but this is what it said the problems was

a function indefinition is not allowed here before '{' token

final.cpp: In function 'void loop()':
final:47: error: a function-definition is not allowed here before '{' token
final:56: error: expected `}' at end of input
final:56: error: expected `}' at end of input


it highlighted { right after
int getDist()
{

in which i colored in red at the bottom

help would be much appreciated! thanks ahead of time






CODES:

int sharpIR = 1;
int avgFactor =10;    

int value = 0;    // variable to keep the actual value
int greenPin = 11;              // led light green
int yellowPin = 10;        // led light yellow
int redPin = 9; // led light red

boolean lightOn = false;

void setup(void){

  Serial.begin(9600);
}


void loop()
{

  int val = getDist();
  Serial.println(val);
  delay(30);

{
  if (value >= 450)  //Turn on LED red if > 500
  {
    analogWrite(redPin, value);
  }
  else if ((value >= 200) && (value < 450))  //Turn on LED yellow-ish if 200 < dist > 500
  {
    analogWrite(yellowPin, value);
  }
  else if (value < 200)  //Turn on LED green if dist < 199
  {
    analogWrite(greenPin, value);
  }
}



{
int getDist()
{
  int runningTotal=0;
  for (int i=0; i < avgFactor; i++)
  {
    int distRead = analogRead(sharpIR);
    runningTotal += distRead;
  }
  int distAvg = (runningTotal / avgFactor);
  return distAvg;
 }
 
 

Seth Landon Schoming

unread,
Dec 10, 2010, 5:23:43 PM12/10/10
to wsu-e...@googlegroups.com
Make sure you close all brackets that you open... What I mean is, for every '{' make sure that you have a '}' somewhere later in the code...

this error is telling you that you need to close void loop() before you define the function getDist()... you have a bracket there, but it needs to be a '}' and not at '{' on the line just above int getDist()
> --
> You received this message because you are subscribed to the Google Groups "wsu-engr101" group.
> To post to this group, send email to wsu-e...@googlegroups.com.
> To unsubscribe from this group, send email to wsu-engr101...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/wsu-engr101?hl=en.

Mohamad ali kazi

unread,
Dec 10, 2010, 11:53:22 PM12/10/10
to wsu-e...@googlegroups.com

In case you are still stuck at this problem, only brackets {} are messed up somewhere in void loop. Try this. Whenever you move your cursor next to a curly bracket lets say { arduino program will show you the } associated with that as a blue square around the brackets. Vice versa

Move your cursor to every { bracket in void loop and check if arduino points to the other bracket end }. If nothing is pointed out you are missing a }. Then move your cursor to every } and check if  the program points to }. If it doesnt, that } bracket is extra. delete it.

From: "khmern...@aim.com" <khmern...@aim.com>
To: wsu-e...@googlegroups.com
Sent: Fri, 10 December, 2010 4:04:07 PM

Subject: [wsu-engr101: 440] arduino codes {{{{

Thaiband Lee Nith

unread,
Dec 10, 2010, 11:59:18 PM12/10/10
to wsu-e...@googlegroups.com
Ah thanks guys good to know. Will find out in a bit. Just got home from work

Sent from my iPhone

nick smith

unread,
Dec 11, 2010, 5:58:43 AM12/11/10
to wsu-e...@googlegroups.com
from what i can see your short 3x } to close out sections.

another nifty tool is that it automatically indents for you when you open a section with { then unindents (is that a word?) when you close a section with }
Reply all
Reply to author
Forward
0 new messages