2.開啟 Electric imp IDE 網頁,在Device中輸入下列程式碼。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Device | |
//設定led為全域變數並使用第1腳 | |
led <- hardware.pin1; | |
//設定led為數位輸出 | |
led.configure(DIGITAL_OUT); | |
//建立一個儲存led狀態的全域變數 | |
state <- 0; | |
function blink() { | |
//state值取相反 | |
//當state=1時,1-1=0 | |
//當state=0時,1-0=1 | |
state = 1-state; | |
//輸出目前的state值到led | |
led.write(state); | |
//每0.5秒啟動imp,並執行一次 | |
imp.wakeup(0.5, blink); | |
} | |
//開始迴圈 | |
blink(); |
4.LED上應可看出明暗變化。
沒有留言:
張貼留言