A few edits for 'telegraph' project (#593)

This commit is contained in:
Galen Nickel 2017-12-05 18:34:02 -08:00 committed by GitHub
parent 9a8a811945
commit c258a5553d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 38 deletions

View File

@ -12,8 +12,8 @@ Build a telegraph between two @boardname@s to communicate with your friends!
## Materials
* @boardname@, battery holder and 2 AAA batteries
* Crocodile clips
* 2 @boardname@s, a battery holder, and 2 AAA batteries
* 4 crocodile clips
## Activities

View File

@ -1,12 +1,12 @@
# Code
Let's build the code that, when the user presses the button ``A`` on a @boardname@, will send an impulse over a wire to the receiving @boardname@ and turn an LED on there.
Let's build the code that, when the user presses the button **A** on a @boardname@, will send an impulse over a wire to the receiving @boardname@ and turn on an LED there.
Make sure that the sending and receiving wires run symmetrically across: pin ``P1`` on one @boardname@ is connected to pin ``P2`` on the other, and vice versa, as shown on the pictures in the "Make" section. This way we can use the same code on both @boardname@s .
Make sure that the sending and receiving wires run "symmetrically" between the two boards. That is: pin **1** on one @boardname@ is connected to pin **2** on the other, and vice versa. Just like it's shown in the pictures in the **[make](./make)** section. This way we can use the same code on both @boardname@s .
## Step 1
We start with a block that digitally writes **high** (value ``1``) to the sending @boardname@'s pin ``P1``. This block can be found in _Pins_ drawer of the Advanced section.
We start with a block that digitally writes **high** value (a digital ``1``) to ``P1`` which sends the value to @boardname@'s pin **1**. This block is found in **Pins** drawer of the Advanced section of the Toolbox.
```blocks
pins.digitalWritePin(DigitalPin.P1, 1)
@ -14,7 +14,7 @@ pins.digitalWritePin(DigitalPin.P1, 1)
## Step 2
To show what we are sending, we add a block to turn on an LED in the centre of the LED display (2,2) using _plot x, y_ :
To show that we are sending the ``1``, we add a block to turn on an LED in the center of the LED display (2, 2) using ``||led:plot x y||``:
```blocks
pins.digitalWritePin(DigitalPin.P1, 1)
@ -23,8 +23,8 @@ led.plot(2, 2)
## Step 3
Now that we know how to send the signal, we only want to be doing it while the button ``A`` is pressed.
Pick an _if_ block from the _Logic_ drawer (you'll need the version with _else_ part that will remain empty for now). Add a check whether the button ``A`` is pressed from the _Input_ drawer and move the blocks from the previous step into _then_ part :
Now that we know how to send the signal, we only want to do it while the button **A** is pressed.
Pick an ``||logic:if then else||`` block from the **Logic** drawer (you'll leave the ``||logic:else||`` part empty for now). Add a check for when button **A** is pressed. Get an ``||inpu:on button pressed||`` from the **Input** drawer and move the blocks from the previous step into ``||logic:then||`` part of the ``||logic:if then else||``:
```blocks
if (input.buttonIsPressed(Button.A)) {
@ -36,7 +36,7 @@ if (input.buttonIsPressed(Button.A)) {
## Step 4
For the _else_ branch (while the button A is not pressed) we want to do the opposite of what we did in the _then_ branch: take the value of pin ``P1`` to **low** (0) and unplot the corresponding LED on the sending @boardname@ :
For the ``||logic:else||`` section (while button **A** is not pressed) we want to do the opposite of what we did in the ``|logic:then||`` section. Which is, make the value of pin ``P1`` go to **low** (digital 0) and unplot the corresponding LED on the sending @boardname@:
```blocks
if (input.buttonIsPressed(Button.A)) {
@ -50,8 +50,8 @@ if (input.buttonIsPressed(Button.A)) {
## Step 5
Let's wrap it all in a forever loop so this code runs in the background, forever checking the button ``A`` and sending the appropriate signal to the receiver.
Modify your code so that your code looks like this. Download the code into one of the @boardname@s, press and release button ``A`` a few times.
Let's wrap it all in a forever loop so this code is running in the background always checking button **A** and sending the appropriate signal to the receiver.
Modify your code to add the blocks below. Download the code onto one of the @boardname@s, press and release button **A** a few times.
```blocks
basic.forever(() => {
@ -65,14 +65,17 @@ basic.forever(() => {
})
```
The sending part is done, so we are going to add the receiving part.
The sending part is done, so now we'll add the receiving part.
## Step 6
The receiver needs to digitally read from the pin to which the sending @boardname@ will be writing (``P2``) over the wire. Let's start by going to the _Pin_ drawer, adding digital read pin ``P0`` and changing the pin value to ``P2``.
Now we want to examine the value read from ``P2`` and check whether it is **high** (value ``1``) or not. Go to the _Logic_ drawer, first pick an _if_ block, then come back for a comparison operator (=). Plug in our digital read block as one operand and the value ``1`` as the other.
We shall turn the LED in the bottom right corner (4,4) on to indicate that we received **high** and turn it off otherwise.
Your code should look as follows:
The receiver needs to digitally read from the pin where the other @boardname@ sends its value to pin **2** across the wire. Let's start by going to the **Pins** drawer, adding a ``||pins:digital read pin||`` and change the pin value to ``P2``.
Now, we want to examine the value read from ``P2`` and check whether it's **high** (``1``) or **low** (``0``). Go to the **Logic** drawer and pick an ``||logic:if then else||`` block, then come back for the comparison operator ``||logic:0 = 0||``. Plug in our ``||pins:digital read pin||`` block as one operand and the value ``1`` as the other.
We'll turn the LED in the bottom right corner (4, 4) on to show that we received a **high** value and turn it off in not.
Make sure your code looks like this:
```blocks
basic.forever(() => {
@ -95,6 +98,11 @@ Your telegraph is ready!
## Step 7
* Connect the first @boardname@ to your computer using your USB cable and download the telegraph script to it.
* Connect the second @boardname@ to your computer using your USB cable and download the telegraph script to it.
* The first person and second person can take turns pressing button A on their @boardname@s to play the telegraph game!
Ok, let's try it out:
1. Connect the first @boardname@ to your computer using your USB cable and download the telegraph code to it.
2. Disconnect the first @boardname@.
3. Connect the second @boardname@ to your computer using your USB cable and download the telegraph code to it.
4. Disconnect the second @boardname@.
5. Connect the battery holder to one of the @boardname@s.
6. The first person, and then second person, can take turns pressing button **A** on their own @boardname@s to play the telegraph game!

View File

@ -10,60 +10,60 @@ Let's build a telegraph between two @boardname@s.
## Materials
* @boardname@, battery holder and 2 AAA batteries
* Crocodile clips
* 2 @boardname@s, a battery holder, and 2 AAA batteries
* 4 crocodile clips
## Steps
## Step 1
### Step 1
![](/static/mb/lessons/banana-keyboard-1.png)
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the @boardname@.
Connect the end of the **1st** crocodile clip to the **GND** pin on the @boardname@.
## Step 2
### Step 2
![](/static/mb/lessons/ornament-chain-2.png)
Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 3V pin on the @boardname@.
Connect the end of the **2nd** crocodile clip to the **3V** pin on the @boardname@.
## Step 3
### Step 3
![](/static/mb/lessons/ornament-chain-3.png)
Using the 3rd crocodile clip, connect the end of the crocodile clip onto pin 1 of the @boardname@.
Connect the end of the **3rd** crocodile clip to pin **1** of the @boardname@.
## Step 4
### Step 4
![](/static/mb/lessons/ornament-chain-4.png)
Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 2 of the @boardname@.
Connect the end of the **4th** crocodile clip to pin **2** of the @boardname@.
## Step 5
### Step 5
![](/static/mb/lessons/ornament-chain-5.png)
Using the 1st crocodile clip, connect the unattached end of the crocodile clip onto the GND on the 2nd @boardname@.
Connect the other end of the **1st** crocodile clip to the **GND** on the second @boardname@.
## Step 6
### Step 6
![](/static/mb/lessons/ornament-chain-6.png)
Using the 2nd crocodile clip, connect the unattached end of the crocodile clip onto the 3V pin on the 2nd @boardname@.
Connect the other end of the **2nd** crocodile clip to the **3V** pin on the second @boardname@.
## Step 7
### Step 7
![](/static/mb/lessons/ornament-chain-7.png)
Using the 3rd crocodile clip, connect the unattached end of the crocodile clip onto pin 2 of the 2nd @boardname@.
Connect the other end of the **3rd** crocodile clip to pin **2** of the second @boardname@.
## Step 8
### Step 8
![](/static/mb/lessons/ornament-chain-8.png)
Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto pin 1 of the 2nd @boardname@
Connect the other end of the **4th** crocodile clip to pin **1** of the second @boardname@.
## Step 9
### Step 9
![](/static/mb/lessons/telegraph-0.png)