Thymio playing music on graphic partition

This activity was carried out with young people aged 12-13 years who participated in the "journée oser les métiers" at EPFL in November 2014.

Here a video/audio example:

Basic idea

The idea is to track a line on the ground with one of the two ground sensors, and use the other sensor to read information, here a musical tone. The tone is made according to how dark the drawing is. But beware, the measurement is done in infrared light, so "dark" may be different from what you see. This gives a sort of unpredictable effect to what you draw.

The idea is similar to that used in the lightpainting example where instead of playing tones Thymio displays colours on its back. One could here also use barcodes on the ground for the notes, but then all becomes a little bit less poetic…

Code

The code used is as follows:

var running = 0
var counter = 0
var intensityDiff
var freq

var black 
var white
timer.period[0] = 50

call leds.prox.v(0,0)

onevent button.forward
    if button.forward == 1 then
        running = 1
        call leds.temperature(0, 0)
        white=0
        black=1000
    end

onevent button.center
    if button.center == 1 then
        running = 0
        motor.left.target = 0
        motor.right.target = 0
    end

onevent prox
    if running == 1 then
        if prox.ground.delta[0]> white then
            white=prox.ground.delta[0]
        end
        if prox.ground.delta[0]< black then
            black=prox.ground.delta[0]
        end
        intensityDiff = prox.ground.delta[1]-525
        if abs(intensityDiff) < 170 then
            motor.left.target = 115+intensityDiff/8
            motor.right.target = 115-intensityDiff/8
        else
            motor.left.target = intensityDiff/4
            motor.right.target = -intensityDiff/4
        end

        if prox.ground.delta[0]<(white-50) then
            call math.muldiv(freq, prox.ground.delta[0] - black, 200, white-black)
            call sound.freq(freq+200, 0)
        else
            call sound.freq(freq+200, -1)
        end

    end

The two blocks of code for buttons allow to start or stop the robot with the "forward" button and the "centre" button respectively.

In the rest of the code, the ground.delta [0] sensor is used to read the tones and the prox.ground.delta [1] sensor is used to follow the track. To decide the pitch of the tone, we compute the intensity of the drawing based on the values of black and white. These two references are updated continuously. Because of this continuous update, the robot should start by looking at some white and some black track.

Results

Here are some pictures of the "partitions" made by the participants:

IMAG0062.jpg
IMAG0063.jpg
IMAG0064.jpg
IMAG0067.jpg
IMAG0068.jpg

Finally there are always children who prefer to have a nice track rather than good sound. Notice that the wheels, the bottom of the door and the windows will make sounds!

IMAG0069.jpg
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License