I have a circuit with 4 outputs that I wish to monitor using the Uno. I want the fastest way to time stamp (i.e. micros() ) the rising edge of the signals as they come in. My thought was pinchangeint() but I can even get a code to compile. Is the pinchangeint() my best approach or is there any ideas for an accurate read?
Doesn’t compile sorry! Perhaps it will shed some light on what I am trying to do. For simplicity the code is with only 2 of the 4 inputs.
#include <PinChangeInt.h>
#include <PinChangeIntConfig.h>
#define PIN1 2;
#define PIN2 3;
unsigned long T1;
unsigned long T2;
void func1 ()
{ T1=micros();
};
void func2 ()
{ T2=micros();
};
void setup(){
pinMode(PIN1, INPUT);
pinMode(PIN2, INPUT);
digitalWrite(PIN1, LOW);
digitalWrite(PIN2, LOW);
PCintPort::attachInterrupt (PIN1, func1, RISING); //look for the rising of pin and call func
PCintPort::attachInterrupt (PIN2, func2, RISING);
}
void loop() {
//checks that each measure has been taken
if (T1 != 0);
if (T2 != 0);
{void loop() {
Serial.print("Hit1:");
Serial.println(T1);
Serial.print("Hit2:");
Serial.println(T2);
delay(200);// waits and clears for next test
T1=0;
T2=0;
}
}
}
I don’t think the if statements preceding it will work either. They are ending in semi-colons, so they end there. The code in the curly-brackets behind it are executed independently. Atleast, C would be that strict, maybe Arduino is less strict.