reverse beeper

This commit is contained in:
Peli de Halleux 2018-01-05 21:20:00 -08:00
parent 6928f9e50e
commit abeb378b17
4 changed files with 67 additions and 0 deletions

View File

@ -90,3 +90,25 @@
} }
] ]
``` ```
## Reverse Bepper
```codecard
[{
"name": "Reverse Beeper",
"description": "Activity 1",
"url":"/coding/reverse-beeper-1",
"cardType": "example"
}, {
"name": "Reverse Beeper",
"description": "Activity 2",
"url":"/coding/reverse-beeper-2",
"cardType": "example"
}, {
"name": "Reverse Beeper",
"description": "Activity 3",
"url":"/coding/reverse-beeper-3",
"cardType": "example"
}
]
```

View File

@ -0,0 +1,11 @@
# Reverse Beeper Activity 1
```blocks
loops.forever(function () {
music.playTone(440, sensors.ultrasonic4.distance());
loops.pause(50)
})
motors.largeBC.setSpeed(-20);
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
motors.stopAllMotors();
```

View File

@ -0,0 +1,13 @@
# Reverse Beeper Activity 2
```blocks
loops.forever(function () {
if (motors.largeB.speed() != 0 && sensors.ultrasonic4.distance() < 20) {
music.playTone(440, sensors.ultrasonic4.distance());
loops.pause(50)
}
})
motors.largeBC.setSpeed(-20);
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
motors.stopAllMotors();
```

View File

@ -0,0 +1,21 @@
# Reverse Beeper Activity 2
```blocks
let beep = false
beep = true
control.runInBackground(function () {
motors.largeB.setSpeed(-20)
motors.largeC.setSpeed(-20)
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear)
motors.stopAllMotors()
beep = false
})
control.runInBackground(function () {
while (beep) {
if (sensors.ultrasonic4.distance() < 20) {
music.playTone(440, sensors.ultrasonic4.distance())
loops.pause(50)
}
}
})
```