ANY-maze Help > The ANY-maze reference > The I/O page > Making I/O connections > Debouncing inputs

Debouncing inputs

Introduction

One problem with switches is that they exhibit something called contact bounce. As the name implies, this is caused by the contacts bouncing apart and back together when the switch is closed. This bounce usually lasts a very short time and so it's often irrelevant in a simple switching circuit. However, in a situation where you want to count switch activations it can be very important - imagine that an animal pressed a lever and this caused some switch contacts to close but that they then bounced 5 times - ANY-maze would read 5 lever presses!

In fact you can also see 'bounce' type effects with other input devices such as photobeams. In this case as the beam is being broken it may momentarily fluctuate between being strong enough to count as 'made' and weak enough to count as 'broken'. Again, if you are counting beam breaks this could yield an unrealistically high score.

Solving the bounce problem

The usual solution to 'bounce' is to apply what's called a debounce interval, such that the state of the switch has to be stable for this interval before being registered as a change.

By default, ANY-maze will automatically apply a 20ms debounce interval to all switch inputs (whatever device they're generated by) to overcome this problem, but you can easily increase this by specifying a longer interval when you create a Input switch - this is described here.

See also:

 An introduction to on/off inputs 
 Setting up an on/off input 

© Copyright 2003-2026 Stoelting Co. All rights reserved

ANY-maze help topic T0922