Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ Creator & Designer Forum Discussions

Anonymous
Not applicable

Hello all,

   

Please guide me coding this 4x4 Matrix. Please tell me,

   

Will I be able to read the Button press with API- CapSense_GetMatrixButtonPos(uint32 widget, uint* pos)?

   

Do I need to write it for each of the BTN i.e. 16 times as it was with Normal BTNs scanned individually? Or calling it once will work; while assigning particular o/p's to each BTN, as I have done in my code?

   

(Please ref. it in attached project, correct & guide me wherever needed)

   

In this API, CapSense_GetMatrixButtonPos(uint32 widget, uint* pos)- the POINTER * pos will return 2 values, namely pos[0]=Column position & pos[1]=Row position. This means that it's pointing to the elements of an array, right? I want to ask, if I wish to check their Pos by row & column how can I do that? I mean I wish to have it indicating o/p LED's for corresponding ROW & COL @ BTN pressed.

   

Will the GetMatrixButtonPos() will give me the active button number? If it does; to check the row & column position of same button, DO I need to read the array as we do in 'C'?

   

OR will it also give me the row & column position with button number?

   

Guys Please help, waiting.

   

Thanks & Regards-

   

Amit

0 Likes
1 Solution
ETRO_SSN583
Level 9
Level 9
100 sign-ins 5 likes given 1000 replies posted

CapSense_GetMatrixButtonPos(), from datasheet, returns -

   

 

   

ne"> uint32 CapSense_GetMatrixButtonPos(uint32 widget, uint8* pos)
Description: If a finger is present on matrix buttons, this function calculates the row and column position
of the finger. Returns a ‘1’ if a finger is on the matrix buttons. This function is available only if
a matrix buttons are defined by the CapSense customizer.

   


Parameters: uint8 widget: Widget number. For every matrix buttons widget there are defines in this
format:
#define CapSense_"widget_name"__MB 5
Example:
#define CapSense_MY_TOUCH1__MB 5
All widget names are upper case.

   


(uint8* pos): pointer to an array of two uint8, where touch postion will be stored:
pos[0] - column position;
pos[1] - row position.

   


All widget names are upper case. The Capsense_CSHL.h file contains defines for the widget
numbers. See the Widget Constants section for details.

   


Return Value: uint8: 1 if finger is on the touchpad, 0 if not.
Side Effects: None
 

   

Returns true of the button position values you are inquiring about is pressed.

   

 

   

You would use a routine that scans your position matrix for closures, the api's do

   

not return matrix number button closed. Key problem with that method would be

   

multiple closures due to fat finger effect.

   

 

   

Regards, Dana.

View solution in original post

0 Likes
11 Replies
ETRO_SSN583
Level 9
Level 9
100 sign-ins 5 likes given 1000 replies posted

CapSense_GetMatrixButtonPos(), from datasheet, returns -

   

 

   

ne"> uint32 CapSense_GetMatrixButtonPos(uint32 widget, uint8* pos)
Description: If a finger is present on matrix buttons, this function calculates the row and column position
of the finger. Returns a ‘1’ if a finger is on the matrix buttons. This function is available only if
a matrix buttons are defined by the CapSense customizer.

   


Parameters: uint8 widget: Widget number. For every matrix buttons widget there are defines in this
format:
#define CapSense_"widget_name"__MB 5
Example:
#define CapSense_MY_TOUCH1__MB 5
All widget names are upper case.

   


(uint8* pos): pointer to an array of two uint8, where touch postion will be stored:
pos[0] - column position;
pos[1] - row position.

   


All widget names are upper case. The Capsense_CSHL.h file contains defines for the widget
numbers. See the Widget Constants section for details.

   


Return Value: uint8: 1 if finger is on the touchpad, 0 if not.
Side Effects: None
 

   

Returns true of the button position values you are inquiring about is pressed.

   

 

   

You would use a routine that scans your position matrix for closures, the api's do

   

not return matrix number button closed. Key problem with that method would be

   

multiple closures due to fat finger effect.

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Look at datasheet for description of  CapSense_GetMatrixButtonPos(). This function will fill your array Pos[2] with the position data returning whether a finger was detected.

   

 

   

See attached project corrections

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hello Bob,

   

Greetings for the day.

   

Thanks for the guidance & sorry for the late reply. I have gone through the correction you have suggested, got much of it. But I am facing problem in understanding this:

   

if(IsButtonPressed)                                    // Finger was detected on matrix
    {
        ButtonNumber = Pos[0] * 4 + Pos[1];                // Calculate which button (0..15) was pressed
    }

   

 

   

As per me, it should be as :

   

        ButtonNumber = Pos[1] * 4 + Pos[0];                // Calculate which button (0..15) was pressed

   

since Pos[1] is for Row & Pos [0] for Column;

   

it will be going the way as:

   

0     1    2    3         {    (0*4) + (0/1/2/3)    }

   

4     5    6    7         {    (1*4) + (0/1/2/3)    }

   

8     9   10  11         {    (2*4) + (0/1/2/3)    }

   

12  13  14  15         {    (3*4) + (0/1/2/3)    }

   

Is it this way or its something else?

   

If there is any reference to go through for details, please share.

   

Thanks for the track guidance. Will be waiting for the response.

   

Regards-

   

Amit

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You could count as you like it. I always use an encoding algorithm for my keypads like

   

char KeyPad[16] = {'0','1','2' ... and so on '9','A',0xff, ... and whatever you like.

   

Later in program

   

KeyPressed = KeyPad[ButtonNumber];

   

This can help in case of routing problems or design changes just to alter the KeyPad array to compensate for that.

   

 

   

Bob

Anonymous
Not applicable

Hello Bob,

   

Greetings for the day.

   

In progress to it, If I wish to have particular o/p for particular i/p(Button touch), will doing as follow work ?

   

if (ButtonNumber==0)
        {
            LED_1_Write(0);
        }else{
            LED_1_Write(1);
        }

   

if (ButtonNumber==1)
        {
            LED_2_Write(0);
        }else{
            LED_2_Write(1);
        }

   

& so on....

   

Thanks & Regards-

   

Amit

0 Likes
ETRO_SSN583
Level 9
Level 9
100 sign-ins 5 likes given 1000 replies posted

Something like -

   

 

   

LED_1_Write( ( ButtonNumber == 0 ) ? 0 : 1 );

   

LED_2_Write( ( ButtonNumber == 1 ) ? 0 : 1 );

   

 

   

Or use a CASE statement......

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

No, that might not be what you are looking for. How long does the corresponding LED have to be switched on (compared to the press of the button)

   

Only as long as the button is pressed?

   

LED switched to "On" when button is pressed, switched off with the press of another button??

   

LED kept on after button pressed for a short constant time???

   

Although it might turn out to be a dirty work of typing, but did you ever consider to use an array of functions which could reduce switching to

   

LED_Wite[ButtonNumber](LED_ON);

   

or in a loop

   

for(ii=0;ii<MaxButtons;ii++)

   

{

   

   LED_Write[ii](ii==Button?LEDON:LEDOFF);

   

}

   

Look here for this programming technique (It's only C-Language...)

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
100 sign-ins 5 likes given 1000 replies posted

LED_1_Write( ( ButtonNumber == 0 ) ? 0 : 1 );

   

LED_2_Write( ( ButtonNumber == 1 ) ? 0 : 1 );

   

 

   

This code, each time its executed, turns on the LED associated with its button, and turns off

   

all others. The LED will stay on until such time as you call this code again and that button

   

is no longer on.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

Hello Dana & Bob,

   

Greetings for the day.

   

         Sorry for the late reply, I was out with family so was really away from all. I have tried your suggestions regarding the dedicated o/p for each o/p. Found them useful, but as Bob has asked about the various durations for the o/p indication; I now have one o/p permanently ON while shifting among them as per change in the BTN pressed.

   

Now if I wish to have it OFF when I release the button, what modification do I need to do? (Touch = ON & Release =OFF)

   

Also tell about having the particular duration to hold the o/p.(Touch = ON & Release = Delay then OFF)

   

Another point is that:-                  If I wish to have only 8 LED's corresponding to 8 i/p lines (4 rows + 4 columns) & lighting ON the corresponding 2 LED's of the BTN pressed (one represents Row & other Column), What changes do I need to do? I mean something like matrixing of the LED's for the respective Row & Column of the BTN. Like:-

   

                         LED 0 (Col-0)            LED 1 (Col-1)            LED 2 (Col-2)            LED 3 (Col-3)

   

LED 4 (Row-0)         BTN-0                   BTN-1                       BTN-2                      BTN-3

   

LED 5 (Row-1)        BTN-4                   BTN-5                        BTN-6                      BTN-7

   

LED 6 (Row-2)        BTN-8                   BTN-9                        BTN-10                    BTN-11

   

LED 7 (Row-3)        BTN-12                 BTN-13                      BTN-14                    BTN-15

   

@BTN 5 = Touch => LED's 1 & 5 should light-up; @BTN 7 = Touch => LED's 3 & 5 should light-up & likewise.

   

Please guide.

   

Thanks & Regards-

   

Amit

0 Likes
Anonymous
Not applicable

Hello Dana & Bob,

   

I have been trying the variations I had mentioned in previous  comment, out of those I have got some.

   

1. I have used ternary operator suggested by you as:

   

                LED_1_Write( ( ButtonNumber == 0 ) ? 0 : 1 );

   

with that I have completed my 4x4 matrix keypad & it was OK;

   

2. Then I tried for Lighting 2 LED for 1 sensor (corresponding to the ROW & COL of that sensor) & was good on that.

   

3. Then I decided to have 5x4 matrix keypad:

   

       in this I think I need to just change the count of ROWs from 4 to 5 while configuring the matrix buttons.

   

I did that, then I assigned all 9 pins (5+4) for the sensor & 20 pins for their corrsp. LEDs & compiled & build it, it said Build Suceeded.

   

-------->>>Now I just wanted to confirm am I right in case of 5x4 matrix keypad?

   

Also if I wish to have LEDs turned OFF after some time, Do I need to Give some delay in between & then turn off the LED in code itself? Or do I have any other option? Please suggest.

   

If I wish to have the same o/p i.e. Button Numbers to be displayed on LCD how do I proceed?

   

Awaits for your responses.

   

Thanks & Regards-

   

Amit

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Turning off the LEDs:

   

You need a Timer component and a clock. Set the timer Period and the clock frequency so that the delay is your requied time to shut down the LEDs

   

When there is any button pressed

   

    Stop the Timer, Set timer period to original value, start the timer

   

 

   

When the timer expires

   

   Stop the timer, switch off all LEDs

   

 

   

Bob

0 Likes