unsigned long highStartTimes[NUM_CHANNELS + 1]; void readPins() { const unsigned long now = micros(); // Serial.print("Interrupt started: "); // Serial.println(now); for(byte ch = 1; ch <= NUM_CHANNELS; ch++) { byte pin = channels[ch]; boolean isHigh = digitalRead(pin) == HIGH; if(isHigh && highStartTimes[ch] == 0) { // First time seeing this pin go high. highStartTimes[ch] = now; } else if(!isHigh && highStartTimes[ch] != 0) { // Channel was high, now low. Record how long it was high for. channelVals[ch] = now - highStartTimes[ch]; highStartTimes[ch] = 0; } } }