I2Cdev Class


I2Cdev Class 是 TWI 的延伸應用,為連接 I2C device (or chip) 類別,類相容於 I2Cdvlib 開源網站,可參考該網站自行加入多樣的 I2C 設備或晶片。

程式碼

參見 GitHub 目錄下 /contributes/I2Cdev.swift

範例

I2C-Scanner

//
    // MARK: - Arduino Like Routine
    //
    func arduinoLike(_ duino:SwiftDuino) {

        duino.log("Initialize")
        let i2c = I2Cdev()
        var addr = 0

        //
        // MARK: -- Setup Routine
        //
        duino.setup { duino in
            i2c.setup(duino: duino, dat_pin: 28, clk_pin: 29)
        }

        //
        // MARK: -- Loop Routine
        //
        duino.loop { duino in
            if let byte = i2c.readByte(address: UInt8(addr), register: 0) {
                duino.log("addr:\(addr), byte:\(byte)")
            }
            addr = loopIn(addr, min: 0, max: 127)
        }
    }

results matching ""

    No results matching ""