pxt-ev3/docs/coding/cruise-control-3.md
Peli de Halleux 892a2d585f
Thresholds (#222)
* add threshold blocks

* updated strings

* added gap

* reorg color/gyro blocks

* fixing sound names

* adding stop block

* fixing exanmples
2018-01-09 12:46:48 -08:00

28 lines
537 B
Markdown

# Cruise Control Activity 3
```blocks
let speed = 0
function decelerate() {
if (speed > -100) {
speed = speed - 10
}
}
function accelerate() {
if (speed < 100) {
speed = speed + 10
}
}
function update() {
brick.clearScreen()
brick.showString("speed: " + speed, 1)
motors.largeBC.setSpeed(speed)
}
sensors.touch2.onEvent(TouchSensorEvent.Pressed, function () {
accelerate()
update()
})
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
decelerate()
update()
})
```