digitalRead()


讀回 pin 腳目前準位 (PinLevel),呼叫 digitalRead() 後,該 pin 腳會自動變為 Input Mode,無需設定。

語法

duino.digitalWrite(pin: UInt8) -> PinLevel

參數

pin:UInt8 , 指定 pin 腳

傳回值

PinLevel: HIGH 或 LOW

範例

讀取 nano51822-UDK Button2 (P0.30) ,若為 .LOW ,則點亮 LED3 (P0.20)

//
        // MARK: -- loop routine closure
        //
        duino.loop { duino in       
            // read DI pin
            if duino.digitalRead(pin: 30) == .LOW {
                duino.digitalWrite(pin: 20, .HIGH)    // LED ON
            } else {
                duino.digitalWrite(pin: 20, .LOW)     // LED OFF 
            }
            duino.delay(ms: 100)
        }

results matching ""

    No results matching ""