variable or field declared void

I have an Arduino Uno that I am using to monitor the temperature of air blowing out of a vent. This isn't a serious project, just a learning adventure. I am trying to use function and cases with this project. I have the temperature sensor connected to A0, and LEDs connected to pins 2-5.

I understand my code is pretty poorly written. I was trying to incorporate ifs, switches, and functions so it caused a bit of uncleanliness, but I don't think that's causing of these errors. I tried Googling the errors, but everything I found was for much more complex things than what I'm doing, and I couldn't think of ways to make it fit my project.

I previously had this project working with a slightly modified version of the Starter Kit example p03_LoveOMeter, but since I did the rewriting, I get the following errors:

Air_Temp_Check:4: error: variable or field 'cycleLightTest' declared void
Air_Temp_Check:4: error: 'onLedPin' was not declared in this scope
Air_Temp_Check:5: error: variable or field 'ledLightOn' declared void
Air_Temp_Check:5: error: 'onLedPin' was not declared in this scope
Air_Temp_Check:16: error: variable or field 'cycleLightTest' declared void
Air_Temp_Check:22: error: variable or field 'ledLightOn' declared void
Air_Temp_Check.ino: In function 'void setup()':
Air_Temp_Check:39: error: 'cycleLightTeset' was not declared in this scope
Air_Temp_Check.ino: In function 'void loop()':
Air_Temp_Check:75: error: 'ledLightOn' was not declared in this scope

And, of course, the code:

const int sensorPin = A0;
const float desiredAirTemp = 80.0;
float temperature;
int sensorVal;
int onLedPin;
int caseVar;

void lightReset(){
  for(int pinNumber = 2; pinNumber<6; pinNumber++){
    pinMode(pinNumber,OUTPUT);
    digitalWrite(pinNumber, LOW);
  }
}

void cycleLightTest(onLedPin){
  lightReset();
  digitalWrite(onLedPin);
  delay(500);
}

void ledLightOn(onLedPin){
  lightReset();
  digitalWrite(onLedPin);
}

void setup(){
  //Open a serial connection
  Serial.begin(9600);
  //Set the LED pin as an output
  sensorVal = analogRead(sensorPin);
  
  //Call reset light function
  lightReset();
  
  // Light check
  // Cycles through lights, leaves on error lights fulltime
  for(onLedPin = 2; onLedPin<6; onLedPin++){
    cycleLightTeset(onLedPin);
  }
}

void loop(){
  // Read the value of the temperature sensor
  sensorVal = analogRead(sensorPin);
  // Convert temperature sensor output to voltage
  float voltage = (sensorVal/1024.0) * 5.0;
  // Convert voltage to temperature
  float temperatureCels = (voltage - .5) * 100;
  temperature = (temperatureCels * 9/5) + 32;
  // Print info to log
  Serial.print("Celsius: ");
  Serial.print(temperatureCels);
  Serial.print(", Fahrenheit: ");
  Serial.print(temperature);
  Serial.print(", Sensor Value: ");
  Serial.println(sensorVal);
  
  if(temperature < desiredAirTemp){
    caseVar = 1;
  }else if(temperature > desiredAirTemp && temperature < desiredAirTemp+15){
    caseVar = 2;
  }else if(temperature > desiredAirTemp+15 && temperature < 125){
    caseVar = 3;
  }else if(temperature > 125){
    caseVar = 4;
  }
  /*
   * Red: Less than 80F
   * Yellow: 80F<temp<95F
   * Green: Greather than 95F
   */
  switch(caseVar) {
    case 1:
      ledLightOn(2);
      Serial.println("Red light! Temp too low!");
      break;
    case 2:
      ledLightOn(3);
      Serial.println("Yellow light!");
      break;
    case 3:
      ledLightOn(4);
      Serial.println("Green light!");
      break;
    case 4:
      ledLightOn(5);
      tone(9, 750, 250);
      delay(500);
      ledLightOn(5);
      Serial.println("ERROR!!!");
      break;
  }
  delay(500);
}

void cycleLightTest( SomeDatatypeGoesHereYouProbablyMeant_int onLedPin){

void ledLightOn( SameForThisOnePutADatatypeHere onLedPin){

2 Likes

void cycleLightTest(onLedPin)What type of variable does this function expect to receive as its argument ?
void ledLightOn(onLedPin)and the same here ?
 digitalWrite(onLedPin);How many arguments does this function take ?
    cycleLightTeset(onLedPin);spelling mistake ?

Okay, so thanks to you guys, I figured it all out. I assumed that since as a global variable I defined onLedPin as an integer that I did not have to do that when doing the arguments for the function, but I suppose that I did. Doing void functionName(int onLedPin){stuff_here;} made it work.

Also, fixing the spelling mistake in the one function name definitely helped.

And I added HIGH and LOW to the arguments for digitalWrite where needed. I don't know how I forgot those.

Thank you so much! It compiled perfectly after fixing this. I'll try not to be such a n00b in the future.

kalaker:
Okay, so thanks to you guys, I figured it all out. I assumed that since as a global variable I defined onLedPin as an integer that I did not have to do that when doing the arguments for the function, but I suppose that I did. Doing void functionName(int onLedPin){stuff_here;} made it work.

Also, fixing the spelling mistake in the one function name definitely helped.

And I added HIGH and LOW to the arguments for digitalWrite where needed. I don't know how I forgot those.

Thank you so much! It compiled perfectly after fixing this. I'll try not to be such a n00b in the future.

You either have a variable as a global, or you pass it as a parameter - you don't do both.