import CAVR public func digitalRead(pin: UInt8) -> Bool { return _digitalRead(pin) } // slightly inefficient, if/when we have a class structure that doesn't allow // you to use analog and digital on the same pin (or read when it should write etc.) // that will be better public func digitalWrite(pin: UInt8, value: Bool) { switch pin { case 3,5,6,9,10,11: _analogWrite(pin, value ? 255 : 0) default: _digitalWrite(pin, value) } } public func pinMode(pin: UInt8, mode: Bool) { _pinMode(pin, mode) } public func analogWrite(pin: UInt8, value: UInt8) { _analogWrite(pin, value) } public func slowAnalogRead(pin: UInt8) -> UInt16 { return _slowAnalogRead(pin) } // this creates a function pointer type callback that does not capture any variables... // https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html public func analogReadAsync(pin: UInt8, callback: @escaping @convention(c) (UInt16) -> Void) { // _analogReadAsyncTest(pin) _analogReadAsync(pin, { _ in digitalWrite(pin:13, value:HIGH) }) // digitalWrite(pin:13, value:HIGH) // _analogReadAsync(pin, { v in // digitalWrite(pin:13, value:HIGH) // }) // _analogReadAsync(pin, callback) }