pxt-ev3/docs/coding/roaming-2.md
Peli de Halleux ea956f1a73
Buttons rename (#287)
* renaming up/down/click to released/pressed/bump

* missing images

* fixing signature issue

* updated strings

* white lego logo
2018-01-31 08:28:00 -08:00

1.1 KiB

Roaming Activity 2

let drive: number[] = []
brick.buttonLeft.onEvent(ButtonEvent.Bumped, function () {
    drive.push(1)
    music.playSoundEffectUntilDone(sounds.systemClick)
})
brick.buttonRight.onEvent(ButtonEvent.Bumped, function () {
    drive.push(3)
    music.playSoundEffectUntilDone(sounds.systemClick)
})
brick.buttonUp.onEvent(ButtonEvent.Bumped, function () {
    drive.push(4)
    music.playSoundEffectUntilDone(sounds.systemClick)
})
brick.buttonDown.onEvent(ButtonEvent.Bumped, function () {
    drive.push(5)
    music.playSoundEffectUntilDone(sounds.systemClick)
})
brick.buttonEnter.pauseUntil(ButtonEvent.Bumped);
loops.pause(1000)
music.playSoundEffectUntilDone(sounds.communicationGo)
for (let d of drive) {
    if (d == 1) {
        motors.largeC.setSpeed(50, 360, MoveUnit.Degrees)
    } else if (d == 3) {
        motors.largeB.setSpeed(50, 360, MoveUnit.Degrees)
    } else if (d == 4) {
        motors.largeBC.setSpeed(50, 360, MoveUnit.Degrees)
    } else {
        motors.largeBC.setSpeed(-50, 360, MoveUnit.Degrees)
    }
}
music.playSoundEffectUntilDone(sounds.communicationGameOver)