Go Down

Topic: error: expected unqualified-id before 'if' (Read 1 time) previous topic - next topic


May 07, 2011, 03:04 am Last Edit: May 07, 2011, 03:43 am by mlandergan Reason: 1
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: [Select]
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: ");



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


The art of getting good answers lies in asking good questions.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131