October 2004

Edge Detection

Most of the time, you don’t need to know whether a switch is on or off so much as you need to know when it changed. You want to know when it turned on or when it turned off. In other words, you want to find the edge of the transition from on to off, or vice versa. This is often called edge detection.

The basic idea is that you check not only what the state of the switch is, but what the state was the last time you checked, and compare the two. Here’s an example in PicBasic Pro:

Continue Reading »

PicBasic Pro
Arduino/Wiring

Permalink

Debouncing a digital input

Any switch is made of two conductive mechanical contacts that are either touching each other (closed circuit) or not (open circuit). When they make contact, the contact is not always perfect. For the fraction of s second before the contact is complete, the circuit may make contact and be broken several times. When you read this input on a microcontroller, you’ll see a rapid switching from 0 to 1 over a few milliseconds until the contact is final.

Continue Reading »

PicBasic Pro
Arduino/Wiring

Permalink