Hi! I am strugling with a problem, can someone help me solve it please?
I have a keypad (4x4 matrix with diodes), I have a function which scans which button is pressed and records it in a global variable "kcode". I want to detect a combination of buttons, which prooves to be difficult. I tried various times and failed. I can not seem to send "Success multirecord" to the display. I reached to this result last.
This is not the whole code.
I have a keypad (4x4 matrix with diodes), I have a function which scans which button is pressed and records it in a global variable "kcode". I want to detect a combination of buttons, which prooves to be difficult. I tried various times and failed. I can not seem to send "Success multirecord" to the display. I reached to this result last.
This is not the whole code.
Code:
void main ()
{
KeypadScan ();/* Scan for a button pressed, working. */
RecordMultipleButtonPress ();/* Records the pressing of multiple sequential buttons, not working. */
ClearRecordMultipleButtonPress ();/* Clear the recorded combination of multiple sequential buttons, not working. */
}
void RecordMultipleButtonPress ()
{
Combination[i] = kcode; /* "kcode" is a global variable that records which button is pressed. */
i++; /* 'i' has to be a global variable. */
if (i == 4) /* If we have recorded 4 buttons in a row, start from the first element of the array again. */
i = 0;
if (Combination [0] == 0 && Combination [1] == 1 && Combination [2] == 2 && Combination [3] == 3)/* If this combination is pressed (0, 1, 2, 3), do: */
lcd_data ("Success, multirecord.");/* send "Success, multirecord." to the LCD. */
}
void ClearRecordMultipleButtonPress ()
{
if (get_timer0 () > 127)/* Every 8.128 mS, 1uS instruction clock, 64 mS per tick. */
j++; /* Must be a global variable. *//* Increment on every 8.128 mS. */
if (j > 1270) /* If more than 10.5 seconds have passed. */
{
for (i=0; i<4; i++)/* Clear the "Combination array" that has recorded the buttons pressed. */
Combination [i] = 0;
set_timer0 (0);/* Set the timer to "0". */
j = 0;/* Set the global counter variable to '0' .*/
i = 0;/* Set i to '0', or the device might start recording from the '2' array element in the next run. */
}
}
Last edited: