Hi everyone, so I'm fairly new to Arduino, this is my first big project with the arduino and I'm having some trouble with an if/else statement.
Some background for this, I have a temperature sensor and based on what the temperature output is, there would be a "song", so to speak, that plays. So if a temperature is higher than a set point it would play one, and if it was lower than that point it would play another. My code is below and I think for better viewing purposes it would be copied and pasted into the actual Arduino sketchbook. I did not paste in the second song, just because I can learn from the first one what is wrong with the second.
My error is the 'frequency' was not declared in this scope.
Also, if you were to take both codes (just the outputs for the temperature sensor and the song portion) they are verified to work separate of each other, just not sure why one cannot work inside the other.
Thank you so much!
const int temperaturePin = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
float voltage, degreesC, degreesF;
voltage = getVoltage(temperaturePin);
degreesC = (voltage - 0.5) * 100.0;
degreesF = degreesC * (9.0/5.0) + 32.0;
Serial.print("voltage: ");
Serial.print(voltage);
Serial.print(" deg C: ");
Serial.print(degreesC);
Serial.print (" deg F: ");
Serial.println(degreesF);
delay(1000);
if (degreesF > 650)
{
const int buzzerPin = 9;
const int songLength = 20;
char notes[] = "ccbacc ccbabb ccbaec";
float beats[] = {1,.5,.5,.5,.5,4,1,1,.5,.5,.5,.5,4,1.5,.5,.5,.5,.5,.5,4};
int tempo = 500;
{
pinMode(buzzerPin, OUTPUT);
}
{
int i, duration;
for (i = 0; i < songLength; i++)
{
duration = beats[i] * tempo;
if (notes[i] == ' ')
{
delay(duration);
}
else
{
tone (buzzerPin, frequency(notes[i]), duration);
delay(duration);
}
delay(tempo/10);
}
while (true){}
}
int frequency(char note)
{
int i;
const int numNotes = 14;
char names[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'A', 'B', 'C'};
int frequencies[] = {880, 988, 1106, 1175, 1319, 349, 392, 415, 466, 523};
for (i = 0; i < numNotes; i++)
{
if (names[i] == note)
{
return (frequencies[i]);
}
}
return(0);
}
}
}
if else (degreesF < 600)
{
//Second Song Here
}
}
float getVoltage int pin)
{
returnanalogRead(pin) * 0.004882814);
}