pxt-calliope/docs/getting-started.md

170 lines
3.8 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? For each challenge, reorder the blocks to recreate the program.
### Show leds
Use the blocks below to draw a figure on the screen. You can redo the smiley face or try something else!
```shuffle
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .
`)
```
2016-05-12 22:56:03 +02:00
To transfer your code to the BBC micro:bit,
* connect your micro:bit to the computer using the USB cable
2016-06-01 16:42:03 +02:00
* click on **Compile**
2016-05-12 22:56:03 +02:00
* drag&drop the **.hex** file into the **MICROBIT** drive
* wait till the yellow light is done blinking!
2016-05-12 22:41:15 +02:00
2016-05-12 22:50:27 +02:00
### Show animation Forever
2016-05-17 18:35:55 +02:00
Show one image after the other to create an animation by snapping them together.
2016-05-12 22:50:27 +02:00
2016-05-17 18:35:55 +02:00
```blocks
2016-05-12 22:50:27 +02:00
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #
`)
```
2016-06-01 16:42:03 +02:00
To transfer your code to the BBC micro:bit,
* connect your micro:bit to the computer using the USB cable
* click on **Compile**
* drag&drop the **.hex** file into the **MICROBIT** drive
* wait till the yellow light is done blinking!
2016-05-17 18:35:55 +02:00
2016-05-12 22:50:27 +02:00
### Repeat forever
Use the ``forever`` block to repeat your code and have a continuous animation.
2016-05-12 22:41:15 +02:00
Unsuffle the blocks to create a happy, unhappy animation.... or changes the image to make it your own!
```shuffle
basic.forever(() => {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #
`)
});
```
### Your turn now!
2016-05-12 22:56:03 +02:00
Use the blocks ``show leds`` and ``forever``
to create your own custom awesome animation!
2016-05-12 22:41:15 +02:00
### Button A and B
Unshuffle the blocks so that the micro:bit shows "YES" when button A is pressed, and "NO" when B is pressed.
The key idea is that all the blocks nested under `on button ... pressed` will run when that button is pressed.
```blocks
input.onButtonPressed(Button.A, () => {
basic.showString("AAAAA");
});
```
Try to unshuffle those blocks:
```shuffle
input.onButtonPressed(Button.A, () => {
basic.showString("YES");
});
input.onButtonPressed(Button.B, () => {
basic.showString("NO");
});
```
### Shake
Using the data from the **accelerometer**, it is possible to detect that the BBC micro:bit is being shaken.
Unshuffle the code to display a frownie when shaken.
```shuffle
input.onGesture(Gesture.Shake, () => {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #`);
});
```
### Tilting
Aside from shake, it is also possible to detect tilt left and right, logo up and down or face up and down.
Let's build a rock paper scissors game where you turn the micro:bit left to display paper, right to display scissors and down to display rock.
Unshuffle and try this code on the micro:bit itself!
```shuffle
input.onGesture(Gesture.TiltLeft, () => {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #`);
});
input.onGesture(Gesture.LogoDown, () => {
basic.showLeds(`
. . . . .
. # # # .
. # # # .
. # # # .
. . . . .`);
});
input.onGesture(Gesture.TiltRight, () => {
basic.showLeds(`
# # . . #
# # . # .
. . # . .
# # . # .
# # . . #`);
});
```
### Pins
It is possible to use the pins (big metal bar at the bottom of the board) as button. Hold the ``GND`` button with one hand and press the ``0`` pin
(called ``P0``) with the other hand to trigger a pin pressed.
Unshuffle the blocks to display a smiley when pin ``P0`` is pressed.
```shuffle
input.onPinPressed(TouchPin.P0, () => {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .`);
});
```
### Your turn now!
2016-05-27 16:06:24 +02:00
Use the screen, buttons, gestures, pins to create a fun game using the micro:bit.