RTC and Pushbutton Interrupts

Hello,

I working on a project that involves sensor values being taken once an hour. I am using a DS1307 real time clock to calculate intervals, but I am also trying to integrate a pushbutton that allows readings to be taken on demand as well. I have read that interrupts may be the answer to my problem, however I check the RTC every 30 seconds using a delay, and I realize that interrupts will not work with a delay.

How can I go about using a pushbutton and an RTC when a delay is necessary?

The following is my current code, with the RTC and pushbutton used through an if statement with a boolean OR.

void loop() {

buttonState = digitalRead(buttonPin);

DateTime now = RTC.now();

Serial.println(now.minute(), DEC);

//change minute value for debugging const int CHECK_MINUTE = 0;

if(now.minute() == CHECK_MINUTE || buttonState) {

//----------------------------- // SENSOR READING IS DONE HERE //-----------------------------

delay(30000); //This delay and the following ensures that a reading isn't taken twice in a minute }

delay(30000); }

How can I go about using a pushbutton and an RTC when a delay is necessary?

Why have the delay() at all ? Check the time from the RTC each time through loop() and carry out actions when the appropriate interval has passed.

andrewf: I realize that interrupts will not work with a delay.

Maybe for your application. But to clarify, interrupts are not disabled by delay(). The handler will be executed.

The main reason for the delay() is to limit power consumption. The sensor project is going to be battery powered and I want it to last as long as possible. I have also read about the sleep() command — can interrupts be used with sleep()?

The main reason for the delay() is to limit power consumption.

The processor is running flat-out 100% of the time, even in a delay,