Paso 3: Programar el Robot
<! Aesl-fuente de DOCTYPE >
red de < >
<!--lista de eventos-->
<!--lista de constantes-->
<!--Mostrar palabras clave estado-->
< bandera palabras clave = "true" / >
<!--nodo thymio-II-->
< nombre de nodo = "thymio-II" > var temp
var rc5_speed_l
var rc5_speed_t
var vmin =-600
var vmax = 600
var led_pulse
Timer.period[0]=20
Sub setmotor
Llame a math.min (rc5_speed_t, rc5_speed_t, vmax)
Llame a math.max (rc5_speed_t, rc5_speed_t, vmin)
Llame a math.min (rc5_speed_l, rc5_speed_l, vmax)
Llame a math.max (rc5_speed_l, rc5_speed_l, vmin)
motor.Left.Target = rc5_speed_l + rc5_speed_t
motor.Right.Target = rc5_speed_l - rc5_speed_t
button.left de onEvent
Si button.left==1 entonces
rc5_speed_t = -200
final
callsub setmotor
button.right de onEvent
Si button.right==1 entonces
rc5_speed_t = 200
final
callsub setmotor
button.center de onEvent
Si button.center==1 entonces
rc5_speed_t = 0
rc5_speed_l = 0
final
callsub setmotor
button.backward de onEvent
Si button.backward==1 entonces
Si rc5_speed_t! = 0 entonces
rc5_speed_t = 0
otra cosa
rc5_speed_l = rc5_speed_l-200
final
final
callsub setmotor
button.forward de onEvent
Si button.forward==1 entonces
Si rc5_speed_t! = 0 entonces
rc5_speed_t = 0
otra cosa
rc5_speed_l = rc5_speed_l + 200
final
final
callsub setmotor
botones de onEvent
Cuando button.backward==1 y button.forward==1 do
rc5_speed_l = 0
final
Cuando button.right==1 y button.left==1 do
rc5_speed_t = 0
final
callsub setmotor
timer0 onEvent
Pulso de color #Body
led_pulse = led_pulse + 1
Si led_pulse > 0 entonces
llamar a leds.top (led_pulse, 0, led_pulse)
Si led_pulse > 40 entonces
led_pulse = -64
final
otra cosa
Temp de =-led_pulse/2
llamar al leds.top (temp, 0, temp)
final
rc5 onEvent
Si rc5.command! = 0 entonces
Si rc5.command == 2 entonces
Si rc5_speed_t! = 0 entonces
rc5_speed_t = 0
otra cosa
rc5_speed_l = rc5_speed_l + 200
final
elseif rc5.command == 4 entonces
rc5_speed_t = -200
elseif rc5.command == 8 entonces
Si rc5_speed_t! = 0 entonces
rc5_speed_t = 0
otra cosa
rc5_speed_l = rc5_speed_l-200
final
elseif rc5.command == 6 entonces
rc5_speed_t = 200
elseif rc5.command == 5 entonces
rc5_speed_t = 0
rc5_speed_l = 0
final
RC5.Command = 0
final
prox onEvent
llamar al sound.system(-1)
llamar al leds.temperature(0,0)
llamar al leds.top(0,0,0)
llamar al leds.circle(0,0,0,0,0,0,0,0)
Si prox.horizontal[2] > 3000 y rc5_speed_l > 0 entonces
rc5_speed_l = 0
final
Si prox.horizontal[0] > 1500 y prox.horizontal[6] & lt; 1000 y rc5_speed_l > 0 then rc5_speed_t = 300
final
Si prox.horizontal[6] > 1500 y prox.horizontal[0] & lt; 1000 y rc5_speed_l > 0 then rc5_speed_t = -300
final < / nodo >
< / red >