Forced to use delay in interrupts...how to?

Hi! We have a problem, regarding our gas sensor MQ-7.
We have a program but we want to have the reading function of the MQ-7 in the background all the time. The code is below:

  • analogWrite(2, 15); *
  • delay(60000);*
  • //90s low voltage 1.4v*
  • Serial.println( "Heating Sensor - 1.4V - 90s" );*
  • analogWrite(2, 187);*
  • delay(90000);*
  • CO_ppm = analogRead(1);*

We cannot have this code running in the background all the time and still launch our other code at the same time. Which type of interrupt/function would help us come over this problem?

With delays of 60 seconds and 90 seconds, there is not a reason in the world to even be using interrupts. Look at the blink without delay example program.

Regards,
Ray L.

There is no "background" on the Arduino.

See the "Blink without Delay" example. In other words, use millis() to keep track of time, so that you can do several things more or less concurrently.

Many things cannot and should not be performed in an interrupt routine. You should use an approach like that described here.

You can either have two states (HEATING and READY) with one interval that changes when the state changes, or you can have two intervals of 150000, one of which starts out at 60000 (an offset between the two 150000 intervals). There are many variations on this theme.

Cheers,
/dev

The Thread planning and implementing a program may give you some ideas about how to structure your program.

...R