Sphero Playground

This application allows you to control a Sphero Mini using JavaScript. You can do this by providing a JavaScript code snippet that includes an async function called drive which will be called with a single argument that represents the Sphero ball.

When connecting to the Sphero, you will be prompted to select a Bluetooth device. For this to work, you must make sure that you are using a browser that supports the Web Bluetooth API (e.g., Google Chrome on a laptop/desktop or the Bluefy app for iOS). You may have to modify your system settings to allow the browser to communicate with Bluetooth devices.

The sphero object has the following methods.

wake()

Wake the Sphero up. This must be your code's first command, otherwise other commands will have no effect.

sleep()

Put the Sphero to sleep.

roll(speed, direction)

Make Sphero roll at a specific speed (-255 - 255) in a specific direction (0° - 360°).

rollTime(speed, direction, duration)

Make Sphero roll at a specific speed (-255 - 255) in a specific direction (0° - 360°) for a specific duration (in milliseconds) and then come back to a complete stop.

delay(duration)

Pause sending commands to the Sphero for duration (in milliseconds).

setColor(red, green, blue)

Set the color of the Sphero's LED light Red, green, and blue values should be provided as values between 0 - 255.

aim(duration)

Run the aiming function for duration (in milliseconds). When aiming, the Sphero will turn off its main LED and turn on the back LED. Point the back LED in the opposite direction of what you want forward to be.

setBackLed(brightness)

Set the brightness (0-255) of the Sphero's back LED light.

getBatteryLevel()

Get the battery level of the Sphero.