Pages: [1]   Go Down
Author Topic: error: expected unqualified-id before 'if'  (Read 949 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone,

So I am working on some code for my robot. I have to ldr's on the front of the robot. It is connected to analog pins 0, 1. I'm still new to programming. When I compile the follow code I get:
Tank_with_ldr_:19: error: expected unqualified-id before 'if'
Tank_with_ldr_:26: error: expected unqualified-id before 'else'

Something got messed up when I pasted the code from the arduino ide, so the loop() wasn't part of it.

Code:
const int analogpin = 0;  // Analog input pin
const int analogpin2 = 1;

void setup()
{
  Serial.begin(9600);   // initialize serial communications at 9600 bps:
}

void loop()
{
 

  int adcvalue = analogRead(analogpin);    // read the analog in value:           
  Serial.print("\ntemp sensor = " );                       
  Serial.print(adcvalue);    // print the adc value to the serial monitor:
  double temp = adcvalue / 25.6;  //convert it to Celsius
  Serial.print("\n temp = ");     
  Serial.println(temp);   // print the temperature
  delay(1000);   // wait 1 second before next sample                   

  int lightSensorReading = analogRead(analogpin2);
  Serial.print("\nlight sensor: ");
  Serial.print(lightSensorReading);


}
  }
« Last Edit: May 06, 2011, 08:43:16 pm by mlandergan » Logged

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code at line 20 on is outside of any function where it can't exist.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50115
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What happened to loop()?
Logged

Pages: [1]   Go Up
Jump to: