2019年4月22日 星期一

單顆按鍵程式庫 OneButton

markdown
最近在開發的板子,因為當初僅設計一個按鍵,現在又需要進行更多的設定操作,結果外接的IO腳位不夠使用了,便上網搜尋了一下,找到了OneButton Library可以用,連結如下

https://github.com/mathertel/OneButton

它可以透過一個按鍵判斷Click、Double Click、Long Press的狀態,剛好可以滿足現在的應用了

下面是把所有OneButton的Function都列出,可以把需要的Function保留下來就好

#include "OneButton.h"
OneButton button1(GPIO_NUM_0, true);

void click1(){
......
}

void doubleclick1(){
......
}

void longPressStart1(){
......
}

void longPressStop1(){
......
}

void longPress1(){
......
}

void setup(){
    button1.attachClick(click1);
    button1.attachDoubleClick(doubleclick1);
    button1.attachLongPressStart(longPressStart1);
    button1.attachLongPressStop(longPressStop1);
    button1.attachDuringLongPress(longPress1);
}

2 則留言:

Unknown 提到...

想跟您請教一下

我想用程式庫OneButton做動作
可是我的希望它在不同的狀態下同樣的動作有不同的效果

Matt 提到...

可以增加一個全域變數,作為進入OneButton後的判斷,讓OneButton知道現在是甚麼狀態而做出不同的效果,希望能幫到你喔

Free ERP on the Raspberry Pi (odoo)

  #更新系統軟體 sudo apt update && sudo apt upgrade -y #安裝資料庫 sudo apt install postgresql -y #安裝py程序 sudo apt install python3-pip -y #安裝od...