Code: Select all
void setup() {
PCICR |= (1 << PCIE0); // Set PCIE0 to enable PCM$K0 scan
PCM$K0 |= (1 << PCINT0);
PCM$K0 |= (1 << PCINT1);
PCM$K0 |= (1 << PCINT2);
PCM$K0 |= (1 << PCINT3);
}
void ISR(PCINT0_vect) {
current_time = micros();
// Channel 1 -------------------------------------------------
if (PINB & B00000001) { // Is input 8 high ?
if (previous_state[CHANNEL1] == LOW) { // Input 8 changed from 0 to 1 (rising edge)
previous_state[CHANNEL1] = HIGH; // Save current state
timer[CHANNEL1] = current_time; // Save current time
}
} else if (previous_state[CHANNEL1] == HIGH) { // Input 8 changed from 1 to 0 (falling edge)
previous_state[CHANNEL1] = LOW; // Save current state
pulse_length[CHANNEL1] = current_time - timer[CHANNEL1]; // Calculate pulse duration & save it
}
Also if you guys provide a pinout diagram for the Metro Express M0 like you do for this
https://cdn-shop.adafruit.com/product-f ... l_v2_0.pdf
Note: Really, P C M S K 0 is banned?