Hello everyone!
I am still learning this programming stuff and one of my codes is giving me a little trouble. Could you either tell me what I have done wrong or point me in the right direction? The goal is to have the LCD display the temp + a message and the corresponding LED illuminate (green and yellow solid, red and buzzer intermittent. My LCD seizes up and flashes all different shapes. I know its not the wiring because it only started acting up when I changed delay to millis(). Period2 = 1000ms. Any help would be amazing! Thanks
//CORRECT TEMP ----------------------------------------
// GREEN LED ON STEADY & LCD UPDATE EVERY 1 SECOND
if (temp > 150 && temp <= 160) {
digitalWrite(2, HIGH); //GREEN ON SOLID
startMillis = millis();
if (currentMillis - startMillis >= period2)
{lcd.print("Temp = ");
lcd.print(temp);
lcd.print(" F ");
lcd.setCursor(0,1);
lcd.print(" READY ");
lcd.clear();}
}
//SLIGHTLY LOW TEMP ---------------------------------
//YELLOW LED ON STEADY & LCD UPDATE EVERY 1 SECOND
if (temp < 150 && temp >= 140) {
digitalWrite(4, HIGH); //YELLOW ON SOLID
startMillis = millis();
if (currentMillis - startMillis >= period2){
lcd.print("Temp = ");
lcd.print(temp);
lcd.print(" F ");
lcd.setCursor(0,1);
lcd.print(" TEMP LOW ");
lcd.clear();}
}
//LOW TEMP ------------------------------------------
if (temp < 140) {
startMillis = millis();//SET TIME
if (currentMillis - startMillis >= period2){
digitalWrite(3, HIGH); //RED ON
digitalWrite(A1, HIGH);//BUZZER ON
lcd.print("Temp = ");
lcd.print(temp);
lcd.print(" F ");
lcd.setCursor(0,1);
lcd.print(" STOP PRODUCTION ");
lcd.clear();}
}
digitalWrite(3, LOW); //RED OFF
digitalWrite(A1, LOW);//BUZZER OFF
//HIGH TEMP -----------------------------------------
if (temp > 160) {
startMillis = millis();//SET TIME
if (currentMillis - startMillis >= period2){
digitalWrite(3, HIGH); //RED ON
digitalWrite(A1, HIGH);//BUZZER ON
lcd.print("Temp = ");
lcd.print(temp);
lcd.print(" F ");
lcd.setCursor(0,1);
lcd.print(" STOP PRODUCTION ");
lcd.clear();}
}
digitalWrite(3, LOW); //RED OFF
digitalWrite(A1, LOW);//BUZZER OFF
}
larryd I just posted the whole code. Sorry I thought it was just in the last section that I changed. Its a little active buzzer which came in a starter kit. I actually have it disconnected now to stop the noise. Thanks
It's not...stupid mistake. I have changed this code so many times I'm surprised I didn't mess up more. Thank you. I'll add that in and see if that eliminates my problems.
What are you trying to achieve with the IF statements and the millis variables? Even if the IF statement is true, you are printing to the lcd display then immediately clearing the display, so you would have no time to actually see what was being displayed.
Got it thanks! I am trying to have the temperature update every second. If the temp falls within certain categories the LED's respond accordingly. I think my problem now is a setup issue. I want the temperature to update routinely and only print certain warnings if applicable. I probably don't explain things well...
So the LED color and message will change but the temp always prints every second.