pxt-ev3/docs/coding/roaming-1.md

32 lines
870 B
Markdown
Raw Normal View History

2018-01-06 07:04:18 +01:00
# Roaming Activity 1
```blocks
let drive: number[] = []
brick.buttonLeft.onEvent(ButtonEvent.Bumped, function () {
2018-01-06 07:04:18 +01:00
drive.push(1)
})
brick.buttonRight.onEvent(ButtonEvent.Bumped, function () {
2018-01-06 07:04:18 +01:00
drive.push(3)
})
brick.buttonUp.onEvent(ButtonEvent.Bumped, function () {
2018-01-06 07:04:18 +01:00
drive.push(4)
})
brick.buttonDown.onEvent(ButtonEvent.Bumped, function () {
2018-01-06 07:04:18 +01:00
drive.push(5)
})
pauseUntil(() => drive.length >= 5)
pause(1000)
2018-01-06 07:04:18 +01:00
music.playSoundEffectUntilDone(sounds.communicationGo)
for (let d of drive) {
if (d == 1) {
2018-02-19 16:35:08 +01:00
motors.largeC.run(50, 360, MoveUnit.Degrees)
2018-01-06 07:04:18 +01:00
} else if (d == 3) {
2018-02-19 16:35:08 +01:00
motors.largeB.run(50, 360, MoveUnit.Degrees)
2018-01-06 07:04:18 +01:00
} else if (d == 4) {
2018-02-19 16:35:08 +01:00
motors.largeBC.run(50, 360, MoveUnit.Degrees)
2018-01-06 07:04:18 +01:00
} else {
2018-02-19 16:35:08 +01:00
motors.largeBC.run(-50, 360, MoveUnit.Degrees)
2018-01-06 07:04:18 +01:00
}
}
music.playSoundEffectUntilDone(sounds.communicationGameOver)
```