Uno: Possibly to use HIGH mode in attachInterrupt

Hello,

attachInterrupt(digitalPinToInterrupt(pin), ISR, mode);

My goal is that I can capture data sending to my Uno board when there is a HIGH (when the control voltage at pin#2 is greater than 3V) and keep capture the data till the the control voltage drops below 3V.

Since the UNO doesn't support HIGH mode in the attachInterrupt but Arduino Due, Zero, MKR1000 only and the other Modes doesn't quite appropriate in my application, I wonder if you have any recommendation or suggestion for the problem.

Thanks much,

If I have understood your requirements correctly, you should simply be able to poll the pin # 2:

void loop() {

if ( digitalRead( 2 ) == HIGH ) {

// do whatever you would have done in the ISR

}

}

huynh213:
and keep capture the data till the the control voltage drops below 3V.

What are the longest and shortest times that the voltage will be above 3v?

Maybe there is no need to use an interrupt - they are usually only required for very short-lived events.

...R

HIGH on the UNO actually defaults to CHANGE.

If you are going to use interrupts on the UNO for your task, use CHANGE, and read the state of the pin in the ISR. If it went high, start your data capture, if it went low, end your data capture.

You will have to provide more information about the "data capture". It's not likely that you will be able to do the data capture within the ISR. You may have to set a flag in the ISR and make sure that your program is non-blocking and tightly looped.

Thank you for quick responses.

Cattledog, you're right. HIGH on Uno means CHANGE. I did use it for my code till to your posts enlightened me.

Robin2 and 6v6gt, thanks for your suggestions. The period of time that the system collects data is up to users, it could be 1 second till to infinitive. I have no idea why I used the interrupt, and I should just use a digitalread and if/else statement to get the job done.

Thanks a lot.

huynh213:
it could be 1 second till to infinitive.

One second is an enormously long time for an Arduino. There is no need to use interrupts. Polling with digitalRead() should be quite sufficient.

Interrupts are important for events that only last a few microseconds.

…R