How to count and control the switch press.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to count and control the switch press.

819 Views
SBK_SBK_SBK_SBK
Contributor I

if (adcResultInMv >4125)
{
GPIOA_PSOR |= 1<<PTA3 | 1<<PTA2;
GPIOA_PCOR |= 1<<PTB5;
if (GPIOA_PDIR & (1<<PTA1)) {
GPIOA_PSOR |= 1<<PTB5;
}
else {
GPIOA_PCOR |= 1<<PTB5;
}
}

 

 

In the above code, i want to count the switch press event and based on the number of switch pressed (if switch pressed >5 ) permanently turn off the Red LED.

 

 

Can anyone one help me to figure out this issue.

0 Kudos
Reply
2 Replies

804 Views
bobpaddock
Senior Contributor III
It is probably not (|=) OR that you want, rather just assignment (=).. The NXP examples are full of these bad examples. They end up clearing bits that you did not mean to clear.

Not clear how the ADC is involved here? If more than five switches are pressed turn off the LED?

Switches are not ideal devices. Unless debouced one press can look like many presses. That is detailed here along with code to debounce them:

http://www.ganssle.com/debouncing.htm



0 Kudos
Reply

791 Views
SBK_SBK_SBK_SBK
Contributor I
Thanks for your reply.
Surely, i will go through it.
0 Kudos
Reply