Arduino Forum

Products => The Arduino Starter Kit and Basic Kit => Topic started by: ahuss on Aug 28, 2015, 06:23 pm

Title: project 03 calibration unqualified-id before
Post by: ahuss on Aug 28, 2015, 06:23 pm
so im trying to get a baseline temp by pressing a switch. so that it is calibrated, however i keep getting an expected unqualifed-id before switch error. if I remove the variable and just put in the pin number to digital read it compiles fine, but not as a variable
Code: [Select]
float volts = 0;
float baselineTemp = 20.0;
int switchState=0;
int switch = 8;
  void setup() {
   pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(A0,INPUT);
  Serial.begin(9600);
  pinMode(switch,INPUT);
  }

void loop() {
  // put your main code here, to run repeatedly:
int sensorValue = analogRead(A0);
Serial.print("Sensor Value: ");
Serial.print(sensorValue);
volts = (sensorValue / 1024.0) * 5.0;
Serial.print(" Voltate: ");
Serial.print(volts);
float temp = (volts - 0.5) * 100;
Serial.print(" Temperature: ");
Serial.println(temp);
delay(10);

if((digitalRead(switch)) == HIGH)
  baselineTemp = analogRead(A0);
 
if(temp < baselineTemp){
  for (int i = 2; i < 5; i++){
    digitalWrite(i,LOW);
  }
}
  else if(temp > baselineTemp+2 && temp < baselineTemp+4){
          digitalWrite(2,HIGH);
         
  } else if(temp > baselineTemp+2 && temp < baselineTemp+4){
          digitalWrite(2,HIGH);
          digitalWrite(3,HIGH);
}else if(temp > baselineTemp+6){
          digitalWrite(2,HIGH);
          digitalWrite(3,HIGH);
          digitalWrite(4,HIGH);
}
}
Title: Re: project 03 calibration unqualified-id before
Post by: dannable on Aug 29, 2015, 11:22 am
'Switch' is an inbuilt function:

https://www.arduino.cc/en/Reference/SwitchCase (https://www.arduino.cc/en/Reference/SwitchCase)

So you cannot use it as a variable name.
Title: Re: project 03 calibration unqualified-id before
Post by: ahuss on Aug 31, 2015, 01:10 am
ah rite lol.
didnt realise c had switch, plus thought in such a case the colour would change
Thanks man