Interrupts

I'm using the MsTimer2 library and and its seems straight forward.

I set my interrupt on a 15 sec timer and it works, meaning the code in the interrupt executes. The issue is it then never returns to the main loop.

So i guess that means it doesn't really work......

What simple line of code am i missing?

What simple line of code am i missing?

All of it. :( How can we tell?

Basically whats in my code:


//the interrupt:

void LCDSleep() {
SleepMode = true;
mySerial.print("?B00"); //Sets backlight to dark
delay(100);
}

//This is in the Void setup:

MsTimer2::set(15000, LCDSleep); // 15 s period
MsTimer2::start();

//The interrupt should happen then return to the main loop no? the only thing i saw was delays throw off the timing a bit but it has to be here to flash the LCD and also i would think its not going to lock up the program.


This is the sample code provided

#include <MsTimer2.h>

// Switch on LED on pin 13 each second

void flash() {
static boolean output = HIGH;

digitalWrite(13, output);
output = !output;
}

void setup() {
pinMode(13, OUTPUT);

MsTimer2::set(500, flash); // 500ms period
MsTimer2::start();
}

void loop() {
}

It's probably not what you're missing, it's what you're including. Usually, "delay"s are a no-no in an interrupt service routine, and quite often, so is serial I/O.

Please use the Code (#) button when posting code.

Thanks, yeah the delay seemed like the culprit. ill check it when i get home. My nubness just found the # insert code button.

thanks again

//The interrupt should happen then return to the main loop no? the only thing i saw was delays throw off the timing a bit but it has to be here to flash the LCD and also i would think its not going to lock up the program.

Well, sort of. The interrupt will continue, interrupting the main loop. As soon as you call MsTimer2::start() - the LCDSleep gets called while your main loop executes.

You will want to keep your interrupt routine (in this case LCDSleep) as quick as possible. It will effect the main loop performance, and possibly millis() and delay().

Think of interrupts like the processor is switching to handle an emergency. While it is working on the emergency, the normal work (main loop) has to be stalled.