How to count and control the switch press.

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to count and control the switch press.

723件の閲覧回数
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 返答(返信)

708件の閲覧回数
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 件の賞賛
返信

695件の閲覧回数
SBK_SBK_SBK_SBK
Contributor I
Thanks for your reply.
Surely, i will go through it.
0 件の賞賛
返信