pxt-calliope/docs/getting-started.md

264 lines
5.9 KiB
Markdown
Raw Normal View History

2016-05-12 22:56:03 +02:00
# Getting started
2016-05-12 22:41:15 +02:00
Are you ready to build cool BBC micro:bit programs?
2016-05-12 22:41:15 +02:00
Here are some challenges for you. Unscramble the blocks in the editor
to make real programs that work!
2016-05-12 22:41:15 +02:00
2016-06-02 21:32:13 +02:00
### Happy face
2016-06-02 20:38:14 +02:00
2016-06-03 00:25:19 +02:00
There are three blocks in the editor (the area to the left).
They should look like this:
2016-06-02 20:38:14 +02:00
2016-06-02 21:32:13 +02:00
```blocks
2016-06-02 20:38:14 +02:00
basic.forever(() => {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
});
```
2016-06-03 00:25:19 +02:00
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!
2016-05-12 22:41:15 +02:00
2016-06-02 21:32:13 +02:00
### Happy unhappy face
2016-05-12 22:50:27 +02:00
2016-06-03 00:25:19 +02:00
Draw an unhappy face instead of the blank screen. Click on the dots
in the second ``show leds`` block until it matches the blocks below.
Now you have an **animation** (cartoon) that shows a happy face,
then an unhappy one, then a happy one again, forever (or until
you turn off your micro:bit)!
2016-05-12 22:50:27 +02:00
2016-05-17 18:35:55 +02:00
```blocks
2016-06-02 21:32:13 +02:00
basic.forever(() => {
2016-05-12 22:50:27 +02:00
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #
`)
2016-06-02 21:32:13 +02:00
});
2016-05-12 22:50:27 +02:00
```
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!
2016-06-02 21:32:13 +02:00
### Your turn!
2016-05-12 22:50:27 +02:00
2016-06-03 00:25:19 +02:00
Pile up more ``show leds`` blocks to create your animation! Create an
animation with at least 5 pictures. What does this animation show?
2016-05-12 22:41:15 +02:00
2016-06-02 21:32:13 +02:00
```blocks
2016-05-12 22:41:15 +02:00
basic.forever(() => {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .
`)
2016-06-03 00:25:19 +02:00
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# # # # #
. . . . .
`)
2016-05-12 22:41:15 +02:00
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #
`)
2016-06-02 21:32:13 +02:00
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# # # # #
2016-06-03 00:25:19 +02:00
. . . # #
`)
basic.showLeds(`
. . . . .
# . # . .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. . . . .
. . # . #
2016-06-02 21:32:13 +02:00
. . . . .
2016-06-03 00:25:19 +02:00
# . . . #
. # # # .
2016-06-02 21:32:13 +02:00
`)
2016-05-12 22:41:15 +02:00
});
```
2016-06-02 21:32:13 +02:00
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!
#### ~hint
2016-06-03 00:25:19 +02:00
You can find the ``show leds`` block in the **Basic** part of the editor.
#### ~
2016-05-12 22:41:15 +02:00
2016-06-03 00:25:19 +02:00
### Button A and button B
2016-05-12 22:41:15 +02:00
2016-06-03 00:25:19 +02:00
This program will show the word **anteater** on the LED
2016-06-02 21:32:13 +02:00
screen when you press button `A`.
2016-05-12 22:41:15 +02:00
```blocks
2016-06-02 21:32:13 +02:00
input.onButtonPressed(Button.A, () => {
2016-06-03 00:25:19 +02:00
basic.showString("anteater");
2016-05-12 22:41:15 +02:00
});
```
Now try to unscramble these blocks in the editor so that the micro:bit
2016-06-03 00:25:19 +02:00
shows **banana** when you press button `B`.
2016-05-12 22:41:15 +02:00
```shuffle
input.onButtonPressed(Button.B, () => {
2016-06-03 00:25:19 +02:00
basic.showString("banana");
2016-05-12 22:41:15 +02:00
});
```
2016-06-03 00:25:19 +02:00
#### ~hint
You can find the letter `B` by clicking the letter `A` on the
``onButtonPressed`` block.
####
Can you combine these blocks so your program shows **anteater** when
you press `A`, but **banana** when you press `B`?
2016-05-12 22:41:15 +02:00
### Shake
You can find when someone is shaking the BBC micro:bit by checking its
**accelerometer** (it finds whether the micro:bit is speeding up or
slowing down).
Unscramble these blocks in the editor to show a frownie when someone
2016-06-03 00:25:19 +02:00
shakes the micro:bit. (Ouch!)
2016-05-12 22:41:15 +02:00
```shuffle
input.onGesture(Gesture.Shake, () => {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #`);
});
```
### 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
2016-06-03 00:25:19 +02:00
oval picture at the top of the board). Tilting a micro:bit like this
is called a **gesture**.
2016-05-12 22:41:15 +02:00
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.
2016-06-03 00:25:19 +02:00
Unscramble these blocks in the editor and try this program on a real
micro:bit!
2016-05-12 22:41:15 +02:00
```shuffle
input.onGesture(Gesture.TiltLeft, () => {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #`);
});
input.onGesture(Gesture.LogoDown, () => {
basic.showLeds(`
. . . . .
. # # # .
. # # # .
. # # # .
. . . . .`);
});
input.onGesture(Gesture.TiltRight, () => {
basic.showLeds(`
# # . . #
# # . # .
. . # . .
# # . # .
# # . . #`);
});
```
### Pins
You can also use the pins as buttons. (The pins are the holes in the
2016-06-03 00:25:19 +02:00
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
pin ``P0``.
2016-05-12 22:41:15 +02:00
```shuffle
input.onPinPressed(TouchPin.P0, () => {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .`);
});
```
### Your turn!
2016-05-12 22:41:15 +02:00
Use the screen, buttons, gestures, and pins to make your own fun game
2016-06-03 00:25:19 +02:00
with the BBC micro:bit! What about some of these?
* 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**!