Merge remote-tracking branch 'origin/master' into setpull

This commit is contained in:
Peli de Halleux 2016-06-03 22:23:35 -07:00
commit e2ce49d94b
5 changed files with 252 additions and 89 deletions

View File

@ -1,10 +1,16 @@
# Getting started
## ~avatar
Are you ready to build cool BBC micro:bit programs?
Here are some challenges for you. Unscramble the blocks in the editor
to make real programs that work!
[OPEN EDITOR](/#follow:getting-started)
## ~
### Happy face
There are three blocks in the editor (the area to the left).
@ -33,11 +39,7 @@ When you run this program, you will see a smiley face, then a blank
screen, then a smiley again -- it never stops! (That's because of the
``forever`` block.)
To move your program from your computer to the BBC micro:bit:
* Connect your micro:bit to the computer with the USB cable.
* Click **Compile**.
* Drag and drop the new file whose name ends in **.hex** into the **MICROBIT** window.
* Wait until the yellow light stops blinking!
Click **Compile** to move your program to the BBC micro:bit!
### Happy unhappy face
@ -65,12 +67,7 @@ basic.forever(() => {
`)
});
```
To move your program from your computer to the BBC micro:bit:
* Connect your micro:bit to the computer with the USB cable.
* Click **Compile**.
* Drag and drop the new file whose name ends in **.hex** into the **MICROBIT** window.
* Wait until the yellow light stops blinking!
Click **Compile** to move your program to the BBC micro:bit!
### Your turn!
@ -123,12 +120,7 @@ basic.forever(() => {
`)
});
```
To move your program from your computer to the BBC micro:bit:
* Connect your micro:bit to the computer with the USB cable.
* Click **Compile**.
* Drag and drop the new file whose name ends in **.hex** into the **MICROBIT** window.
* Wait until the yellow light stops blinking!
Click **Compile** to move your program to the BBC micro:bit!
#### ~hint
@ -138,12 +130,12 @@ You can find the ``show leds`` block in the **Basic** part of the editor.
### Button A and button B
This program will show the word **anteater** on the LED
This program will show the word **ANTEATER** on the LED
screen when you press button `A`.
```blocks
input.onButtonPressed(Button.A, () => {
basic.showString("anteater");
basic.showString("ANTEATER");
});
```
@ -155,11 +147,11 @@ on the micro:bit screen.
#### ~
Now try to unscramble these blocks in the editor so that the micro:bit
shows **banana** when you press button `B`.
shows **BANANA** when you press button `B`.
```shuffle
input.onButtonPressed(Button.B, () => {
basic.showString("banana");
basic.showString("BANANA");
});
```
#### ~hint
@ -169,11 +161,13 @@ You can find the letter `B` by clicking the letter `A` on the
#### ~
Click **Compile** to move your program to the BBC micro:bit!
#### Your turn!
Can you combine these blocks so your program shows your real name
instead of **anteater** when you press `A`, but _your secret agent
name_ instead of **banana** when you press `B`?
instead of **ANTEATER** when you press `A`, but _your secret agent
name_ instead of **BANANA** when you press `B`?
### Shake
@ -194,46 +188,7 @@ input.onGesture(Gesture.Shake, () => {
# . . . #`);
});
```
### Tilting with gestures
You can also find when someone is tilting the micro:bit left or right,
face up or face down, and logo up or logo down (the logo is the yellow
oval picture at the top of the board). Tilting a micro:bit like this
is called a **gesture**.
Try to build a Rock Paper Scissors game where you tilt the micro:bit
left to show paper, right to show scissors, and down to show rock.
Unscramble these blocks in the editor and try this program on a real
micro:bit!
```shuffle
input.onGesture(Gesture.TiltLeft, () => {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #`);
});
input.onGesture(Gesture.LogoDown, () => {
basic.showLeds(`
. . . . .
. # # # .
. # # # .
. # # # .
. . . . .`);
});
input.onGesture(Gesture.TiltRight, () => {
basic.showLeds(`
# # . . #
# # . # .
. . # . .
# # . # .
# # . . #`);
});
```
Click **Compile** to move your program to the BBC micro:bit!
### Pins
@ -242,32 +197,231 @@ metal stripe at the bottom of the micro:bit board.) For example, hold
the ``GND`` button with one hand and touch the ``0`` pin (called
``P0``) with your other hand to tell the micro:bit you're pressing it.
Unscramble the blocks in the editor to show a smiley when you press
Unscramble the blocks in the editor to show a heart when you press
pin ``P0``.
```shuffle
input.onPinPressed(TouchPin.P0, () => {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# . # . #
# . . . #
. # # # .`);
. # . # .
. . # . .`);
});
```
Click **Compile** to move your program to the BBC micro:bit!
### Your turn!
## ~hint
Use the screen, buttons, gestures, and pins to make your own fun game
with the BBC micro:bit! What about some of these?
Try this experiment: find a friend and hold hands together. Press the ``GND`` button
while your friend pressed the ``P0`` button. You should see the heart! The electric current is going through your bodies and accross your handshake
to make it happen!
* A backpack burglar alarm
* Daily news broadcaster for your class
* Animated jewelry
* A _complete_ animated cartoon
* A calculator
* A music box
## ~
These are all things you can make with the BBC micro:bit by itself.
Just think what you can do if you connect the micro:bit's pins to
extra parts like microphones and other **sensors**!
## Let's play Rock Paper Scissors!
### ~avatar avatar
Build a Rock Paper Scissors game with the BBC micro:bit!
You can play the game with a friend who has it on a micro:bit.
You can also play it with friends who are just using their hands.
### ~
## Step 1: Getting started
We want the micro:bit to choose rock, paper, or scissors when you
shake it. Try creating an ``on shake`` block so when you shake the
micro:bit, it will run part of a program.
Clear up the blocks and add the blocks below.
```blocks
input.onGesture(Gesture.Shake, () => {
})
```
Next, when you shake the micro:bit, it should pick a random number from `0` to `2`
and store it in the variable `item`.
Add a ``set`` block with a variable. Then add a ``pick random`` block,
and store the random number in the variable,
like this:
```blocks
input.onGesture(Gesture.Shake, () => {
let item = Math.random(3)
})
```
### ~hint
No one can predict random numbers. That's what makes them great for Rock Paper Scissors!
### ~
Each possible number these blocks can make (`0`, `1`, or `2`) means a different picture.
We will show the right picture for that number on the LED screen.
## Step 2: Picking paper
Put an ``if`` block after the ``let`` block that checks whether
`item` is `0`. Make sure the ``if`` block has an ``else if`` part
and an ``else`` part.
Next, add a ``show leds`` block that shows a
picture of a piece of paper:
```blocks
input.onGesture(Gesture.Shake, () => {
let item = Math.random(3)
if (item == 0) {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #
`)
} else if (false) {
} else {
}
})
```
## Step 3: A random rock
Now we are going to add a new picture for the micro:bit to show
when another random number comes up.
Make the ``else if`` part check if the variable `item` is `1`.
Then add a ``show leds`` block with a picture of a rock.
```blocks
input.onGesture(Gesture.Shake, () => {
let item = Math.random(3)
if (item == 0) {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #
`)
} else if (item == 1) {
basic.showLeds(`
. . . . .
. # # # .
. # # # .
. # # # .
. . . . .
`)
} else {
}
})
```
## Step 4: Suddenly scissors
Add a ``show leds`` block with a picture of scissors to the ``else`` part:
```blocks
input.onGesture(Gesture.Shake, () => {
let item = Math.random(3)
if (item == 0) {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #
`)
} else if (item == 1) {
basic.showLeds(`
. . . . .
. # # # .
. # # # .
. # # # .
. . . . .
`)
} else {
basic.showLeds(`
# # . . #
# # . # .
. . # . .
# # . # .
# # . . #
`)
}
})
```
### ~hint
You don't need to check if `item` is `2` because `2` is the only number left out of `0`, `1`, and `2`.
That's why you can use an ``else`` instead of an ``else if``.
### ~
Your game is ready!
Click **Compile** to move your program to the BBC micro:bit!
Have fun!
## Step 5: Are you the greatest?
Here is a way you can make your Rock Paper Scissors game better.
When button ``A`` is pressed,
the micro:bit will add `1` to your score.
Open the ``Game`` drawer, and then add the block ``change score by 1`` to your program,
like this:
```blocks
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
```
## Step 6: Prove you're the greatest!
After your micro:bit can add `1` to the score, show how many wins you have.
```blocks
input.onButtonPressed(Button.A, () => {
game.addScore(1)
basic.showString("WINS:")
basic.showNumber(game.score())
})
```
## Step 7: Staying honest
Success! Your micro:bit can track wins!
But what about losses?
Use the ``Game`` drawer to subtract `1` from your score when you press button `B`.
Here are all the blocks you will need:
```shuffle
input.onButtonPressed(Button.B, () => {
game.addScore(-1)
basic.showString("LOSSES:")
basic.showNumber(game.score())
})
```
Click **Compile** to move your program to the BBC micro:bit!
## Your turn!
How else can you make your game better?
Ever hear of [Rock Paper Scissors Spock Lizard](http://www.samkass.com/theories/RPSSL.html)?

View File

@ -71,4 +71,4 @@
### @section full
The lessons promote computational thinking and computer science literacy[ read more...](/lessons/teach)
The lessons promote computational thinking and computer science literacy.

View File

@ -1,10 +1,11 @@
# Ring Tone
Play a continuous tone through pin P0.
Play a musical tone through pin `P0` with the pitch as high or low as you say.
The tone will keep playing until you tell it not to.
## Simulator
Simulation of this function is available in many, but not all browsers.
This function only works on the micro:bit and in some browsers.
```sig
music.ringTone(440)
@ -12,11 +13,18 @@ music.ringTone(440)
### Parameters
* `frequency` : [Number](/reference/types/number) - Plays a tone in (Hz)
* a [number](/reference/types/number) that says the tone's
**frequency** (how high-pitched or low-pitched the tone is). This
number is in **Hz** (**Hertz**), which is a measurement of frequency
or pitch.
### Example
Play a sound based on the tile of the device
This program checks the **accelerometer** for the micro:bit's
**acceleration** (how much the micro:bit is speeding up or slowing
down). Then it uses that acceleration to make a tone. If the micro:bit
speeds up, the tone's pitch gets higher, and if it slows down, the
tone's pitch gets lower. It's fun -- try it!
```blocks
basic.forever(() => {
@ -26,5 +34,6 @@ basic.forever(() => {
### See also
[rest](/reference/music/rest), [play tone](/reference/music/play-tone) , [tempo](/reference/music/tempo), [set tempo](/reference/music/set-tempo), [change tempo by](/reference/music/change-tempo-by)
[rest](/reference/music/rest), [play tone](/reference/music/play-tone),
[tempo](/reference/music/tempo), [set tempo](/reference/music/set-tempo),
[change tempo by](/reference/music/change-tempo-by)

View File

@ -1,6 +1,6 @@
{
"name": "pxt-microbit",
"version": "0.2.144",
"version": "0.2.147",
"description": "BBC micro:bit target for PXT",
"keywords": [
"JavaScript",
@ -29,6 +29,6 @@
"typescript": "^1.8.7"
},
"dependencies": {
"pxt-core": "0.2.156"
"pxt-core": "0.2.161"
}
}

View File

@ -68,7 +68,7 @@
"yottaTarget": "bbc-microbit-classic-gcc",
"yottaCorePackage": "pxt-microbit-core",
"githubCorePackage": "microsoft/pxt-microbit-core",
"gittag": "v0.1.10",
"gittag": "v0.1.11",
"serviceId": "ws"
},
"serial": {