2018-02-28 02:15:12 +01:00
|
|
|
# Ignition
|
|
|
|
|
|
|
|
Explore sensor events and sensor status.
|
|
|
|
|
|
|
|
## Activity 1
|
|
|
|
|
|
|
|
Wait for a touch sensor press or ultrasonic object detection. Show an expression on the screen when they happen.
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
|
|
|
brick.showImage(images.eyesDizzy)
|
|
|
|
})
|
|
|
|
sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectDetected, function () {
|
|
|
|
brick.showImage(images.eyesTiredMiddle)
|
|
|
|
})
|
|
|
|
brick.showImage(images.eyesSleeping)
|
|
|
|
```
|
|
|
|
|
|
|
|
## Activity 2
|
|
|
|
|
|
|
|
Play some motor sounds if touch sensor `1` is pressed at the same moment when and object comes close.
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
while (true) {
|
2018-04-03 13:10:35 +02:00
|
|
|
if (sensors.touch1.isPressed() &&
|
2018-02-28 02:15:12 +01:00
|
|
|
sensors.ultrasonic4.distance() < 10) {
|
|
|
|
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
|
|
|
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Activity 3
|
|
|
|
|
|
|
|
Play some motor sounds if touch sensor `1` is pressed when both the `enter` button is pressed on the brick and an object comes close.
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
while (true) {
|
|
|
|
if (sensors.ultrasonic4.distance() < 10 &&
|
2018-04-03 13:10:35 +02:00
|
|
|
sensors.touch1.isPressed() &&
|
|
|
|
brick.buttonEnter.isPressed()) {
|
2018-02-28 02:15:12 +01:00
|
|
|
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
|
|
|
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|