pxt-ev3/docs/coding/cruise-control-2.md

15 lines
342 B
Markdown
Raw Normal View History

2018-01-06 06:49:04 +01:00
# Cruise Control Activity 2
```blocks
let speed = 0;
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
2018-01-06 06:49:04 +01:00
if (speed < 100)
speed = speed + 10;
2018-02-19 16:35:08 +01:00
motors.largeBC.run(speed);
2018-01-06 06:49:04 +01:00
})
sensors.touch2.onEvent(ButtonEvent.Pressed, function () {
2018-01-06 06:49:04 +01:00
if (speed > -100)
speed = speed - 10;
2018-02-19 16:35:08 +01:00
motors.largeBC.run(speed);
2018-01-06 06:49:04 +01:00
})
```