As a part of a large program, I use IRQ0 for triggering the impulse from an energy counter (kWh-meter).
A LED has to flash a shortwhile as an ackknowdge for the receipt of this impulse.
It seems that the code for the flashing LED functions very fast; if I place the same code within the(main)loop it function well.
Can anybody explain me why?
/* pulse counting from energycounter (kWh-meter)
Arduino Mega 2560
Pulse on IRQ0 (pin2)
LED on pin 12
*/
#define kWhpulsLED 12
#define off 1
#define on 0
void setup() {
pinMode(12, OUTPUT); //kWh-LED
pinMode(2, INPUT); //kWh-takt via IRQ0
digitalWrite(2, HIGH); //Pull up resistance
digitalWrite(kWhpulsLED,off); //turn kWhpulsLED off
attachInterrupt(0, puls, RISING); //IRQ0 will start void pulse
}
//========================================================================================
void loop() {
// put your main code here, to run repeatedly:
/*
delay(1000);
digitalWrite(kWhpulsLED,on); //turn kWhpulsLED on
delay(1000);
digitalWrite(kWhpulsLED,off); //turn kWhpulsLED off
*/
}
//========================================================================================
void puls() {
digitalWrite(kWhpulsLED,on); //turn kWhpulsLED on
delay(1000);
digitalWrite(kWhpulsLED,off); //turn kWhpulsLED off
}