probably just a simple silly error, im a newb...

In trying to write a program , I'm using the analog to run a thermistor, this will be calibrated later using resistors etc and getting the value right (it probably wont be 90), but i keep getting the same errors...
below is my code:
// program for egg boiling timer. timer starts when water temp reaches boiling. flashes yellow when soft boiled, then fades into red, and flashed red when hard boiled

int red = 9; // Digital pin 9 - Red LED
int yellow = 10; // Digital pin 10 - Yellow LED
int time = 5; // time/delay
int pulsewidth; // pulsewidth value (0-255)
int analog; // declare an integer variable first
// using analog pin 0 for thermistor potential divider
byte x;

void setup() {
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
}

void loop() {
analog = analogRead(0); // read voltage on channel 0 and store it in variable
if(analog<90){
}
else{

delay(180000); //delay 3 mins

void loop() { //flash yellow LED for 5 seconds at 4Hz to signify soft boiled
if(x>19){
digitalWrite(10,HIGH);
delay(250);
digitalWrite(10,LOW);
delay(250);
}
x++;
}

else{

void loop() {
// slowly fade the red LED to full brightness, yellow to 0
for (pulsewidth=0; pulsewidth <= 255; pulsewidth++){
analogWrite(red, pulsewidth);
analogWrite(yellow, -pulsewidth);
delay(time);
}

}
digitalWrite(9,LOW); //reset both LEDs
digitalWrite(10,LOW);

void loop() { //flash red LED for 5 seconds at 4Hz to signify hard boiled
if(x>19){
digitalWrite(9,HIGH);
delay(250);
digitalWrite(9,LOW);
delay(250);
}
x++;

else{

}

}
}
##############################################END OF CODE#################################################
and my errors are as follows:
egg_timer_1.cpp: In function 'void loop()':
egg_timer_1:27: error: a function-definition is not allowed here before '{' token
egg_timer_1:65: error: expected }' at end of input egg_timer_1:65: error: expected }' at end of input

PLEASE HELP :slight_smile:

other useful info (maybe), I'm using the "arduino duemilanove or Nano w/ ATmega 328" board

rich x

You have void loop() in there four time - you can only call it once.

Click your cursor next to each }, then use the scroll bar & look back in the code to see if the mating { is in the right place.

Clicking CTRL-T (autoformat) will also help you catch things like that.

hi CrossRoads

can I not have loops inside loops then? if so how can I make my program wait and only start when analog is more than 90?

thanks :slight_smile:

Question 1: You can have nested for:next loops, or nested while loops, or nested functions.
You just can't call all the functions "void loop()", that has special meaning to the compiler.

Question 2:
while (analogRead(0) <=90){
// hang out here
}

cool, I tried that, so I basically I replaced all the void loops with while code, because I wasn't using the else bit at all, I was using them all for the same, and that way none of them are inside each other.
So, this is what it looks like now...

// program for egg boiling timer. timer starts when water temp reaches boiling. flashes yellow when soft boiled, then fades into red, and flashed red when hard boiled

int red = 9; // Digital pin 9 - Red LED
int yellow = 10; // Digital pin 10 - Yellow LED
int time = 5; // time/delay
int pulsewidth; // pulsewidth value (0-255)
int analog; // declare an integer variable first
// using analog pin 0 for thermistor potential divider
byte x;

void setup() {
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
}

while (analogRead(0) <=90){
// wait for it...
}

delay(180000); //delay 3 mins

while (x<19){ //flash for 5 sec to show egg is soft boiled

digitalWrite(10,HIGH);
delay(250);
digitalWrite(10,LOW);
delay(250);
x++;
}

x=0

void loop() {
// slowly fade the red LED to full brightness, yellow to 0
for (pulsewidth=0; pulsewidth <= 255; pulsewidth++){
analogWrite(red, pulsewidth);
analogWrite(yellow, -pulsewidth);
delay(time);
}

}
digitalWrite(9,LOW); //reset both LEDs
digitalWrite(10,LOW);

while (x<90){ //flash red LED for 5 seconds at 4Hz to signify hard boiled
digitalWrite(9,HIGH);
delay(250);
digitalWrite(9,LOW);
delay(250);
x++;
}
else{
}
}}}

##########END

with errors:
egg_timer_1:1: error: expected unqualified-id before numeric constant
egg_timer_1:21: error: expected unqualified-id before 'while'
egg_timer_1:25: error: expected constructor, destructor, or type conversion before '(' token
egg_timer_1:28: error: expected unqualified-id before 'while'
egg_timer_1:37: error: expected constructor, destructor, or type conversion before '=' token

sorry I'm such a pain!

rich

You need to check your use of { }s
All the code that is not a function (i.e. void something_or_other() )
needs to fit within
void setup() {
// code here runs once
}
or
void loop() {
// code here repeats
}

You have code that is not a function and is not in either required function (setup & loop).

Ahh, I see, I've redone a lot of the code and it now compiles fine :slight_smile:

thank you so much CrossRoads! :smiley:

rich

Glad to help.