Hi, I'm currently working on a project in which I am using an interrupt triggered by a switch, to turn on a relay connected to the mains input of a transformer, (i'm using led on pin 13 to test this) as well as a couple of power indicator LEDs and some other bits which are as of yet inconsequential! I've got the ISR working fine but now my loop() function doesn't seem to work even though all it does is turn on an LED. My ISR is a bit long and i've read that these should be kept short, but it is fairly critical that the interrupt function occurs at the time of the interrupt and that the switch is debounced so the relay turns on and off when expected. Also it is not apparent in my code yet, but (using a switch case controlled by a switch input) I want to generate pwm outputs to three stepper drivers based on the input of a Wii nunchuck. i don't want to include the power control in this section of code but still need to be able to switch it on and off. Here's my code if anyone could give me some insight into anything i'm doing wrong it would be much appreciated.
int ledLow = 7;
int ledHigh = 8;
int powerOut = 13;
const unsigned int DEBOUNCE_TIME = 300;
static unsigned long last_interrupt_time = 0;
volatile int powerswitch2 = LOW;
void setup() {
pinMode(powerOut,OUTPUT);
attachInterrupt(0,powerroutine,FALLING);
pinMode(ledLow,OUTPUT);
pinMode(ledHigh,OUTPUT);
}
void loop() {
digitalWrite(ledLow,HIGH);
}
void powerroutine() {
unsigned long interrupt_time = millis();
if (interrupt_time - last_interrupt_time > DEBOUNCE_TIME) {
powerswitch2 = !powerswitch2;
digitalWrite(ledHigh,powerswitch2);
digitalWrite(powerOut,powerswitch2);
last_interrupt_time = interrupt_time;
}
}