diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 9929de99..6ba58a25 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -16,8 +16,9 @@ * [Touch Sensor Values](/tutorials/touch-sensor-values) * [What Color?](/tutorials/what-color) * [Line Following](/tutorials/line-following) - * [Green Light, Red Light](/tutorials/greenlight-redlight) + * [Red Light, Green Light](/tutorials/redlight-greenlight) * [Object Near?](/tutorials/object-near) + * [Intruder Alert](/tutorials/intruder-alert) * [Coding](/coding) * [Autonomous Parking](/coding/autonomous-parking) diff --git a/docs/static/tutorials/intruder-alert.png b/docs/static/tutorials/intruder-alert.png new file mode 100644 index 00000000..e18cac15 Binary files /dev/null and b/docs/static/tutorials/intruder-alert.png differ diff --git a/docs/static/tutorials/intruder-alert/detect-method-dropdown.png b/docs/static/tutorials/intruder-alert/detect-method-dropdown.png new file mode 100644 index 00000000..dff7fa24 Binary files /dev/null and b/docs/static/tutorials/intruder-alert/detect-method-dropdown.png differ diff --git a/docs/static/tutorials/intruder-alert/intruder-alert.gif b/docs/static/tutorials/intruder-alert/intruder-alert.gif new file mode 100644 index 00000000..36f7a40b Binary files /dev/null and b/docs/static/tutorials/intruder-alert/intruder-alert.gif differ diff --git a/docs/static/tutorials/intruder-alert/play-sound-effect-dropdown.png b/docs/static/tutorials/intruder-alert/play-sound-effect-dropdown.png new file mode 100644 index 00000000..285f5e63 Binary files /dev/null and b/docs/static/tutorials/intruder-alert/play-sound-effect-dropdown.png differ diff --git a/docs/static/tutorials/intruder-alert/set-status-light-dropdown.png b/docs/static/tutorials/intruder-alert/set-status-light-dropdown.png new file mode 100644 index 00000000..5e65e127 Binary files /dev/null and b/docs/static/tutorials/intruder-alert/set-status-light-dropdown.png differ diff --git a/docs/static/tutorials/intruder-alert/show-image-dropdown.png b/docs/static/tutorials/intruder-alert/show-image-dropdown.png new file mode 100644 index 00000000..42678aa0 Binary files /dev/null and b/docs/static/tutorials/intruder-alert/show-image-dropdown.png differ diff --git a/docs/tutorials.md b/docs/tutorials.md index 7c61ff62..4d3748dc 100644 --- a/docs/tutorials.md +++ b/docs/tutorials.md @@ -97,3 +97,16 @@ Step by step guides to coding your @boardname@. "imageUrl":"/static/tutorials/object-near.png" }] ``` + +## Infrared Sensor + +```codecard +[{ + "name": "Intruder Alert", + "description": "Build an intruder alert using the infrared sensor.", + "cardType": "tutorial", + "url":"/tutorials/intruder-alert", + "imageUrl":"/static/tutorials/intruder-alert.png" +}] +``` + diff --git a/docs/tutorials/intruder-alert.md b/docs/tutorials/intruder-alert.md new file mode 100644 index 00000000..d8843e36 --- /dev/null +++ b/docs/tutorials/intruder-alert.md @@ -0,0 +1,105 @@ +# Intruder Alert + +## Introduction @fullscreen + +The Infrared Sensor uses infrared light waves to detect proximity to the robot. Build an intruder alert using the infrared sensor. + +![Brick in simulator with infrared sensor](/static/tutorials/intruder-alert/intruder-alert.gif) + +## Step 1 + +Open the ``||sensors:Sensors||`` Toolbox drawer. Drag out an ``||sensors:on infrared||`` block onto the Workspace (you can place this anywhere). Use the second drop-down menu to select ``detected``. + +![Sensor detect method dropdown selections](/static/tutorials/intruder-alert/detect-method-dropdown.png) + +```blocks +sensors.infrared1.onEvent(InfraredSensorEvent.ObjectDetected, function () { + +}) +``` + +## Step 2 + +Open the ``||brick:Brick||`` Toolbox drawer. From the **Screen** section, drag out a ``||brick:show image||`` block onto the Workspace, and drop it into the ``||sensors:on infrared||`` block. + +```blocks +sensors.infrared1.onEvent(InfraredSensorEvent.ObjectDetected, function () { + brick.showImage(images.expressionsBigSmile) +}) +``` + +## Step 3 + +In the ``||brick:show image||`` block, use the drop-down menu to select the **STOP** sign image. + +![Screen image selections](/static/tutorials/intruder-alert/show-image-dropdown.png) + +```blocks +sensors.infrared1.onEvent(InfraredSensorEvent.ObjectDetected, function () { + brick.showImage(images.informationStop1) +}) +``` + +## Step 4 + +Open the ``||brick:Brick||`` Toolbox drawer. From the **Buttons** section, drag out a ``||brick:set status light||`` block onto the Workspace, and drop it after the ``||brick:show image||`` block. + +```blocks +sensors.infrared1.onEvent(InfraredSensorEvent.ObjectDetected, function () { + brick.showImage(images.informationStop1) + brick.setStatusLight(StatusLight.Orange) +}) +``` + +## Step 5 + +In the ``||brick:set status light||`` block, use the drop-down menu to select the ``red flash`` light + +![Status light selection dropdown list](/static/tutorials/intruder-alert/set-status-light-dropdown.png) + +```blocks +sensors.infrared1.onEvent(InfraredSensorEvent.ObjectDetected, function () { + brick.showImage(images.informationStop1) + brick.setStatusLight(StatusLight.RedFlash) +}) +``` + +## Step 6 + +Open the ``||loops:Loops||`` Toolbox drawer. Drag a ``||loops:repeat||`` loop onto the Workspace, and drop it after the ``||brick:set status light||`` block. + +```blocks +sensors.infrared1.onEvent(InfraredSensorEvent.ObjectDetected, function () { + brick.showImage(images.informationStop1) + brick.setStatusLight(StatusLight.RedFlash) + for (let i = 0; i < 4; i++) { + + } +}) +``` + +## Step 7 + +Open the ``||music:Music||`` Toolbox drawer. Drag a ``||music:play sound effect until done||`` block onto the Workspace, and drop it into the ``||loops:repeat||`` loop. + +```blocks +sensors.infrared1.onEvent(InfraredSensorEvent.ObjectDetected, function () { + brick.showImage(images.informationStop1) + brick.setStatusLight(StatusLight.RedFlash) + for (let i = 0; i < 4; i++) { + music.playSoundEffectUntilDone(sounds.animalsCatPurr) + } +}) +``` + +## Step 8 + +In the ``||music:play sound effect until done||`` block, use the drop-down menu to select ``information error alarm`` sound effect. + +![Sound effect dropdown selections](/static/tutorials/intruder-alert/play-sound-effect-dropdown.png) + +## Step 9 + +Now, plug your @boardname@ into the computer with the USB cable, and click the **Download** button at the bottom of your screen. Follow the directions to save your program to the brick. + +Attach an Infrared Sensor to Port 1 of your brick. Test your program by putting an object increasingly closer to the Infrared Sensor – your Intruder Alert should trigger when you get too close!