Example #1
0
import logging as log
from functools import partial
from time import sleep

from tomotoio.geo import Vector
from utils import createCubes, createNavigators, releaseCubes

cubes = createCubes()
navs = createNavigators(cubes)

for i in range(2):
    def handleCollision(k, e):
        if e.collision:
            cubes[k].setSoundEffect(6 + k)

    cubes[i].motion.enableNotification()
    cubes[i].motion.addListener(partial(handleCollision, i))

try:
    while True:
        sleep(0.1)
        if all([nav.lastPosition for nav in navs]):
            break

    m = [1500, 500]
    m0 = 500
    v = [Vector(0, 0) for nav in navs]

    while True:
        sleep(0.1)
Example #2
0
import logging as log
from time import sleep

from utils import createCubes, releaseCubes

# Identify each cube by the color and the sound signal,
# and report the battery level on the console.
cubes = createCubes(initialReport=True)

try:
    for k in range(10):
        for i, c in enumerate(cubes):
            log.info("Cube #%d, Iteration #%d" % (i + 1, k + 1))
            log.info(c.getConfigProtocolVersion())
            log.info(c.toioID.get())
            log.info(c.motion.get())
            log.info(c.button.get())
            log.info(c.battery.get())
        sleep(0.5)

finally:
    # Disconnect
    releaseCubes(cubes)