How to count and control the switch press.

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How to count and control the switch press.

724 次查看
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 项奖励
回复
2 回复数

709 次查看
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 项奖励
回复

696 次查看
SBK_SBK_SBK_SBK
Contributor I
Thanks for your reply.
Surely, i will go through it.
0 项奖励
回复