Briefly, my question is: How fast can one change pinMode back and forth?
I'm working on a set of drum triggers, and I'll have a bunch of analog sensors to read. For each trigger, I'm using a peak detector circuit with a diode, op amp, and capacitor that holds a voltage until I get a chance to take a reading via an analog pin. Once I've got the reading, I want to drain the capacitor to reset the circuit. I figure the way to do this is something like this:
// switch pin connected to the capacitor to low-impedance mode
pinMode(drainPin,OUTPUT); // delay here to allow chip to stabilize?
// drain the capacitor
digitalWrite(drainPin,LOW); // allow time to drain capacitor to zero?
// switch drain pin back to high-impedance mode
pinMode(drainPin,INPUT();
I don't have an oscilloscope so I can't really figure out a good way to test if this is going to work the way I expect it to or not. (Aside from trial and error!) Do I need to insert a delay to let the chip stabilize a bit, or does the pin change modes more or less instantaneously?
And when I switch the pin to OUTPUT mode, isn't it already in a LOW state? (That's my impression from reading the reference.) In other words, can I just skip the middle statement?
And does anyone know how long it takes to drain a 1µF capacitor through an input pin? Will I need a delay before switching back to INPUT mode to be sure the capacitor is drained?
I sure would appreciate any insight on this. Thanks in advance!
Chip