Skip to main content

Basic Usage

Search and Connect to toio™Core Cube

First, call P5tCube.connectNewP5tCube() and receive P5tCube instance in Promise shown as below.

caution

This library depends on Web Bluetooth so that this API must be called in a user-action function like mouseClicked() or keyPressed() etc.

const gCubes = [];

function mouseClicked() {
P5tCube.connectNewP5tCube().then( cube => {
// 'cube' is an instance of connected toio™Core Cube.
// Now you can call any API!
gCubes.push( cube );
} );
}

Then, we can fully access to any API of p5.toio.

Use a P5tCube API

Basically, please refer to the P5tCube API reference Page. Here is a simple example.

Example: Turn the light on

// Turn the light on with white
cube?.turnLightOn( 'white' );

OK. Super simple. You can confirm the result by OpenProcessing.
OpenProcessing Sample: Turn Light On

Use a P5tId API

For P5tId class, refer to the P5tId API reference Page. And here is another sample.

Example: Is on the tile mat

if (P5tId.ColorTileMat.isOnMat(cube?.x, cube?.y)) {
background('red');
} else if (P5tId.SimpleTileMat.isOnMat(cube?.x, cube?.y)) {
// Partially, this mat overlaps with Ring Mat.
background('blue');
} else{
background('white');
}

Also, you can play immediately from the following link.
OpenProcessing Sample: Is on Tile Mat