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;
}