本次测试是在触摸按键范例的基础上进行的,测试的目的是为了进一步掌握对Led灯的操控。这次是开始准备利用范例中提供的LED-Control()函数操作Led灯,这样代码也相应会简化了不少,但在测试时流水灯不会避开触摸的按键,达不到测试目的,最后还是改回位操作,先检测当前的Led灯,若是亮起状态就放弃不操作,以免影响触摸效果。下面是主要的代码:
//??????
void main()
{
UINT8 ch,ledx;
UINT16 value;
UINT16 err; //???????仯???
CfgFsys( ); //CH549??????????
mDelaymS(20);
mInitSTDIO( ); //????0?????
printf("TouchKey demo start ...\n");
LED_Port_Init();
TouchKey_Init();
Press_Flag = 0; //?????????
/* ?????????? */
for(ch = 8; ch!=12; ch++)
{
PowerValue[ch] = TouchKeySelect( ch,CPW_Table[ch] );
printf("%d ",PowerValue[ch] );
}
printf("\n");
while(1)
{
/* ??????? */
for(ch = 8; ch!=12; ch++)
{
value = TouchKeySelect( ch,CPW_Table[ch] );
err = ABS(PowerValue[ch],value);
if( err > DOWM_THRESHOLD_VALUE ) //???????????????????
{
if((Press_Flag & (1<<ch)) == 0) //????????????
{
printf("ch %d pressed,value:%d\n",(UINT16)ch, value);
/* ?????? */
LED_Control(ch-8,1);
}
Press_Flag |= (1<<ch);
}
else if( err < UP_THRESHOLD_VALUE ) //?????????δ????
{
if(Press_Flag & (1<<ch)) //?????
{
Press_Flag &= ~(1<<ch);
printf("ch %d up,value:%d\n",(UINT16)ch, value);
/* ?????? */
LED_Control(ch-8,0);
}
}
}
/* ????????? */
ledx++;
switch(ledx){
case 1:
if(LED2){
LED2 = 0;
mDelaymS(100);
LED2 = 1;
}
break;
case 2:
if(LED3){
LED3 = 0;
mDelaymS(100);
LED3 = 1;
}
break;
case 3:
if(LED4){
LED4 = 0;
mDelaymS(100);
LED4 = 1;
}
break;
case 4:
if(LED5){
LED5 = 0;
mDelaymS(100);
LED5 = 1;
}
ledx = 0;
}
/* ??????????? */
}
}
下图是测试的照片,在流水灯正常运行的情况下按下按键,对应的Led灯会亮起。