2015-05-12 90 views
0

我在做一個帶有arduino 4x4鍵盤和16x2 LCD的計算器。我必須用timer庫爲這個項目做timer-interupt。我之前問過這個Q,但我不知道我必須使用計時器庫。這是我的問題:如果用戶沒有按鍵盤上的任何一個按鍵30秒,計算器應該關閉。我怎樣才能做到這一點與計時器庫?Arduino中的定時器庫

+0

所以,你已經知道如何「關閉」它:計時器事件將只執行'digitalWrite()'來該引腳自行關閉 - 你需要一個外部電路。你需要在30秒後用'after()'註冊一個回調函數,並且你需要在任何按鍵時重新調度它,通過再次調用事件id和'after()'後面的'stop()'。它有效嗎? – Sigismondo

回答

0

而不是使用定時器庫,你可以使用米利斯()函數:

// setup 

long int time; 

void loop(){ 
// get input 
if(input){ 
    interpretInput(input); // For example 
    time = millis(); 
} 
if(millis()>time+30000){ // if there is more than 30 seconds between now and the last input, then call your shutdown function 
    shutdown(); 
} 
}