Add 'Touch to Run` tutorial (#420)

* Add 'Touch to Run` tutorial

* Edits and thumbnail image
This commit is contained in:
Galen Nickel 2018-04-03 21:33:53 -07:00 committed by GitHub
parent c97098b99e
commit ac9ebf6776
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 71 additions and 0 deletions

BIN
docs/static/tutorials/touch-to-run.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

View File

@ -36,5 +36,11 @@ Step by step guide to coding your @boardname@.
"cardType": "tutorial",
"url":"/tutorials/run-motors",
"imageUrl":"/static/tutorials/run-motors.png"
}, {
"name": "Touch to Run",
"description": "Press the Touch sensor and run a motor.",
"cardType": "tutorial",
"url":"/tutorials/touch-to-run",
"imageUrl":"/static/tutorials/touch-to-run.png"
}]
```

View File

@ -0,0 +1,65 @@
# Touch to Run
## Introduction @fullscreen
Use the Touch sensor to run a motor.
![Large motor connected to brick](/static/tutorials/touch-to-run/touch-to-run.gif)
## Step 1
Open the ``||sensors:Sensors||`` Toolbox drawer. Drag out **2** ``||sensors:on touch||`` blocks onto the Workspace (you can place these anywhere).
```block
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
})
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
})
```
## Step 2
In one of the ``||sensors:on touch||`` blocks, use the second drop-down menu to change from ``pressed`` to ``released``.
![Touch sensor action dropdown](/static/tutorials/touch-to-run/on-touch-dropdown.png)
```block
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
})
sensors.touch1.onEvent(ButtonEvent.Released, function () {
})
```
## Step 3
Open the ``||motors:Motors||`` Toolbox drawer. Drag out a ``||motors:run||`` block onto the Workspace, and drop it into the ``||brick:on touch pressed||`` block.
```block
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
motors.largeA.run(50)
})
sensors.touch1.onEvent(ButtonEvent.Released, function () {
})
```
## Step 4
Open the ``||motors:Motors||`` Toolbox drawer. Drag out a ``||motors:stop||`` block onto the Workspace, and drop it into the ``||sensors:on touch released||`` block.
```block
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
motors.largeA.run(50)
})
sensors.touch1.onEvent(ButtonEvent.Released, function () {
motors.largeA.stop()
})
```
## Step 5
Now, lets 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 and releasing the touch sensor does the motor start and stop as expected?