按钮轮询如何取最后一次的触发

2019-07-20 12:25发布

采用非中断按钮,长时间按按钮,如何取最后一次的信息。[mw_shl_code=c,true]u8 KEY_Scan(u8 mode)
{         
        static u8 key_up=1;
        if(mode)key_up=1;
        if(key_up&&((WARING_KEY==0 && close_judge==0)||(WARING_KEY==1 && close_judge==1)||(INTRUDE_KEY==1 && Relay12==1)||(DOOR_KEY==0)))
        {
                delay_ms(10);
                key_up=0;
                if(WARING_KEY==0 && close_judge==0) return 3;
                else if(WARING_KEY==1 && close_judge==1) return 4;
                else if(INTRUDE_KEY==1 && Relay12==1) return 2;
                else if(DOOR_KEY==0) return 1;
        }
        else if((WARING_KEY==0 && close_judge==1)||(WARING_KEY==1 && close_judge==0)||(INTRUDE_KEY==1 && Relay12==1)||(DOOR_KEY==1))
                key_up=1;
        return 0;
}

void Button_watch(void)
{
        static u8 key;
        key=KEY_Scan(1);
        if(key)
        {
                switch(key)
                {
                        case DOOR_PRES:
                                        if(close_judge)
                                        return;
                                        state_door[0]=1;
                                        state_door[1]=1;
                                        state_door[2]=1;
                                        return;
                        case WAR_INT:
                                if(close_judge || close_intrude || time_out_war)
                                        return;       
                                state_door[0]=1;
                                state_door[1]=3;
                                state_door[2]=1;
                                close_intrude=1;
                                return;
                        case WAR_STA:
                                state_door[0]=1;
                                state_door[1]=4;
                                state_door[2]=0;
                                close_judge=1;
                                OPEN_ALL_DOOR(2048);
                                return;
                        case WAR_END:
                                state_door[0]=1;
                                state_door[1]=4;
                                state_door[2]=1;
                                close_judge=0;               
                                close_intrude=0;
                                time_out_war=0;
                                CLOSE_ALL_DOOR(2048);
                                return;
                }
        }
}[/mw_shl_code]


主程序
[mw_shl_code=applescript,true]while(1)
{
……
Button_watch();
……
}[/mw_shl_code]
怎么做到连续按下按钮,只触发一次
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
9条回答
操作系统
1楼-- · 2019-07-20 16:52
 精彩回答 2  元偷偷看……
烟酒不沾
2楼-- · 2019-07-20 22:37
你说的连续按,是长按不松开还是间隔很短的重按?处理方法是不一样的!
Eternal单人行
3楼-- · 2019-07-21 02:21
烟酒不沾 发表于 2017-8-23 11:26
你说的连续按,是长按不松开还是间隔很短的重按?处理方法是不一样的!

长按不松开,但主循环检测到多次触发
操作系统
4楼-- · 2019-07-21 07:23
 精彩回答 2  元偷偷看……
Eternal单人行
5楼-- · 2019-07-21 07:36
操作系统 发表于 2017-8-23 12:08
楼主是不是想解决单击,双击,三击 等 问题?如何只是要求检测长按,短按的问题.好办.等按钮松开时才去动作.长 ...

只能用
while(按钮闭合){};
去掉长按吗?有没有不影响时间的方法
操作系统
6楼-- · 2019-07-21 09:44
Eternal单人行 发表于 2017-8-23 13:10
只能用
while(按钮闭合){};
去掉长按吗?有没有不影响时间的方法

当然有了.你这个方法是怎么来的.

一周热门 更多>