diff --git a/docs/static/tutorials/touch-sensor-values.png b/docs/static/tutorials/touch-sensor-values.png new file mode 100644 index 00000000..21b3fbc8 Binary files /dev/null and b/docs/static/tutorials/touch-sensor-values.png differ diff --git a/docs/static/tutorials/touch-sensor-values/touch-to-stop.gif b/docs/static/tutorials/touch-sensor-values/touch-to-stop.gif new file mode 100644 index 00000000..24af826e Binary files /dev/null and b/docs/static/tutorials/touch-sensor-values/touch-to-stop.gif differ diff --git a/docs/tutorials.md b/docs/tutorials.md index 6e87bd6c..715dab9f 100644 --- a/docs/tutorials.md +++ b/docs/tutorials.md @@ -42,5 +42,11 @@ Step by step guide to coding your @boardname@. "cardType": "tutorial", "url":"/tutorials/touch-to-run", "imageUrl":"/static/tutorials/touch-to-run.png" +}, { + "name": "Using Touch Sensor Values", + "description": "Check the value of a Touch sensor and stop a motor if pressed.", + "cardType": "tutorial", + "url":"/tutorials/touch-sensor-values", + "imageUrl":"/static/tutorials/touch-sensor-values.png" }] ``` \ No newline at end of file diff --git a/docs/tutorials/touch-sensor-values.md b/docs/tutorials/touch-sensor-values.md new file mode 100644 index 00000000..c7f3eee3 --- /dev/null +++ b/docs/tutorials/touch-sensor-values.md @@ -0,0 +1,92 @@ +# Using Touch Sensor Values + +## Introduction @fullscreen + +Use the Touch sensor value to stop a running motor. + +![Touch sensor and motor attached to brick](/static/tutorials/touch-sensor-values/touch-to-stop.gif) + +## Step 1 + +Open the ``||brick:Brick||`` Toolbox drawer. Drag an ``||brick:on button||`` block onto the Workspace, and place it anywhere on the Workspace. + +```block +brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () { + +}) +``` + +## Step 2 + +Open the ``||motors:Motors||`` Toolbox drawer. Drag out a ``||motors:run||`` block onto the Workspace, and drop it into the ``||brick:on button||`` block. + +```block +brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () { + motors.largeA.run(50) +}) +``` + +## Step 3 + +Open the ``||logic:Logic||`` Toolbox drawer. Drag out an ``||logic:if then||`` block onto the Workspace, and drop it into the ``||loops:forever||`` block. + +```block +forever(function () { + if (true) { + + } +}) +``` + +## Step 4 + +Open the ``||sensors:Sensors||`` Toolbox drawer. Drag out a ``||sensors:touch is pressed||`` block onto the Workspace, and drop it in the ``||logic:if then||`` block replacing ``true``. + +```block +forever(function () { + if (sensors.touch1.isPressed()) { + + } +}) +``` + +## Step 5 + +Open the ``||music:Music||`` Toolbox drawer. Drag out a ``||music:play sound effect||`` block onto the Workspace, and drop it under the ``||logic:if then||`` block. + +```block +forever(function () { + if (sensors.touch1.isPressed()) { + music.playSoundEffect(sounds.animalsCatPurr) + } +}) +``` + +## Step 6 + +In the ``||music:play sound effect||`` block, use the drop-down menu to select the ``information touch`` sound effect. + +```block +forever(function () { + if (sensors.touch1.isPressed()) { + music.playSoundEffect(sounds.informationTouch) + } +}) +``` + +## Step 7 + +Open the ``||motors:Motors||`` Toolbox drawer. Drag out a ``||motors:stop||`` block onto the Workspace, and drop it in after the ``||music:play sound effect||`` block. + +```block +forever(function () { + if (sensors.touch1.isPressed()) { + music.playSoundEffect(sounds.informationTouch) + motors.largeA.stop() + } +}) +``` + +## Step 8 + +Now, let’s download our program to the brick. Plug your EV3 brick into the computer with the USB cable, and click the blue **Download** button in the bottom left of your screen. Follow the directions to save your program to the brick. Attach a Large motor to Port A, and a Touch sensor to Port 1 on your brick. Test your program by pressing the ENTER button. When the motor starts, press the touch sensor. Does the motor stop as expected?