5 ms·
They're not really software resistors; they're hardware that's controllable from software. </pedantry> And this is very useful; this will definitely save some
by sketerpot 17y ago
They're not really software resistors; they're hardware that's controllable from software. </pedantry>
And this is very useful; this will definitely save some resistor wiring. Now if only there was some easy way to debounce a switch in software....
- kd5bjo 17y agoIt's not too bad: keep an exponentially decaying average of the pin state, and use some hysteresis (different levels for on/off) on that value. You should be most of the way there. It'll take (worst case) 8 bits for the average and 1 for the current state. You could probably still get reasonable results with a 7-bit average so that the whole thing still fits in a byte of RAM.
- carterschonwald 17y agoIs it just me, or does this idiom sound very similar to one of the critiqued "incorrect" programming idioms in the recently analyzed breathalyzer code?
- kd5bjo 17y agoYes; it's almost identical. It's one of the simplest digital low-pass filters you can write. Basically, it does the same thing that an analog R/C filter would do (given sufficient precision and sampling rates). The issue with the breathalyzer code wasn't that the algorithm was incorrect, but that the programmer used the wrong algorithm.
- mindslight 17y agoAfter reading a button press, wait a while for the level to settle (say 50ms or so). This kind of thing is normally done from a timer interrupt that polls all buttons and saves their state for the foreground thread (I'd think this would be in the Arduino library somewhere).
- adbachman 17y agoIt (debouncing) is available as a library from the arduino site: [http://www.arduino.cc/playground/Code/Debounce](http://www.arduino.cc/playground/Code/Debounce) http://www.arduino.cc/playground/Code/Debounce](http://www.a...