#### Event triggered on timer 0 period (here, 20 ms)
onevent timer0
    # Led ring animation
    call math.fill(led, 0)
    led_state = (led_state + 2) & 0xff
    fixed = led_state / 32
    led[fixed] = 32
    led[(fixed - 1) & 0x7] = 32 - (led_state & 0x1F)
    led[(fixed + 1) & 0x7] = led_state & 0x1F
    call leds.circle(led[0], led[1], led[2], led[3],
        led[4], led[5], led[6], led[7])

    # Body color pulse
    led_pulse = led_pulse + 1    
    if led_pulse > 0 then
        call leds.top(led_pulse, led_pulse, 0)
        if led_pulse > 32 then
            led_pulse = -32
        end
    else 
        call leds.top(-led_pulse, -led_pulse, 0)
    end