Interface with the littleBits Droid Inventor Kit using Swift.
import DroidKit
let droid = Droid()
droid.onConnect {
droid.move(.forward, atSpeed: 0.5)
droid.wait(for: .seconds(2))
droid.turnWheel(.left, by: 30°)
droid.wait(for: .seconds(2))
droid.stop()
}In Xcode, go to File → Add Packages… and paste in https://github.com/tinkertanker/DroidKit.git as the package URL.
Unfortunately, the current version of Playgrounds does not support Swift Package Manager, therefore, this will be a little annoying.
Alternatively, you can just download the
DroidKit Demo.playgroundbook.
- Clone this Repository
- Create a new Playground and open it in Finder
Control-ClickorRight-ClickandShow Package Contents- Open up Contents/UserModules
- Create a folder called
DroidKit.playgroundmodule - Within
DroidKit.playgroundmodule, create a folder namedSources - Move the
.swiftfiles from this package into theSourcesfolder individually. Unfortunately you cannot nest folders within a Playground Module.
Remember to add the NSBluetoothAlwaysUsageDescription key to the Info.plist.
In English, it's "Privacy - Bluetooth Always Usage Description"
- Make sure to enable indefinite execution otherwise it will not work.
PlaygroundPage.current.needsIndefiniteExecution = true
- There seems to be issues connecting with the Droid when running on Swift Playgrounds for macOS. It's best to use Swift Playgrounds on iPad.
- Calling
Droid()will start searching for a Droid to connect to.