I am using controllino MEGA with Atmega2560 chip. I am trying to write a program to detect rising and falling edge on PORT K (PCINT16 AND PCINT17). I have most of it working but there is some issue with consistency and I think there is a problem in my code.
Beacause I am working with buttons there is issues with electricity when button engages. with meant that my interupts would sometime run twice or maybe even more. The solution = ADD TIME CHECK. Below is working code. I tried with micros = 800 but would still get issues sometimes, seems millis = 1 is just enough.
The 'digitalRead()' function is super slow. I wouldn't use it in an ISR, especially not twice. Use direct read of PINK register and mask the appropriate bits.
gfvalvo:
The 'digitalRead()' function is super slow. I wouldn't use it in an ISR, especially not twice. Use direct read of PINK register and mask the appropriate bits.
oh thats kinda smart.
here I edited last part now other things in port K don't stop it from working and don't interfere. Unless you gonna say that bitRead is also slow or I am missing something else. Thanks a lot for the help.