In the ISR you can determine the status of the interrupt pin after the interrupt was triggered using digitalRead, bitRead, or direct port manipulation and see if the change went High or Low. Then perform conditional action.
if (interruptPinStatus==1)
{
// action A
}
else
{
// action B
}
if you take a look at the video of our team, you'll see that a certain dog blocks a certain amount of time the sensor. the other team didn't pass that close, that time i can measure...
my goal is to capture that time that the sensorgate is blocked (should indeed be used to calculate a speedtrap)
but also, if we do perfect passings like in this video, I also want to calculate the time that the sensors are blocked by two dogs, that way i can calculate the smallest passings
I've had a most enjoyable time with Google and YouTube learning about Flyball. Surely if you have the patience, persistance and precision required to train a flyball dog you can program an Arduino.
I've added a pulse generating routine to dlloyd's pulse duration sketch, which should give you a tool for developing your program. Connect a wire from pin 8 to pin 2. I've set it up for a 100ms pulse length every 5 seconds. You can set things up for micros() instead of millis() if you need that precision.
//Pulses generated on pin8 and read with interrupts on pin2
//Pulse measument variables
boolean inputStatePrevious = LOW;
volatile boolean inputState = LOW;
volatile unsigned long startMillis = 0;
volatile unsigned long stopMillis = 0;
unsigned long durationMillis = 0;
//Pulse generation constants and variables
const int pulsePin = 8;//pin sending pulses
const int pulseHigh = 100;//High time, millis() or micros()
const int pulseLow = 5000;//Low time
unsigned long ms;//time from millis() or micros()
unsigned long msLast;//last time the pulse pin changed state
boolean pinState = LOW;//current pulsePin state
unsigned long millisStart;
//unsigned long microsStart;
int pulseNumber = 0;
void setup()
{
attachInterrupt(0, blink, CHANGE);
Serial.begin(115200);
pinMode(pulsePin, OUTPUT);
millisStart = millis();
//microsStart = micros():
pinMode(2,INPUT);//Interrupt 0 on pin2
}
void loop()
{
/* pulse generation routine using ternary operator: "?"
The basic syntax of using the ternary operator is:
(condition) ? (if_true) : (if_false)
The pulse routine takes (ms-ms_last value) and if pinState High compares it
to pulseHigh time, and if Low, to pulseLow time. */
ms = millis();
//ms = micros();
if (pulseNumber < 4) //send train of four pulses
{
if (ms - msLast > (pinState ? pulseHigh : pulseLow))
{
digitalWrite(pulsePin, pinState = !pinState);
msLast = ms;
}
}
if ((inputState == LOW) && (inputStatePrevious == HIGH))
{
++pulseNumber;//numbers pulses from 1 to 4
Serial.print("pulseNumber = ");
Serial.println(pulseNumber);
durationMillis = stopMillis - startMillis;
Serial.print("startMillis = ");
Serial.println(startMillis);
Serial.print("stopMillis = ");
Serial.println(stopMillis);
Serial.print("durationMillis = ");
Serial.println(durationMillis);
Serial.println();
}
inputStatePrevious = inputState;
}
void blink()
{
//inputState = digitalRead(2);
inputState = bitRead(PIND,2);//bitRead is faster than digitalRead
if (inputState == HIGH)
{
startMillis = millis();
}
else
{
stopMillis = millis();
}
}
Can you provide a little more information about the start/finish gates. Are there two lines of sensors so you know which dog crossed first when measuring pass timing?
It sounds like you are planning to use an Arduino to automate some timing in your practice sessions. Will you be using a commercial optical gate, or will you be making something? I'm curious about how you will use pulse duration, and what length you expect. It doesn't seem to give you either pass timing, or the start/finish time of a dog.