onevent buttons
    when button.forward==1 do #increase speed
        speed=speed+50
        if speed>500 then
            speed=500
        end
    end
    when button.backward==1 do #decrease speed
        speed=speed-50
        if speed<-300 then
            speed=-300
        end
    end
    when button.center==1 do #stop robot
        speed=0
        motor.left.target=0
        motor.right.target=0
    end