My goal with the code is simple. Let the Piezo buzz when temperature reaches 25 degrees. My piezo is hooked up correctly, because It makes a buzz when the arduino boots or when I put this line of code anywhere else in my code.
I also checked if the If statement was called. And yes it is! So the if statements is happening yet I don't hear a buzz.
I am aware that I am breaking my seven segmented screen by using the delay. But I don't mind the screen working when the buzzer is.
void loop()
{
//local vars
if (millis() % 5000 <= 10) {
float lm35TempC = lm35.getTempC();
sevseg.setNumber(lm35TempC, 2);
if (lm35TempC > 25.00) {
tone(1,500,1000);
delay(3000); <------- WHERE IT PROBABLY GOES WRONG
}
if (lm35TempC < 25.00) {
noTone(1);
}
}
sevseg.refreshDisplay(); // Must run repeatedly; don't use blocking code (ex: delay()) in the loop() function or this won't work right
}
To conclude: The If-statement is working yet I don't hear a buzz. How does this happen?
Thanks in Advance!
millis() % 5000 <= 10
is only 10ms every 5 second. How long does the functionsevseg.refreshDisplay
take? more than 10ms?