Good morning,
Lately we have been experimenting with projects with ATmega328P microcontrollers to SAMD21, in this case with the MKR1500 board.
My need is to send the board in deep sleep to save consumption and in the meantime to count the impulses of a reed sensor connected to a digital pin via an interrupt.
Here problems arise, with this board (at least in my case) when it goes to sleep, interrupts are not counted as arriving in FALLING / RISING mode, instead with HIGH or LOW mode, the board wakes up at the first impulse ...
Instead I would like the board to continue to sleep for a certain time, and in the meantime to count the impulses.
My piece of code is as follows:
pinMode(countPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(countPin), count_int, FALLING); /*attiva interrupt su pin*/
Serial1.println("Go to sleep...");
LowPower.deepSleep(10000);
detachInterrupt(1); /*disattiva interrupt su pin*/
print_count();
void count_int()
{
count++;
}
void print_count(void)
{
Serial1.print("count: ");
Serial1.println(count);
count=0;
}
I apologize in advance for my bad English