P5tCube
Hierarchy
↳ P5tCube
Index
Constructors
Properties
- angle
- batteryLevel
- bleProtocolVersion
- buttonPressed
- cube
- flat
- magnet
- name
- posture
- sensorX
- sensorY
- shakeLevel
- standardId
- x
- y
- angleTypeId
- easeTypeId
- magnetId
- moveTypeId
- postureId
- rotateTypeId
- seId
- shakeLevelId
Methods
- addEventListener
- configMagnet
- connect
- connectP5tCube
- disconnect
- distanceToCube
- distanceToXY
- move
- moveTo
- moveToCube
- moveToMulti
- normalizeAngleDegrees
- normalizeAngleRadian
- onPositionIdChanged
- onStandardIdChanged
- playMelody
- playSE
- playSingleNote
- relativeAngleToXY
- rotate
- setFrameRate
- stop
- turnLightOff
- turnLightOn
- turnLightOnRGB
- turnLightOnRGBA
- turnTo
- turnToCube
- turnToXY
- connectNewCube
- connectNewP5tCube
Constructors
constructor
+ new P5tCube(cube
: CubeBase): P5tCube
Inherited from Cube.constructor
Defined in cube/cube.ts:48
Parameters:
Name | Type |
---|---|
cube | CubeBase |
Returns: P5tCube
Properties
angle
• angle: number | undefined = undefined
Defined in cube/cube.ts:37
batteryLevel
• batteryLevel: number | undefined = undefined
Inherited from Cube.batteryLevel
Defined in cube/cube.ts:44
bleProtocolVersion
• bleProtocolVersion: string | undefined = undefined
Inherited from Cube.bleProtocolVersion
Defined in cube/cube.ts:45
buttonPressed
• buttonPressed: boolean | undefined = undefined
Inherited from Cube.buttonPressed
Defined in cube/cube.ts:43
Protected
cube
• cube: CubeBase | undefined = undefined
Defined in cube/cube.ts:48
flat
• flat: boolean | undefined = undefined
Defined in cube/cube.ts:39
magnet
• magnet: string | undefined = undefined
Defined in cube/cube.ts:42
name
• name: string | undefined = undefined
Defined in cube/cube.ts:46
posture
• posture: string | undefined = undefined
Defined in cube/cube.ts:40
sensorX
• sensorX: number | undefined = undefined
Defined in cube/cube.ts:35
sensorY
• sensorY: number | undefined = undefined
Defined in cube/cube.ts:36
shakeLevel
• shakeLevel: number | undefined = undefined
Inherited from Cube.shakeLevel
Defined in cube/cube.ts:41
standardId
• standardId: string | undefined = undefined
Inherited from Cube.standardId
Defined in cube/cube.ts:38
x
• x: number | undefined = undefined
Defined in cube/cube.ts:33
y
• y: number | undefined = undefined
Defined in cube/cube.ts:34
Static
angleTypeId
▪ angleTypeId: object = CubeMotorChar.angleTypeId
Inherited from Cube.angleTypeId
Defined in cube/cube.ts:25
Type declaration:
absEfficient: 0 = 0
absNegativeDir: 2 = 2
absPositiveDir: 1 = 1
noRotate: 5 = 5
relNegativeDir: 4 = 4
relPositiveDir: 3 = 3
sameAsCurrent: 6 = 6
Static
easeTypeId
▪ easeTypeId: object = CubeMotorChar.easeTypeId
Inherited from Cube.easeTypeId
Defined in cube/cube.ts:24
Type declaration:
accel: 1 = 1
accelDecel: 3 = 3
constant: 0 = 0
decel: 2 = 2
Static
magnetId
▪ magnetId: object = CubeSensorChar.magnetId
Defined in cube/cube.ts:22
Type declaration:
noMagnet: "noMagnet" = "noMagnet"
pattern1: "pattern1" = "pattern1"
pattern2: "pattern2" = "pattern2"
pattern3: "pattern3" = "pattern3"
pattern4: "pattern4" = "pattern4"
pattern5: "pattern5" = "pattern5"
pattern6: "pattern6" = "pattern6"
Static
moveTypeId
▪ moveTypeId: object = CubeMotorChar.moveTypeId
Inherited from Cube.moveTypeId
Defined in cube/cube.ts:23
Type declaration:
efficient: 0 = 0
rotate1st: 2 = 2
withoutBack: 1 = 1
Static
postureId
▪ postureId: object = CubeSensorChar.postureId
Defined in cube/cube.ts:20
Type declaration:
back: "back" = "back"
bottom: "bottom" = "bottom"
front: "front" = "front"
left: "left" = "left"
right: "right" = "right"
top: "top" = "top"
Static
Readonly
rotateTypeId
▪ rotateTypeId: object = { efficient: 'efficient', clockwise: 'clockwise', counterClockwise: 'counterClockwise', } as const
Inherited from Cube.rotateTypeId
Defined in cube/cube.ts:27
Type declaration:
clockwise: "clockwise" = "clockwise"
counterClockwise: "counterClockwise" = "counterClockwise"
efficient: "efficient" = "efficient"
Static
seId
▪ seId: object = CubeSoundChar.seId
Defined in cube/cube.ts:19
Type declaration:
cancel: 2 = 2
cursor: 3 = 3
effect1: 9 = 9
effect2: 10 = 10
enter: 0 = 0
get1: 6 = 6
get2: 7 = 7
get3: 8 = 8
matIn: 4 = 4
matOut: 5 = 5
selected: 1 = 1
Static
shakeLevelId
▪ shakeLevelId: object = CubeSensorChar.shakeLevelId
Inherited from Cube.shakeLevelId
Defined in cube/cube.ts:21
Type declaration:
level1: 1 = 1
level10: 10 = 10
level2: 2 = 2
level3: 3 = 3
level4: 4 = 4
level5: 5 = 5
level6: 6 = 6
level7: 7 = 7
level8: 8 = 8
level9: 9 = 9
noDetection: 0 = 0
Methods
addEventListener
▸ addEventListener(type
: string, listener
: CubeListner): void
Inherited from Cube.addEventListener
Defined in cube/cube.ts:106
Register callback from upper layer.
Parameters:
Name | Type | Description |
---|---|---|
type | string | Support following types. - 'buttonpress' - 'buttonrelease' - 'batterylevelchange' - 'sensorflat' - 'sensorcollision' - 'sensordoubletap' - 'sensorposturechange' - 'sensorshakelevelchange' - 'sensormagnetchange' - 'positionid' - 'standardid' |
listener | CubeListner | - |
Returns: void
configMagnet
▸ configMagnet(enable
: boolean): void
Inherited from Cube.configMagnet
Defined in cube/cube.ts:779
Enable/Disable magnet function.
Parameters:
Name | Type | Description |
---|---|---|
enable | boolean | boolean value. set true to enable and false to disable. |
Returns: void
connect
▸ connect(): Promise‹Cube›
Defined in cube/cube.ts:61
Connect to the toio™Core Cube.
Returns: Promise‹Cube›
Promise. resolve
includes a Cube instance.
connectP5tCube
▸ connectP5tCube(): Promise‹P5tCube›
Defined in p5tCube.ts:12
Connect to the toio™Core Cube.
Returns: Promise‹P5tCube›
Promise. resolve
includes a P5tCube instance.
disconnect
▸ disconnect(): void
Inherited from Cube.disconnect
Defined in cube/cube.ts:83
Disconnet from the toio™Core Cube.
Returns: void
distanceToCube
▸ distanceToCube(cube
: Cube): number
Inherited from Cube.distanceToCube
Defined in cube/cube.ts:683
Calculate distance from this Cube to the specified Cube.
Parameters:
Name | Type | Description |
---|---|---|
cube | Cube | aim cube instance. |
Returns: number
Distance from this Cube to the specified Cube.
distanceToXY
▸ distanceToXY(x
: number, y
: number): number
Inherited from Cube.distanceToXY
Defined in cube/cube.ts:665
Calculate distance from this Cube to the specified coordinate.
Parameters:
Name | Type | Description |
---|---|---|
x | number | X value of the target coordinate. |
y | number | Y value of the target coordinate. |
Returns: number
Distance from this Cube to the specified coordinate.
move
▸ move(left
: number, right
: number, duration
: number): void
Defined in cube/cube.ts:455
Move with specified speed/time.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
left | number | - | Left motor speed. Negative value means back direction. -115 to -8, 8 to 115, and 0 integer value. |
right | number | - | Right motor speed. Negative value means back direction. -115 to -8, 8 to 115, and 0 integer value. |
duration | number | 0 | Motor control duration in msec. 0-2550( 0: Eternally ). |
Returns: void
moveTo
▸ moveTo(aim
: object, maxSpeed
: number, moveType
: 0, easeType
: 0, timeout
: number): void
Defined in p5tCube.ts:74
Move to specified coordinate/angle.
Parameters:
▪ aim: object
object including following properties. x, y: coordinate of aimed point. angle(Optional): Cube's angle at the goal point. angleType(Optional): angleTypeId value. See the spec
Name | Type |
---|---|
angle? | undefined | number |
angleType? | undefined | number |
x | number |
y | number |
▪ maxSpeed: number
8 to 115, and 0 integer value.
▪Default value
moveType: 0= CubeMotorChar.moveTypeId.efficient
(Optional)moveTypeId value. default is moveTypeId.efficient
▪Default value
easeType: 0= CubeMotorChar.easeTypeId.constant
(Optional)easeTypeId value. default is easeTypeId.constant
▪Default value
timeout: number= 5
(Optional)timeout in sec. default is 5 sec. 1-255 sec. 0 means exceptionally 10 sec.
Returns: void
moveToCube
▸ moveToCube(cube
: Cube, maxSpeed
: number, moveType
: 0, easeType
: 0, timeout
: number): void
Inherited from Cube.moveToCube
Defined in cube/cube.ts:533
Move to specified cube's position.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
cube | Cube | - | aim cube instance. |
maxSpeed | number | - | 8 to 115, and 0 integer value. |
moveType | 0 | CubeMotorChar.moveTypeId.efficient | (Optional)moveTypeId value. default is moveTypeId.efficient |
easeType | 0 | CubeMotorChar.easeTypeId.constant | (Optional)easeTypeId value. default is easeTypeId.constant |
timeout | number | 5 | (Optional)timeout in sec. default is 5 sec. 1-255 sec. 0 means exceptionally 10 sec. |
Returns: void
moveToMulti
▸ moveToMulti(aims
: object[], maxSpeed
: number, moveType
: 0, easeType
: 0, isAppend
: boolean, timeout
: number): void
Overrides Cube.moveToMulti
Defined in p5tCube.ts:99
Move to specified several coordinate/angle.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
aims | object[] | - | object array each aim includes following properties. x, y: coordinate of aimed point. angle(Optional): Cube's angle at the goal point. angleType(Optional): angleTypeId value. See the spec |
maxSpeed | number | - | 8 to 115, and 0 integer value. |
moveType | 0 | CubeMotorChar.moveTypeId.efficient | (Optional)moveTypeId value. default is moveTypeId.efficient |
easeType | 0 | CubeMotorChar.easeTypeId.constant | (Optional)easeTypeId value. default is easeTypeId.constant |
isAppend | boolean | false | (Optional)true: append to existing mutiple aim command. false: overwrite existing command. |
timeout | number | 5 | (Optional)timeout in sec. default is 5 sec. 1-255 sec. 0 means exceptionally 10 sec. |
Returns: void
Protected
normalizeAngleDegrees
▸ normalizeAngleDegrees(angle
: number): number
Inherited from Cube.normalizeAngleDegrees
Defined in cube/cube.ts:741
Normalize the specified angle in Degrees within [0-360]
Parameters:
Name | Type | Description |
---|---|---|
angle | number | Normalization target angle. |
Returns: number
Normalized angle in Degrees.
Protected
normalizeAngleRadian
▸ normalizeAngleRadian(angle
: number): number
Inherited from Cube.normalizeAngleRadian
Defined in cube/cube.ts:759
Normalize the specified angle in Radian within [(-Math.PI)-Math.PI]
Parameters:
Name | Type | Description |
---|---|---|
angle | number | Normalization target angle. |
Returns: number
Normalized angle in Radian.
Protected
onPositionIdChanged
▸ onPositionIdChanged(info
: positionIdInfo): void
Overrides Cube.onPositionIdChanged
Defined in p5tCube.ts:29
For prepared callback function cubePositionIdChanged
.
Parameters:
Name | Type |
---|---|
info | positionIdInfo |
Returns: void
Protected
onStandardIdChanged
▸ onStandardIdChanged(info
: standardIdInfo): void
Overrides Cube.onStandardIdChanged
Defined in p5tCube.ts:39
For prepared callback function cubeStandardIdChanged
.
Parameters:
Name | Type |
---|---|
info | standardIdInfo |
Returns: void
playMelody
▸ playMelody(melody
: object[]): void
Inherited from Cube.playMelody
Defined in cube/cube.ts:436
Play melody specified wiht MIDI note sequence.
Parameters:
Name | Type | Description |
---|---|---|
melody | object[] | An array composed of some combinations of note and duration values. Use like below. playMelody( [ { note: 0x50, duration: 0x1E }, { note: 0x52, duration: 0x1E }, { note: 0x54, duration: 0x1E } ] ); Refer to the instruction of playSingleNote() for note/duration. |
Returns: void
playSE
▸ playSE(idSE
: number): void
Defined in cube/cube.ts:408
Play pre-installed sound effect.
Parameters:
Name | Type | Description |
---|---|---|
idSE | number | Sounde effect index value. Please make use of static seId.xxx properties in this class. |
Returns: void
playSingleNote
▸ playSingleNote(note
: number, duration
: number): void
Inherited from Cube.playSingleNote
Defined in cube/cube.ts:419
Play single MIDI note.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
note | number | - | MIDI note number 0-128. 128 is a special value for no-sound. Refer toio™Core Cube Spec: Note number and note name. |
duration | number | 30 | Sound duration in msec. 0-2550( 0: Eternally ). |
Returns: void
relativeAngleToXY
▸ relativeAngleToXY(x
: number, y
: number): number
Inherited from Cube.relativeAngleToXY
Defined in cube/cube.ts:700
Calculate relative angle from this Cube to the specified coordinate.
Parameters:
Name | Type | Description |
---|---|---|
x | number | X value of the target coordinate. |
y | number | Y value of the target coordinate. |
Returns: number
Relative angle from this Cube to the specified coordinate.
rotate
▸ rotate(speed
: number, duration
: number): void
Defined in cube/cube.ts:557
Rotate with specified speed/time.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
speed | number | - | Motor speed. Plus value means clockwise direction and the other is counter-clockwise. -115 to -8, 8 to 115, and 0 integer value. |
duration | number | 0 | Motor control duration in msec. 0-2550( 0: Eternally ). |
Returns: void
setFrameRate
▸ setFrameRate(fps
: number): void
Inherited from Cube.setFrameRate
Defined in cube/cube.ts:367
Set framerate.
Parameters:
Name | Type |
---|---|
fps | number |
Returns: void
stop
▸ stop(): void
Defined in cube/cube.ts:444
Stop moving.
Returns: void
turnLightOff
▸ turnLightOff(): void
Inherited from Cube.turnLightOff
Defined in cube/cube.ts:374
Turn the light off.
Returns: void
turnLightOn
▸ turnLightOn(color
: p5.Color, duration
: number): void
Defined in p5tCube.ts:52
Turn the light on with specified p5.Color
and duration(optional) values.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
color | p5.Color | - | p5.Color value. RGBA values are reflected. |
duration | number | 0 | Light up duration in msec. 0-2550 ( 0: Eternally ). |
Returns: void
turnLightOnRGB
▸ turnLightOnRGB(r
: number, g
: number, b
: number, duration
: number): void
Inherited from Cube.turnLightOnRGB
Defined in cube/cube.ts:386
Turn the light on with specified RGB and duration(optional) values.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
r | number | - | Red value. 0-255. |
g | number | - | Green value. 0-255. |
b | number | - | Blue value. 0-255. |
duration | number | 0 | Light up duration in msec. 0-2550 ( 0: Eternally ). |
Returns: void
turnLightOnRGBA
▸ turnLightOnRGBA(r
: number, g
: number, b
: number, a
: number, duration
: number): void
Inherited from Cube.turnLightOnRGBA
Defined in cube/cube.ts:399
Turn the light on with specified RGB, Alpha and duration(optional) values.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
r | number | - | Red value. 0-255. |
g | number | - | Green value. 0-255. |
b | number | - | Blue value. 0-255. |
a | number | - | Alpha( = Brightness ) value. 0-255. |
duration | number | 0 | Light up duration in msec. 0-2550( 0: Eternally ). |
Returns: void
turnTo
▸ turnTo(angle
: number, speed
: number, rotateType
: string, timeout
: number): void
Defined in p5tCube.ts:123
Turn to specified angle.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
angle | number | - | Aim angle. Unit depends on the setting angleMode(Default: RADIANS) |
speed | number | - | 8 to 115, and 0 integer value. |
rotateType | string | P5tCube.rotateTypeId.efficient | (Optional)rotation direction value. default is rotateType.efficient |
timeout | number | 5 | (Optional)timeout in sec. default is 5 sec. 1-255 sec. 0 means exceptionally 10 sec. |
Returns: void
turnToCube
▸ turnToCube(cube
: Cube, speed
: number, rotateType
: string, timeout
: number): void
Inherited from Cube.turnToCube
Defined in cube/cube.ts:646
Turn to specified cube's position.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
cube | Cube | - | aim cube instance. |
speed | number | - | 8 to 115, and 0 integer value. |
rotateType | string | Cube.rotateTypeId.efficient | (Optional)rotation direction value. default is rotateType.efficient |
timeout | number | 5 | (Optional)timeout in sec. default is 5 sec. 1-255 sec. 0 means exceptionally 10 sec. |
Returns: void
turnToXY
▸ turnToXY(x
: number, y
: number, speed
: number, rotateType
: string, timeout
: number): void
Defined in p5tCube.ts:142
Turn to the specified coordinate.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x | number | - | X value of the target coordinate. |
y | number | - | Y value of the target coordinate. |
speed | number | - | 8 to 115, and 0 integer value. |
rotateType | string | P5tCube.rotateTypeId.efficient | (Optional)rotation direction value. default is rotateType.efficient |
timeout | number | 5 | (Optional)timeout in sec. default is 5 sec. 1-255 sec. 0 means exceptionally 10 sec. |
Returns: void
Static
connectNewCube
▸ connectNewCube(): Promise‹Cube›
Inherited from Cube.connectNewCube
Defined in cube/cube.ts:793
Connect to new toio™Core Cube.
Returns: Promise‹Cube›
Promise. resolve
handler includes a instance of connected Cube
.
Static
connectNewP5tCube
▸ connectNewP5tCube(): Promise‹P5tCube›
Defined in p5tCube.ts:218
Connect to new toio™Core Cube.
Returns: Promise‹P5tCube›
Promise. resolve
handler includes a instance of connected P5tCube
.