Push button

The push button module supplies a digital signal. When the button is pressed a high signal is output, when it is not pressed a low signal is output. The following programme examples can also be applied to other digital sensors.

Push Button PCB layout
Circuit details

Push Button design symbol

Push Button circuit details
To generate a digital signal from the push button, it is connected as part of a potential divider. When the button is not pressed, it has very high resistance between its terminals (compared with the pull down resistor R4). This makes the output signal low. When the button is pressed, it has a low resistance (compared with R4) making the output high. The default push button in the XLD block is a 6 x 6 mm tact switch.
Programming
Example 1
Reading the state of the push button requires the use of the Decision box.

The push button module can be connected to any of the inputs, suppose it is connected to input D3. Then the Decision box properties need to be set like this. . . .

Using the push button as a means of starting a programme could use a flowchart like this . . .

Programme control will loop around the NO path until the push button is pressed.
Example 2
Quite often, it is useful to have the programme carry out some continuous task and at the same time monitor the state of the push button. This is possible using interrupts.

There are two parts to this programme, the main part and the interrupt routine. If the push button is not pressed then control follows the main routine (shown on the left). If the push button is pressed, then execution of the main programme is suspended and control branches to the interrupt routine shown on the right hand side. When the interrupt routine has been completed, control returns to where it left off in the main programme (via the Return box). Note: it is important to include the Enable Interrupt box before the return box (if you still want the push button to be monitored).
The Enable Interrupt box is the Interrupt Setup box with its properties set to Enabled.

The PB pressed box is the Interrupt box with the following settings:
