From abeb378b175b6ac99a31f40272015558539afc22 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Fri, 5 Jan 2018 21:20:00 -0800 Subject: [PATCH] reverse beeper --- docs/coding.md | 22 ++++++++++++++++++++++ docs/coding/reverse-beeper-1.md | 11 +++++++++++ docs/coding/reverse-beeper-2.md | 13 +++++++++++++ docs/coding/reverse-beeper-3.md | 21 +++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 docs/coding/reverse-beeper-1.md create mode 100644 docs/coding/reverse-beeper-2.md create mode 100644 docs/coding/reverse-beeper-3.md diff --git a/docs/coding.md b/docs/coding.md index f5a428ec..071a1834 100644 --- a/docs/coding.md +++ b/docs/coding.md @@ -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" +} +] +``` diff --git a/docs/coding/reverse-beeper-1.md b/docs/coding/reverse-beeper-1.md new file mode 100644 index 00000000..54f10c53 --- /dev/null +++ b/docs/coding/reverse-beeper-1.md @@ -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(); +``` diff --git a/docs/coding/reverse-beeper-2.md b/docs/coding/reverse-beeper-2.md new file mode 100644 index 00000000..9c3df90f --- /dev/null +++ b/docs/coding/reverse-beeper-2.md @@ -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(); +``` diff --git a/docs/coding/reverse-beeper-3.md b/docs/coding/reverse-beeper-3.md new file mode 100644 index 00000000..557883e6 --- /dev/null +++ b/docs/coding/reverse-beeper-3.md @@ -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) + } + } +}) +```