2x2 Key click has a 4 button keypad. The click allows multiple key presses and has a debounce circuit composed of 74HC32 quad 2-input OR gate from NXP and the SN74HC14 Hex Schmitt-Trigger Inverter from Texas Instruments. 2x2 Key click is designed to use either 3.3V or 5V power supply. The buttons can be independently read.
In electronics, two metal components tend to bounce or create multiple signals when they are in contact with each other — like when you push a button — before they get to a stable state. You want a single contact to be recorded, but the microcontroller records this as if you pressed the button many times.
So debouncing is, as the name states, the removal of bounces or spikes of low and high voltages. Graphically speaking, you want a clean line, not spikes. A debounce circuit makes sure that there are no voltage changes on the output. Thanks to it, one button press is recorded as such.
All four Schmitt-trigger outputs are connected to input pins of the logic OR gate 74HC32, whose output is directly connected to the INT pin on mikroBUS. This pin is used to signalize an interrupt to the MCU any time a button is pressed.
In this way, the MCU software can be implemented as a simple polling routine, without any delays programmed in the code (like it would be necessary if there wasn’t a hardware debouncing circuit present).
Thanks to the INT pin you can easily program a common interrupt service routine, in order to detect when a button is pressed (the state of the button changes from low to high logic level).
This table shows how the pinout on 2x2 Key click corresponds to the pinout on the mikroBUS™ socket (the latter shown in the two middle columns).
The demo initialises the TFT display and sets pins to operate in input direction. The main fucntion of the demo uses the polling method to check if inputs are on an active level. The TFT display shows the button state according to detect level.
1 void main()
5 Draw_Taster(X1, Y1, RELEASED, "T1");
6 Draw_Taster(X2, Y1, RELEASED, "T2");
7 Draw_Taster(X1, Y2, RELEASED, "T3");
8 Draw_Taster(X2, Y2, RELEASED, "T4");
12 if(Taster_Pressed(TAST1, &t1_state))
13 Draw_Taster(X1, Y1, PRESSED, "T1");
15 if(Taster_Released(TAST1, &t1_state))
16 Draw_Taster(X1, Y1, RELEASED, "T1");
18 if(Taster_Pressed(TAST2, &t2_state))
19 Draw_Taster(X2, Y1, PRESSED, "T2");
21 if(Taster_Released(TAST2, &t2_state))
22 Draw_Taster(X2, Y1, RELEASED, "T2");
24 if(Taster_Pressed(TAST3, &t3_state))
25 Draw_Taster(X1, Y2, PRESSED, "T3");
27 if(Taster_Released(TAST3, &t3_state))
28 Draw_Taster(X1, Y2, RELEASED, "T3");
30 if(Taster_Pressed(TAST4, &t4_state))
31 Draw_Taster(X2, Y2, PRESSED, "T4");
33 if(Taster_Released(TAST4, &t4_state))
34 Draw_Taster(X2, Y2, RELEASED, "T4");
36 t1_state = TAST1;
37 t2_state = TAST2;
38 t3_state = TAST3;
39 t4_state = TAST4;