cruise control activities
This commit is contained in:
parent
81f406c6cc
commit
485f02ed27
@ -131,4 +131,25 @@
|
|||||||
"url":"/coding/ignition-3",
|
"url":"/coding/ignition-3",
|
||||||
"cardType": "example"
|
"cardType": "example"
|
||||||
}]
|
}]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Cruise Control
|
||||||
|
|
||||||
|
```codecard
|
||||||
|
[{
|
||||||
|
"name": "Cruise Control",
|
||||||
|
"description": "Activity 1",
|
||||||
|
"url":"/coding/cruise-control-1",
|
||||||
|
"cardType": "example"
|
||||||
|
}, {
|
||||||
|
"name": "Cruise Control",
|
||||||
|
"description": "Activity 2",
|
||||||
|
"url":"/coding/cruise-control-2",
|
||||||
|
"cardType": "example"
|
||||||
|
}, {
|
||||||
|
"name": "Cruise Control",
|
||||||
|
"description": "Activity 3",
|
||||||
|
"url":"/coding/cruise-control-3",
|
||||||
|
"cardType": "example"
|
||||||
|
}]
|
||||||
```
|
```
|
10
docs/coding/cruise-control-1.md
Normal file
10
docs/coding/cruise-control-1.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Cruise Control Activity 1
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let speed = 0;
|
||||||
|
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
|
||||||
|
if (speed < 100)
|
||||||
|
speed = speed + 10;
|
||||||
|
motors.largeBC.setSpeed(speed);
|
||||||
|
})
|
||||||
|
```
|
15
docs/coding/cruise-control-2.md
Normal file
15
docs/coding/cruise-control-2.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Cruise Control Activity 2
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let speed = 0;
|
||||||
|
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
|
||||||
|
if (speed < 100)
|
||||||
|
speed = speed + 10;
|
||||||
|
motors.largeBC.setSpeed(speed);
|
||||||
|
})
|
||||||
|
sensors.touch2.onEvent(TouchSensorEvent.Pressed, function () {
|
||||||
|
if (speed > -100)
|
||||||
|
speed = speed - 10;
|
||||||
|
motors.largeBC.setSpeed(speed);
|
||||||
|
})
|
||||||
|
```
|
28
docs/coding/cruise-control-3.md
Normal file
28
docs/coding/cruise-control-3.md
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# 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.printLine("speed: " + speed, 1)
|
||||||
|
motors.largeBC.setSpeed(speed)
|
||||||
|
}
|
||||||
|
sensors.touch2.onEvent(TouchSensorEvent.Pressed, function () {
|
||||||
|
accelerate()
|
||||||
|
update()
|
||||||
|
})
|
||||||
|
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
|
||||||
|
decelerate()
|
||||||
|
update()
|
||||||
|
})
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user