pxt-ev3/docs/tutorials/coast-or-brake.md
Galen Nickel 7e9cc791ec Some edits for the new sensor/motor examples (#901)
* Some edits for the new sensor/motor examples

* article typo

* dark and bright

* fix block styling

* I like 'on'

* more block styling
2019-09-02 04:20:42 -07:00

641 B

Coast or Brake

This code example will set the brake when button A is pressed or let the motor coast (turn freely when not running) when button B is pressed. The motor is turned by one rotation to cause motion.

brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
    // tell motor to brake once the run command is done
    motors.largeB.setBrake(true)
    motors.largeB.run(100, 1, MoveUnit.Rotations)
})
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
    // tell motor to coast once the run command is done
    motors.largeB.setBrake(false)
    motors.largeB.run(100, 1, MoveUnit.Rotations)
})