understanding this for loop code

greetings.

I’m trying to wrap my head around this code;

int Pump = 7;
int Light = 8;

void setup() {
   Serial.begin(9600);
   pinMode (Pump, OUTPUT);
   pinMode (Light, OUTPUT);
}

void loop() 
{
  digitalWrite(Light,HIGH);
  for(int i=0; i<32; i++){
    for(int j=0;j<100;j++){
      digitalWrite(Pump,HIGH);
      delay(9000);
    }
    for(int k=0;k<100;k++){
      digitalWrite(Pump,LOW);
      delay(27000);
    }
  }
  
  digitalWrite(Light,LOW);
  for(int l=0;l<16;l++){
    for(int m=0;m<100;m++){
      digitalWrite(Pump,HIGH);
      delay(9000);
    }
  for(int n=0;n<100;n++)
  {
    digitalWrite(Pump,LOW);
    delay(27000);
  }
  }
}

i know that pump turn on 15 minutes, shut off 45 minutes. the light though… run light on 32 times?
thanks in advance.

There is no reason to be diddling with the pins inside the inner loops. There is no reason to have the inner loops at all.

  for(int i=0; i<32; i++){
    for(int j=0;j<100;j++){
      digitalWrite(Pump,HIGH);
      delay(9000);
    }
    for(int k=0;k<100;k++){
      digitalWrite(Pump,LOW);
      delay(27000);
    }
  }

should be

  for(int i=0; i<32; i++)
  {
      digitalWrite(Pump,HIGH);
      delay(900000UL);

      digitalWrite(Pump,LOW);
      delay(2700000UL);
  }

You can make similar changes to the other two for loop messes, too.

PaulS:
There is no reason to be diddling with the pins inside the inner loops. There is no reason to have the inner loops at all.

  for(int i=0; i<32; i++){

for(int j=0;j<100;j++){
     digitalWrite(Pump,HIGH);
     delay(9000);
   }
   for(int k=0;k<100;k++){
     digitalWrite(Pump,LOW);
     delay(27000);
   }
 }



should be


for(int i=0; i<32; i++)
 {
     digitalWrite(Pump,HIGH);
     delay(900000UL);

digitalWrite(Pump,LOW);
     delay(2700000UL);
 }




You can make similar changes to the other two for loop messes, too.

so if im to write pump on 3 hours, it would be

{
digitalWrite(pump,HIGH);
delay(1080000000UL)

?

No, that would be 300 hours.

If you are doing things that need 15 minute, 45 minute, 3 hour, etc. durations, then an RTC really is in order.

Also useful:

#define ONESEC 1000L
#define ONEMIN (60*ONESEC)
#define ONEHOUR (60*ONEMIN)

Then you can do something readable and less error-prone, like:

delay(3*ONEHOUR);