Skip to content

clignoter toutes les 1s

massteff edited this page Sep 10, 2018 · 5 revisions

Précédent | Home | Timide)

Ex 10.2

Donnée

Faire clignoter toutes les secondes le Thymio d'une lumière rouge

Thymio VPL

configuration

Code

# variables for state
var state[4] = [0,0,0,0]
var new_state[4] = [0,0,0,0]

# stop timer 0
timer.period[0] = 0
# reset outputs
call sound.system(-1)
call leds.top(0,0,0)
call leds.bottom.left(0,0,0)
call leds.bottom.right(0,0,0)
call leds.circle(0,0,0,0,0,0,0,0)

# subroutine to display the current state
sub display_state
call leds.circle(0,state[1]*32,0,state[3]*32,0,state[2]*32,0,state[0]*32)

onevent buttons
when button.forward == 1 do
if state[0] == 0 then
call leds.top(32,0,0)
timer.period[0] = 1000
emit pair_run 0
end
end


onevent timer0
timer.period[0] = 0
if state[0] == 0 then
new_state[0] = 1
call leds.top(0,0,0)
timer.period[0] = 1000
emit pair_run 1
end

if state[0] == 1 then
new_state[0] = 0
call leds.top(32,0,0)
timer.period[0] = 1000
emit pair_run 2
end

call math.copy(state, new_state)
callsub display_state

Clone this wiki locally