Execute a function for x seconds every y seconds

Hi everyone, I would like to execute a function for X seconds every Y seconds on Arduino.

I'm trying to control a resistance to heat up some water in a constant rate (1o Celsius per minute), so what I thought was: I'll measure what is the rate when it's running for the whole minute and then I'll adjust it to the desired rate.

Let's say it heats up 5o celsius per minute, so I would like to activate the resistance for 60/5 seconds, but not all at once, I was thinking about activating the resistance for 1 second every 12 seconds to keep the rate constant for no matter what (if the day is too cold, too hot, if I change my equipment etc.)

Do you guys think this is possible? If not, any ideas how can I make it work? I saw the Timer.h library but it doesn't seems to solve my problem =/

Thanks in advance, please let me know if any information can be useful!

Do you guys think this is possible?

Yes. It's a variation on the blink without delay example. Different on and off durations is all.

saw the Timer.h library but it doesn't seems to solve my problem =/

How do you know? Not that it is needed, but it isn't right to dis a library you haven't even tried.

The phrase to describe this is (slow) software PWM.

unsigned long period_start = 0L ;
#define PERIOD 13000

float duty_cycle = 0.1 ;


void loop ()
{
  unsigned long diff = millis () - period_start ;
  bool active = diff < PERIOD * duty_cycle ;
  digitalWrite (heater_pin, active ? HIGH : LOW) ;  // assuming active HIGH...
  if (diff >= PERIOD)
  {
    period_start += PERIOD ;
    digitalWrite (heater_pin, LOW) ;  // assuming active HIGH
  }

  .. other stuff affecting duty_cycle here...

}

This demo several things at a time illustrates the use of millis() for timing.

...R