Eremote Thymio 2000 (3 / 4 steg)
Steg 3: Programmera roboten
<! DOCTYPE aesl-source >
< nätverk >
<!--lista över globala händelser-->
<!--lista med konstanter-->
<!--Visa sökord staten-->
< sökord flagga = "true" / >
<!----> nod thymio-II
< nodnamnet = "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
Ring math.min (rc5_speed_t, rc5_speed_t, vmax)
Ring math.max (rc5_speed_t, rc5_speed_t, vmin)
Ring math.min (rc5_speed_l, rc5_speed_l, vmax)
Ring 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
OnEvent button.left
om button.left==1 sedan
rc5_speed_t = -200
slutet
callsub setmotor
OnEvent button.right
om button.right==1 sedan
rc5_speed_t = 200
slutet
callsub setmotor
OnEvent button.center
om button.center==1 sedan
rc5_speed_t = 0
rc5_speed_l = 0
slutet
callsub setmotor
OnEvent button.backward
om button.backward==1 sedan
om rc5_speed_t! = 0 då
rc5_speed_t = 0
annat
rc5_speed_l = rc5_speed_l-200
slutet
slutet
callsub setmotor
OnEvent button.forward
om button.forward==1 sedan
om rc5_speed_t! = 0 då
rc5_speed_t = 0
annat
rc5_speed_l = rc5_speed_l + 200
slutet
slutet
callsub setmotor
OnEvent knappar
När button.backward==1 och button.forward==1 göra
rc5_speed_l = 0
slutet
När button.right==1 och button.left==1 göra
rc5_speed_t = 0
slutet
callsub setmotor
OnEvent timer0
#Body färg puls
led_pulse = led_pulse + 1
om led_pulse > 0 då
Ring leds.top (led_pulse, 0, led_pulse)
om led_pulse > 40 sedan
led_pulse =-64
slutet
annat
Temp =-led_pulse/2
kalla leds.top (temp, 0, temp)
slutet
OnEvent rc5
om rc5.command! = 0 då
om rc5.command == 2 sedan
om rc5_speed_t! = 0 då
rc5_speed_t = 0
annat
rc5_speed_l = rc5_speed_l + 200
slutet
ElseIf rc5.command == 4 sedan
rc5_speed_t = -200
ElseIf rc5.command == 8 då
om rc5_speed_t! = 0 då
rc5_speed_t = 0
annat
rc5_speed_l = rc5_speed_l-200
slutet
ElseIf rc5.command == 6 sedan
rc5_speed_t = 200
ElseIf rc5.command == 5 sedan
rc5_speed_t = 0
rc5_speed_l = 0
slutet
RC5.Command = 0
slutet
OnEvent prox
kalla sound.system(-1)
kalla leds.temperature(0,0)
kalla leds.top(0,0,0)
kalla leds.circle(0,0,0,0,0,0,0,0)
Om prox.horizontal[2] > 3000 och rc5_speed_l > 0 då
rc5_speed_l = 0
slutet
Om prox.horizontal[0] > 1500 och prox.horizontal[6] & lt; 1000 och rc5_speed_l > 0 då rc5_speed_t = 300
slutet
Om prox.horizontal[6] > 1500 och prox.horizontal[0] & lt; 1000 och rc5_speed_l > 0 då rc5_speed_t =-300
slutet < / nod >
< / nätverk >