Voice Recorder Thymio

Required additional Materials:  MicroSD Class 4 Card 

Voice Recorder Thymio Project

This code transforms Thymio into a sound recorder.  Watch the video to see how it works:

Thymio will be Red when recording in progress. Thymio will be Green when Playing back a recording.


# This script transforms your Thymio into a sound recorder.
# Pressing on the center button starts the recording,
# and pressing a second time stops it.
# Pressing on the forward button replays a recorded sound.
# The left and right buttons select a sound bank whose
# index is shown by the yellow light.

# index of the song to record/play
var song_index = 0
# 1 if recording, 0 otherwise
var recording = 0
# temporary array for top leds
var leds[8]
# temporary variable for iteration
var i

# default display: song_index == 0
call leds.circle(32, 0, 0, 0, 0, 0, 0, 0)

sub update_display
# for each led
for i in 0:7 do
# if it corresponds to the sound index,
# turn on, otherwise turn off
if song_index == i then
leds[i] = 32
else
leds[i] = 0
end
end
# update the display using the temporary array
call leds.circle(leds[0], leds[1], leds[2], leds[3], leds[4], leds[5], leds[6], leds[7])

onevent button.center
# when button is pressed
if button.center == 1 then
if recording == 0 then
# if no recording is in progress,
# turn red and start one
call leds.top(32, 0, 0)
call sound.record(song_index)
recording = 1
else
# if recording is in progress,
# stop it and turn off light
call leds.top(0, 0, 0)
call sound.record(-1)
recording = 0
end
end

onevent button.forward
# when button is pressed and no recording is in progress
if button.forward == 1 and recording == 0 then
# turn green and replay sound
call leds.top(0, 32, 0)
call sound.replay(song_index)
end

onevent button.left
# when button is pressed
if button.left == 1 then
# decrement song index (in mod 8 integers)
song_index = (song_index + 7) % 8
callsub update_display
end

onevent button.right
# when button is pressed
if button.right == 1 then
# increment song index (in mod 8 integers)
song_index = (song_index + 1) % 8
callsub update_display
end

onevent button.backward
if button.backward == 1 then
call sound.play(-1)
end

onevent sound.finished
# turn off the light
call leds.top(0, 0, 0)