attachInterrupt questions

I'm trying to use attachInterrupt to monitor the position of a switch. When the switch it changed, I want a pump to activate.

Is it possible to do serial writing inside the function called in the interrupt? Also, when using the CHANGE mode, would the logic in the called function process the input of the interrupted pin before or after the change?

Why do you think you need an interrupt? Is it because you need to wake the processor from a sleep mode?

Is it possible to do serial writing inside the function called in the interrupt?

It's an extremely bad idea. An ISR (interrupt service routine) should be very fast; serial IO is very slow.

Also, when using the CHANGE mode, would the logic in the called function process the input of the interrupted pin before or after the change?

That would be "after". It's a microcontroller, not a time machine.

-j

@AWOL: I thought it would be a good idea so that when the switch is pressed, the pump turns on/off almost immediately. Would it be possible to just use it in the main loop instead? I'm just checking to see if the switch has been pressed.

The switch is located on a remote control, and this remote control wirelessly communicates with the apparatus that the pump is housed in. Is there any way to detect a change in an input without an interrupt?

Is there any way to detect a change in an input without an interrupt?

Just call digitalRead()

That's what I'm doing now, but I don't want to miss any inputs

All the Ga. Tech EE's that I've known are able to measure stuff like this. :) Got a 'scope? Toggle a digital output inside your loop and measure the frequency with the scope. That will tell you how fast your loop is running.

Regards,

-Mike

the pump turns on/off almost immediately

It's a question of timescales.

(Back of a beermat calculation coming up)

Imagine your pump runs at a pretty high speed, say 20 000rpm. That's 333 revolutions per second, or 120 000 degrees per second. The Arduino is clocked at 16MHz, so in the time it takes to execute a single cycle instruction (or, put another way, the rate it "polls" its interrupts), your motor shaft will have rotated 0.0075 of a degree.

Do you really need to be that responsive?