The full code is too long to show but in this section I want to delay LEDs for a set time that has been selected previously in the program. The name of these variables are ‘WATER’ and ‘NOIL’ and I have initialized them previously. The program does upload fine with no error message but the LEDs don’t delay for the correct time. What am I doing wrong? Can anyone help please?
if(MM == 6)
{
(lcd_key = read_LCD_buttons());
lcd.setCursor(2,0);
lcd.print("Calculating");
delay(2000);
TOTAL = coolant+volume;
TOIL = 5*(TOTAL/100);
GOIL = oil*(volume/100);
NOIL = TOIL-GOIL;
WATER = coolant-NOIL;
if(NOIL<0){
ADD = NOIL*-1;
WATER = WATER+ADD;
NOIL = 0;
}
lcd.clear();
lcd.print("Water:");
lcd.setCursor(6,0);
lcd.print(WATER); //I want to delay an LED (Pin 21) for the value of 'WATER' i.e WATER = 7 ,delay LED for 7 Seconds
lcd.print("L");
lcd.setCursor(0,1);
lcd.print("Oil:");
lcd.setCursor(6,1);
lcd.print(NOIL); // The same with NOIL but delay LED (pin20), see section if{MM == 8}
lcd.print("L");
MM = 7;
}
if(MM == 7)
{
if(machine == 1)
{
digitalWrite(22,HIGH);
MM = 8;
}
if(machine == 2)
{
digitalWrite(25,HIGH);
MM = 8;
}
if(machine == 3)
{
digitalWrite(26,HIGH);
digitalWrite(32,HIGH);
MM = 8;
}
if(machine == 4)
{
digitalWrite(26,HIGH);
digitalWrite(35,HIGH);
MM = 8;
}
if(machine == 5)
{
digitalWrite(26,HIGH);
digitalWrite(36,HIGH);
digitalWrite(44,HIGH);
MM = 8;
}
if(machine == 6)
{
digitalWrite(26,HIGH);
digitalWrite(36,HIGH);
digitalWrite(47,HIGH);
MM = 8;
}
if(machine == 7)
{
digitalWrite(26,HIGH);
digitalWrite(36,HIGH);
digitalWrite(48,HIGH);
digitalWrite(52,HIGH);
MM = 8;
}
}
if(MM == 8)
{
NOIL = TOIL-GOIL;
WATER = coolant-NOIL;
NOIL = NOIL*1000;
WATER = WATER*1000; // I want to keep LED 20 and 21 for 'NOIL' period of time
digitalWrite(20,HIGH); //Then turn off LED 20 and leave LED 21 on for 'WATER' period of time
digitalWrite(21,HIGH);
delay(NOIL);
digitalWrite(20,LOW);
delay(WATER);
digitalWrite(21,LOW);
delay(10000);
digitalWrite(19,HIGH);
delay(30000);
digitalWrite(19,LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Coolant in");
lcd.setCursor(0,1);
lcd.print("Machine");
MM = 9;
}