Compare commits

...

57 Commits

Author SHA1 Message Date
3b2729d9d8 0.2.136 2016-06-01 07:42:41 -07:00
571ae8337f Bump pxt-core to 0.2.147 2016-06-01 07:42:39 -07:00
cc2d18b969 Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-06-01 07:42:37 -07:00
fd02bd9407 updated docs menu 2016-06-01 07:42:03 -07:00
6429b57081 Improve docs (terminology, hyperlinks). 2016-05-31 17:17:36 -07:00
5650f7dc35 Finishing pass on send/receive number. Examples distributed more sensibly. 2016-05-31 17:02:22 -07:00
a9cfe83bdf Target=kids so removing all 'Important Security Considerations' for now. 2016-05-31 12:06:03 -07:00
f9409b5fb5 Mailbot example works now. 2016-05-31 11:44:20 -07:00
7f9f14df18 rename 2016-05-27 21:40:59 -07:00
a383060b4d Improved examples; last one needs work. 2016-05-27 16:22:38 -07:00
04c8221b41 0.2.135 2016-05-27 14:48:59 -07:00
facea7d27d Bump pxt-core to 0.2.146 2016-05-27 14:48:57 -07:00
cfe65569ad Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-05-27 14:48:56 -07:00
7a0ad8e3ed disabling source maps 2016-05-27 14:16:47 -07:00
4fb10faec2 Radio send/receive string. Rewrote text. Updated examples. 2016-05-27 12:03:54 -07:00
f3463b5961 refactor strings.json generation for packages 2016-05-27 09:23:47 -07:00
f39703e6f7 refreshed docs 2016-05-27 08:55:40 -07:00
74b333dee4 various small updates to docs 2016-05-27 07:06:24 -07:00
466bda468f update instructions 2016-05-26 21:38:11 -07:00
f4afa773ad missing images blocks 2016-05-26 20:42:15 -07:00
21280f41bc updated random boolean color 2016-05-26 19:55:25 -07:00
41c7053f3f added math.randomBoolean 2016-05-26 19:49:38 -07:00
1a00fded98 final vidoe cleanup 2016-05-26 19:33:26 -07:00
304ef89a1d 0.2.134 2016-05-26 19:30:45 -07:00
433b2bb08d Bump pxt-core to 0.2.145 2016-05-26 19:30:43 -07:00
273e23095b Merged. 2016-05-26 16:52:33 -07:00
8af6d640d3 Exhaustive rewrite. Did not change code much. 2016-05-26 16:18:33 -07:00
5553fb93bb removing videos from docs 2016-05-26 15:24:10 -07:00
493f76eba7 removed video from rps 2016-05-26 15:10:46 -07:00
91b90bf70e 0.2.133 2016-05-26 12:49:32 -07:00
43adfa198f Bump pxt-core to 0.2.143 2016-05-26 12:49:30 -07:00
59f7d0b537 update logo 2016-05-26 12:27:05 -07:00
f3bfe3d94e 0.2.132 2016-05-26 11:15:56 -07:00
ed54ace797 Bump pxt-core to 0.2.141 2016-05-26 11:15:16 -07:00
0648e80131 added serial.redirect 2016-05-26 11:07:09 -07:00
ce9a83ff28 0.2.131 2016-05-26 09:15:26 -07:00
54439bba4d Bump pxt-core to 0.2.140 2016-05-26 09:15:22 -07:00
23a581c899 added rock-paper-scissors page 2016-05-26 09:15:10 -07:00
3f8fa4b05b 0.2.130 2016-05-25 10:53:55 -07:00
53ab8651bd Bump pxt-core to 0.2.139 2016-05-25 10:53:52 -07:00
87300be648 updated starter template 2016-05-24 22:18:33 -07:00
d0a7df7f36 0.2.129 2016-05-24 21:57:47 -07:00
1c8fa5eab6 move pins->map up in block list 2016-05-24 21:39:57 -07:00
d8c2d697b1 Merge pull request #75 from gbaman/master
Add few more radio documentation pages
2016-05-24 21:21:00 -07:00
2ede815535 Add write-value-to-serial documentation 2016-05-25 02:58:27 +01:00
a67f16a860 Deleted redundant paragraph. 2016-05-24 18:27:14 -07:00
819ab9aa9a Add receive-string documentation page 2016-05-25 02:23:33 +01:00
318ffde27f Add send-string documentation page 2016-05-25 01:53:13 +01:00
525e59ae4f Heavy rewrite; added Fahrenheit example too for US. 2016-05-24 17:51:10 -07:00
ab087b4afa Add set-transmit-power documentation page 2016-05-25 01:40:01 +01:00
3b8ae69a6c Rewrite of text and examples. 2016-05-24 15:36:04 -07:00
8de6605112 0.2.128 2016-05-24 14:32:27 -07:00
daea493dcb Bump pxt-core to 0.2.138 2016-05-24 14:32:11 -07:00
b290692334 using pxt constant to find binary .hex 2016-05-24 14:06:25 -07:00
f25f295d0c 0.2.127 2016-05-24 13:03:06 -07:00
5fd691ef92 Bump pxt-core to 0.2.137 2016-05-24 13:03:04 -07:00
67c8753315 Updating loop docs 2016-05-24 12:30:31 -07:00
154 changed files with 909 additions and 431 deletions

4
.gitignore vendored
View File

@ -1,9 +1,11 @@
node_modules
yotta_modules
yotta_targets
built
typings
tmp
temp
projects
projects/**
win10/app/bin
win10/app/bld
win10/*.opendb

View File

@ -1,7 +1,7 @@
# micro:bit target for PXT
This target allow to program a [BBC micro:bit](https://www.microbit.co.uk/) using
[Microsoft Programming Experience Toolkit](https://github.com/Microsoft/pxt).
PXT ([Microsoft Programming Experience Toolkit](https://github.com/Microsoft/pxt)).
* [Try it live](https://m.pxt.io)
@ -28,17 +28,26 @@ Run this command to open a local web server:
```
pxt serve
```
If the local server opens in the wrong browser, make sure to copy the URL containing the local token.
Otherwise, the editor will not be able to load the projects.
If you need modify the `.cpp` files, turn on yotta compilation with the ``-yt`` flag:
```
pxt serve -yt
```
To make sure you're running the latest tools, run
```
npm update
```
More instructions at https://github.com/Microsoft/pxt#running-a-target-from-localhost
## Universal Windows App
The Windows 10 app is a [Universal Windows Hosted Web App](https://microsoftedge.github.io/WebAppsDocs/en-US/win10/CreateHWA.htm)
that wraps m.pxt.io and provides additional features.
that wraps ``m.pxt.io`` and provides additional features.
### Building

View File

@ -1,8 +1,8 @@
/// <reference path="../node_modules/pxt-core/built/pxt.d.ts"/>
import * as fs from 'fs';
import * as path from 'path';
import * as child_process from 'child_process';
import * as fs from "fs";
import * as path from "path";
import * as child_process from "child_process";
let writeFileAsync: any = Promise.promisify(fs.writeFile)
let execAsync: (cmd: string, options?: { cwd?: string }) => Promise<Buffer> = Promise.promisify(child_process.exec)
@ -13,10 +13,10 @@ export function deployCoreAsync(res: ts.pxt.CompileResult) {
if (drives.length == 0) {
console.log("cannot find any drives to deploy to")
} else {
console.log("copy microbit.hex to " + drives.join(", "))
console.log(`copy ${ts.pxt.BINARY_HEX} to ` + drives.join(", "))
}
return Promise.map(drives, d =>
writeFileAsync(d + "microbit.hex", res.outfiles["microbit.hex"])
writeFileAsync(d + ts.pxt.BINARY_HEX, res.outfiles[ts.pxt.BINARY_HEX])
.then(() => {
console.log("wrote hex file to " + d)
}))

View File

@ -8,6 +8,6 @@
"module": "commonjs",
"rootDir": ".",
"newLine": "LF",
"sourceMap": true
"sourceMap": false
}
}

View File

@ -2,10 +2,6 @@
Are you ready to build cool BBC micro:bit programs? For each challenge, reorder the blocks to recreate the program.
## Open [https://m.pxt.io](/) and create a new **Blocks Editor** project
## Basic
### Show leds
Use the blocks below to draw a figure on the screen. You can redo the smiley face or try something else!
@ -22,7 +18,7 @@ basic.showLeds(`
To transfer your code to the BBC micro:bit,
* connect your micro:bit to the computer using the USB cable
* click on **Download**
* click on **Compile**
* drag&drop the **.hex** file into the **MICROBIT** drive
* wait till the yellow light is done blinking!
@ -47,6 +43,11 @@ Show one image after the other to create an animation by snapping them together.
`)
```
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!
### Repeat forever
@ -77,8 +78,6 @@ basic.forever(() => {
Use the blocks ``show leds`` and ``forever``
to create your own custom awesome animation!
## Inputs
### 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.
@ -168,4 +167,4 @@ input.onPinPressed(TouchPin.P0, () => {
### Your turn now!
Use the scree, buttons, gestures, pins to create a fun game using the micro:bit.
Use the screen, buttons, gestures, pins to create a fun game using the micro:bit.

View File

@ -34,7 +34,7 @@
* [Rock Paper Scissors](/lessons/rock-paper-scissors), create the classic game of rock paper scissors with if statement
* [Truth or Dare](/lessons/truth-or-dare), a game that forces each player to reveal a secret or do something funny with if statement
* [Spinner](/lessons/spinner), spin the arrow with multiple if statements
* [Die Roll](/lessons/die-roll), spin with more if statements
* [Dice Roll](/lessons/dice-roll), spin with more if statements
* [Looper](/lessons/looper), display a series of numbers with a for loop index
* [Strobe Light](/lessons/strobe-light), develop shapes with a nested for loops
* [Temperature](/lessons/temperature), get the ambient temperature (degree Celsius °C)

View File

@ -1,8 +1,6 @@
# answering machine blocks lesson
create an answering machine on the BBC micro:bit #docs
### @video td/videos/answering-machine-0
Create an answering machine on the BBC micro:bit
## Topic
@ -25,12 +23,8 @@ Learn how to creating a message with a **string**, `show string` to write your m
```cards
basic.showString('Hi!')
input.onButtonPressed(Button.A, () => {})
```
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
## Objectives
* learn how to show a string on the LED screen one character at a time

View File

@ -4,7 +4,6 @@ Learn to create an answering machine on the micro:bit
### ~avatar avatar
### @video td/videos/answering-machine-0
Let's learn how to create an answering machine!

View File

@ -12,8 +12,6 @@ basic.showString("ASK ME A QUESTION")
### Challenge 1
### @video td/videos/answering-machine-1
Now we need to reply after someone asks micro:bit a yes or no question. We want to respond `YES` when button `A` is pressed. Add a condition for button `A` and inside it show the string `YES`.
```blocks
@ -27,8 +25,6 @@ input.onButtonPressed(Button.A, () => {
### Challenge 2
### @video td/videos/answering-machine-2
What if micro:bit's answer to the question is no? Let's have `NO` be displayed when button `B` is pressed. Add a condition for button `B` and inside it show the string `NO`.
```blocks

View File

@ -1,8 +1,6 @@
# beautiful image lesson
display beautiful images on the BBC micro:bit.
### @video td/videos/beautiful-image-0
Display beautiful images on the BBC micro:bit.
## Topic

View File

@ -4,8 +4,6 @@ Generate and show a beautiful image.
### ~avatar avatar
### @video td/videos/beautiful-image-0
Let's learn how to show an image on the LED screen.
### ~

View File

@ -18,8 +18,6 @@ basic.showLeds(`
### Challenge 1
### @video td/videos/beautiful-image-1-2
Now show an new image that will display on the micro:bit.
```blocks

View File

@ -2,8 +2,6 @@
Learn how to create a blinking LED.
### @video td/videos/blink-0
## Topic
Plot
@ -30,7 +28,6 @@ basic.pause(100)
basic.forever(() => {})
```
## Objectives
* learn how to turn on LED lights on the LED screen

View File

@ -4,7 +4,15 @@ Turn an LED on and off with forever
### ~avatar avatar
### @video td/videos/blink-0
```sim
basic.forever(() => {
led.plot(2, 2)
basic.pause(500)
led.unplot(2, 2)
basic.pause(500)
})
```
Let's build a blinking light!
### ~
@ -43,7 +51,6 @@ basic.forever(() => {
led.unplot(2, 2)
basic.pause(500)
})
```
### ~avatar boothing

View File

@ -17,8 +17,6 @@ basic.forever(() => {
### Challenge 1
### @video td/videos/blink-1
Let's display a "smiley face" on the screen! We'll start by plotting the eyes.
Add `plot(1,1)` and `plot(3,1)` under `plot(2,2)` ; then add `unplot(1,1)`, `unplot(3,1)` and `unplot(2,2)` after `pause`. When you're ready, don't forget to run your code to try it out!
@ -38,8 +36,6 @@ basic.forever(() => {
### Challenge 2
### @video td/videos/blink-2
Let's add the code to plot the mouth by using `plot` and `unplot` to the following coordinates: (1,4), (2,4) and (3,4). When you're ready, don't forget to run your code to try it out!
```blocks
@ -63,8 +59,6 @@ basic.forever(() => {
### Challenge 3
### @video td/videos/blink-3
Let's keep using `plot` to convert the mouth into a smiley face.
```` bitmatrix

View File

@ -2,8 +2,6 @@
A game to catch eggs in a basket.
### @video td/videos/catch-the-egg-game-0
## Topic
Variables

View File

@ -108,8 +108,6 @@ basic.forever(() => {
### Challenge 3
### @video td/videos/catch-the-egg-game-4
Let's make the egg fall faster by decreasing the amount of time it pauses in each position by decreasing **falling pause** by `25` every 5 catches. Now, instead of pausing for 300 milliseconds we can pause for the value of **falling pause**.
```blocks

View File

@ -2,8 +2,6 @@
create a die on the BBC micro:bit.
### @video td/videos/compass-0
## Topic
If (Conditionals)

View File

@ -2,8 +2,6 @@
Learn how to create a counter with with on button pressed.
### @video td/videos/counter-0
## Topic
Variables

View File

@ -4,8 +4,6 @@ Display a number with a variable.
### ~avatar avatar
### @video td/videos/counter-0
Welcome! This tutorial will teach you how to make a counter that increments when button A is pressed. Let's get started!
### ~

View File

@ -16,8 +16,6 @@ input.onButtonPressed(Button.A, () => {
### Challenge 1
### @video td/videos/counter-1-2
Let's add the code to `count` when `B` is pressed. Add an event handler with `on button pressed(B)` then add the code to `count`.
@ -33,7 +31,6 @@ input.onButtonPressed(Button.B, () => {
})
```
### Challenge 3
Now let's try to reset the counter when the micro:bit is shaken. You will need to register an event handler with `on shake`.

View File

@ -1,8 +1,6 @@
# die roll lesson
# dice roll lesson
create a die on the BBC micro:bit.
### @video td/videos/die-roll-0
Create a dice on the BBC micro:bit.
## Topic
@ -10,10 +8,10 @@ If (Conditionals)
## Quick Links
* [activity](/lessons/die-roll/activity)
* [challenges](/lessons/die-roll/challenges)
* [quiz](/lessons/die-roll/quiz)
* [quiz answers](/lessons/die-roll/quiz-answers)
* [activity](/lessons/dice-roll/activity)
* [challenges](/lessons/dice-roll/challenges)
* [quiz](/lessons/dice-roll/quiz)
* [quiz answers](/lessons/dice-roll/quiz-answers)
## Prior learning/place of lesson in scheme of work

View File

@ -1,12 +1,10 @@
# die roll activity
# dice roll activity
Create a die on the micro:bit
Create a dice on the micro:bit
### ~avatar avatar
### @video td/videos/die-roll-0
Welcome! This tutorial will help you create a die. Let's get started!
Welcome! This tutorial will help you create a dice. Let's get started!
### ~
@ -19,7 +17,7 @@ input.onGesture(Gesture.Shake, () => {
})
```
We need to show a random value from 1 to 6 on our die. So let's make a local variable called **roll**.
We need to show a random value from 1 to 6 on our dice. So let's make a local variable called **roll**.
```blocks
input.onGesture(Gesture.Shake, () => {
@ -27,7 +25,7 @@ input.onGesture(Gesture.Shake, () => {
})
```
We need a condition for if **roll** is 5. We will show a `6` if **roll** is 5 because **roll** has a range from 0 to 5. We can use `show LEDs` to display the side of a die that shows 6.
We need a condition for if **roll** is 5. We will show a `6` if **roll** is 5 because **roll** has a range from 0 to 5. We can use `show LEDs` to display the side of a dice that shows 6.
```blocks
@ -45,7 +43,7 @@ input.onGesture(Gesture.Shake, () => {
```
Let's use an `else if` condition for if **roll** is 4. If **roll** is 4 we can show 5 dots on the die.
Let's use an `else if` condition for if **roll** is 4. If **roll** is 4 we can show 5 dots on the dice.
```blocks
@ -72,7 +70,7 @@ input.onGesture(Gesture.Shake, ()=> {
```
Now we need to repeat the same steps for if **roll** is 3. If **roll** is 3 we will show `4` on the die.
Now we need to repeat the same steps for if **roll** is 3. If **roll** is 3 we will show `4` on the dice.
```blocks
@ -106,7 +104,7 @@ input.onGesture(Gesture.Shake, () => {
```
Let's also repeat these steps to show the 3, 2, and 1 on the die. We are almost done with our die!
Let's also repeat these steps to show the 3, 2, and 1 on the dice. We are almost done with our dice!
```blocks
input.onGesture(Gesture.Shake, () => {
@ -165,7 +163,7 @@ input.onGesture(Gesture.Shake, () => {
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/lessons/die-roll/challenges)!
Excellent, you're ready to continue with the [challenges](/lessons/dice-roll/challenges)!
### ~

View File

@ -1,10 +1,10 @@
# die roll challenges
# dice roll challenges
Create a die on the micro:bit.
Create a dice on the micro:bit.
## Before we get started
Complete the following [guided tutorial](/lessons/die-roll/activity), your code should look like this:
Complete the following [guided tutorial](/lessons/dice-roll/activity), your code should look like this:
```blocks
input.onGesture(Gesture.Shake, () => {
@ -62,7 +62,7 @@ input.onGesture(Gesture.Shake, () => {
### Challenge 1
Modify the line of code with `pick random` so that only number 1-4 can appear on the die.
Modify the line of code with `pick random` so that only number 1-4 can appear on the dice.
```blocks
@ -121,7 +121,7 @@ input.onGesture(Gesture.Shake, () => {
### Challenge 2
Let's make a trick die! Modify the line of code with `pick random` so that only numbers 3-6 can appear on the die. Also note that we need to ensure `roll = 0` when only 1 dot is shown on the BBC micro:bit.
Let's make a trick dice! Modify the line of code with `pick random` so that only numbers 3-6 can appear on the dice. Also note that we need to ensure `roll = 0` when only 1 dot is shown on the BBC micro:bit.
```blocks
input.onGesture(Gesture.Shake, () => {

View File

@ -1,8 +1,8 @@
# die roll quiz answers
# dice roll quiz answers
Create a die when the BBC micro:bit is shaken
Create a dice when the BBC micro:bit is shaken
These are the answers to the [die roll quiz](/lessons/die-roll/quiz).
These are the answers to the [dice roll quiz](/lessons/dice-roll/quiz).
## 1. Create a variable named 'roll' that will be randomly assigned to a number between 0 and 5.

View File

@ -1,12 +1,12 @@
# die roll quiz
# dice roll quiz
Create a die when the BBC micro:bit is shaken
Create a dice when the BBC micro:bit is shaken
## Name
## Directions
Use this activity document to guide your work in the [die roll tutorial](/lessons/die-roll/activity).
Use this activity document to guide your work in the [dice roll tutorial](/lessons/dice-roll/activity).
Answer the questions while completing the tutorial. Pay attention to the dialogues!

View File

@ -1,8 +1,6 @@
# digi yoyo lesson
create a counter with a while loop.
### @video td/videos/digi-yoyo-0
Create a counter with a while loop.
## Topic

View File

@ -4,8 +4,6 @@ Create a counter with a while loop.
### ~avatar avatar
### @video td/videos/digi-yoyo-0
Welcome! This tutorial will teach how to create a counter with a while loop. Let's get started!
### ~

View File

@ -40,8 +40,6 @@ while (count > 0) {
### Challenge 2
### @video td/videos/digi-yoyo-1-2
Inside of the while loop, let's add `pause->(1000)` so that we have a pause between each number as it's counting down. Also, let's show `count`!

View File

@ -2,8 +2,6 @@
Learn how to create LED images with a global variable.
### @video td/videos/flashing-heart-0
## Topic
Pause

View File

@ -4,8 +4,6 @@ Control images with a variable.
### ~avatar avatar
### @video td/videos/flashing-heart-0
In this activity, you will learn how to blink an image on the LED screen.
### ~

View File

@ -25,8 +25,6 @@ basic.forever(() => {
### Challenge 1
### @video td/videos/flashing-heart-1
Let's plot a different image. Let's display a broken heart!
To do this, you need to add a block between the last line and the end loop. Add a `show LEDs` block and then add a `pause` of 500 milliseconds.
@ -60,8 +58,6 @@ basic.forever(() => {
### Challenge 2
### @video td/videos/flashing-heart-2
Now let's alternate flashing the heart and the broken heart. To do this, we need to add a `clear screen` block and then add a `pause` block of 500 milliseconds under the new code we added in Challenge 1.

View File

@ -2,8 +2,6 @@
Learn how to create a counter with with on button pressed.
### @video td/videos/counter-0
## Topic
Game Library

View File

@ -1,13 +1,5 @@
# game counter activity
Turn an LED on and off with forever loop
### ~avatar avatar
### @video td/videos/counter-0
### ~
Have you ever tried to create a game counter? The concept is fairly simply: increase the game `score` with `on button pressed` .
Let's start by adding `on button (A) pressed` will run each time the user presses A. Let's add a line of code that increments `score` by `1`.

View File

@ -15,8 +15,6 @@ input.onButtonPressed(Button.A, () => {
### Challenge 1
### @video td/videos/counter-1-2
Let's add the code to `score` when `B` is pressed. Add an event handler with `on button (B) pressed` then add the code to `score`.

View File

@ -2,8 +2,6 @@
Learn to create a random number with input from button A.
### @video td/videos/guess-the-number-0
## Topic
Math - Pick Random

View File

@ -4,8 +4,6 @@ Guess the number with math random.
### ~avatar avatar
### @video td/videos/guess-the-number-0
Welcome! This tutorial will help you create a guess the number game! Let's get started!
### ~

View File

@ -15,8 +15,6 @@ input.onButtonPressed(Button.A, () => {
### Challenge 1
### @video td/videos/guess-the-number-2
When button `B` is pressed, we want to clear the screen. This will make it so users can play your game over and over again! Add an event handler to handle this case.
```blocks

View File

@ -2,8 +2,6 @@
### ~avatar avatar
### @video td/videos/guess-the-number-0
This tutorial will help you create a guess the number game! Let's get started!
### ~

View File

@ -2,8 +2,6 @@
Learn to control blinking LEDs.
### @video td/videos/looper-0
## Topic
For Loop

View File

@ -1,13 +1,5 @@
# looper blocks activity
Display a series of numbers with a for loop.
### ~avatar avatar
### @video td/videos/looper-0
### ~
Welcome! This activity will teach how to display a series of numbers for a for loop. Let's get started!
Let's create a for loop where `0` is the loop's starting value, `i` is the index variable, and `5` is the ending value. The index variable `i` starts at 0 and increases by 1 each time through the loop. The loop ends when `i = 5`.

View File

@ -20,8 +20,6 @@ for (let i = 0; i < 6; i++) {
### Challenge 1
### @video td/videos/looper-1
What if we want to count up to lucky number 7 instead? Let's do that by changing the ending value to `7` instead of `5`.
@ -37,8 +35,6 @@ for (let i = 0; i < 8; i++) {
### Challenge 2
### @video td/videos/looper-2
What about 9? Let's do that by changing the ending value to `9`.
```blocks
@ -55,8 +51,6 @@ for (let i = 0; i < 10; i++) {
### Challenge 3
### @video td/videos/looper-3
Now let's start counting from `3` instead! Our for loop will always start at `0` so we simply add `3` to the `i` variable when passing it to `show number`.
```blocks
@ -72,8 +66,6 @@ Run it on the simulator!
### Challenge 4
### @video td/videos/looper-4
Now, let's **count down from 9**. Change the line `show number(i + 2, 150)` to `show number(9 - i, 150)`.
```blocks

View File

@ -1,8 +1,6 @@
# love meter blocks lesson
create a love meter with the BBC micro:bit.
### @video td/videos/love-meter-0
Create a love meter with the BBC micro:bit.
## Topic

View File

@ -4,8 +4,6 @@ Create a love meter with the micro:bit
### ~avatar avatar
### @video td/videos/love-meter-0
Welcome! This activity will help you create a love meter with the micro:bit. Let's get started!
### ~

View File

@ -45,8 +45,6 @@ input.onPinPressed(TouchPin.P0, () => {
### Challenge 3
### @video td/videos/love-meter-3
**If** the rating is between 4 and 7, display the text "MEDIOCRE!" **else** display the text "MATCHED!"
```blocks

View File

@ -1,8 +1,6 @@
# lucky 7 blocks lesson
show a number on the LED screen.
### @video td/videos/lucky-7-0
Show a number on the LED screen.
## Topic

View File

@ -4,8 +4,6 @@ Show a number on the LED screen.
### ~avatar avatar
### @video td/videos/lucky-7-0
Let's learn how to show the lucky number 7 on the LED screen.
### ~

View File

@ -21,8 +21,6 @@ basic.pause(500)
### Challenge 2
### @video td/videos/lucky-7-1-2
What about other multiples of 7? Let's display the next multiple of 7 on the screen!
```blocks

View File

@ -2,7 +2,7 @@
show an image that points up when the logo is up.
### @video td/videos/magic-logo-0
## Topic

View File

@ -4,8 +4,6 @@ Show an image that points up when the logo is up.
### ~avatar avatar
### @video td/videos/magic-logo-0
Welcome! This tutorial will help you display an arrow pointing toward the logo! Let's get started.
### ~

View File

@ -24,8 +24,6 @@ input.onLogoUp(() => {
How about when the logo is down? We should display an arrow pointing downward!
### @video td/videos/magic-logo-1-2
```blocks
input.onLogoUp(() => {
basic.showLeds(`

View File

@ -2,8 +2,6 @@
change the brightness of the BBC micro:bit.
### @video td/videos/night-light-0
## Topic
Set Brightness

View File

@ -4,8 +4,6 @@ Change the brightness of the micro:bit.
### ~avatar avatar
### @video td/videos/night-light-0
Welcome! This tutorial will teach you how to change the brightness of the micro:bit. Let's get started!
### ~

View File

@ -23,7 +23,7 @@ input.onButtonPressed(Button.A, () => {
```
### Challenge 1
### @video td/videos/night-light-2
What if we want to turn off all the LEDs? Let's do this by setting the brightness to `0` when button `B` is pressed. Add an event handler with `on button pressed(B)` add `set brightness(0)` to turn off the LEDs.

View File

@ -55,7 +55,7 @@ input.onButtonPressed(Button.B, () => {
### Challenge 2
### @video td/videos/offset-image-2
Now we want to make sure that the button does not go off the screen to the right. Add a new line that checks to see if offset = 5 after button `A` is pressed.

View File

@ -2,7 +2,7 @@
a game against the BBC micro:bit.
### @video td/videos/rock-paper-scissors-0
## Topic

View File

@ -4,7 +4,7 @@ A classic game against the micro:bit.
### ~avatar avatar
### @video td/videos/rock-paper-scissors-0
Welcome! This tutorial will help you create a game of rock paper scissors with the micro:bit. Let's get started!

View File

@ -93,7 +93,7 @@ input.onButtonPressed(Button.A, () => {
### Challenge 2
### @video td/videos/rotation-animation-1-and-2
Now that we have the on button pressed condition, let's make the animation stop rotating by setting the rotating global variable to false when button `A` is pressed.

View File

@ -2,7 +2,7 @@
clear the screen by pressing button "A".
### @video td/videos/screen-wipe-0
## Topic

View File

@ -4,7 +4,7 @@ Clear the screen by pressing buttons on the micro:bit
### ~avatar avatar
### @video td/videos/screen-wipe-0
This activity will teach how to clear the screen by pressing button A on the micro:bit.

View File

@ -85,7 +85,7 @@ input.onButtonPressed(Button.B, () => {
### Challenge 2
### @video td/videos/screen-wipe-2
Replay the animation when the "B" button is pressed placing the `show LEDs` block on the canvas.

View File

@ -2,7 +2,7 @@
design a blinking image lesson #docs
### @video td/videos/smiley-0
## Topic

View File

@ -4,7 +4,7 @@ Learn to design a blinking image.
### ~avatar avatar
### @video td/videos/smiley-0
Welcome! This tutorial will help you make a smiley face blink. Let's get started!

View File

@ -54,7 +54,7 @@ input.onButtonPressed(Button.A, () => {
### Challenge 2
### @video td/videos/smiley-2
Now, we want to show a frowny face when this button is pressed. Let's show the LEDs.

View File

@ -2,7 +2,7 @@
design a blinking rectangle animation.
### @video td/videos/snowflake-fall-0
## Topic

View File

@ -4,7 +4,7 @@ design a blinking rectangle animation.
### ~avatar avatar
### @video td/videos/snowflake-fall-0
Welcome! This tutorial will teach how design a **snowfall animation**. Let's get started!

View File

@ -27,7 +27,7 @@ basic.forever(() => {
### Challenge 1
### @video td/videos/snowflake-fall-1
To finalize our snowflake fall, let's add a different snowflake pattern.

View File

@ -2,7 +2,7 @@
code a speed game by declaring Booleans on the BBC micro:bit.
### @video td/videos/speed-button-3
## Topic

View File

@ -63,7 +63,7 @@ input.onButtonPressed(Button.A, () => {
### Challenge 3
### @video td/videos/speed-button-3
Now let's display if the user won or lost. To do so, we need to check the status of `fastPress` when the game is finished, and then show the correct message.
@ -91,7 +91,7 @@ input.onButtonPressed(Button.A, () => {
### Challenge 4
### @video td/videos/speed-button-4
Modify the code to change the difficulty level. Increasing the time will make it easier, while decreasing the time will make it harder. For example, changing the 5000 milliseconds to 6000 milliseconds will make the difficulty easier.

View File

@ -2,7 +2,7 @@
a spin the BBC micro:bit game with the input on shake.
### @video td/videos/spinner-0
## Topic

View File

@ -4,7 +4,7 @@ Create an arrow that randomly points to a player.
### ~avatar avatar
### @video td/videos/spinner-0
### ~

View File

@ -2,7 +2,7 @@
Learn how to create a blinking LED script.
### @video td/videos/strobe-light-0
## Topic

View File

@ -4,7 +4,7 @@ Develop shapes with a for loop.
### ~avatar avatar
### @video td/videos/strobe-light-0
Welcome! This guided tutorial will teach how to develop shapes with a for loop. Let's get started!

View File

@ -19,7 +19,7 @@ for (let i = 0; i < 5; i++) {
### Challenge 1
### @video td/videos/strobe-light-1
Make the LEDs light up faster by changing the **pause** from 200 to 100 milliseconds:
@ -36,7 +36,7 @@ for (let i = 0; i < 5; i++) {
### Challenge 2
### @video td/videos/strobe-light-2
Make the board light up by rows instead of by columns by swapping the `i` and `j` variables in `plot(i, j)`.
@ -53,7 +53,7 @@ for (let i = 0; i < 5; i++) {
### Challenge 3
### @video td/videos/strobe-light-ultimate
Now that all the LEDs are lit up, let's make them turn off by reversing the strobe light pattern! You can use `unplot` to turn off a single LED.

View File

@ -22,7 +22,7 @@ The lesson plan maps to the Progressions Pathways, Computing Curriculum, and Qui
Expand your knowledge of programming with lots of great step-by-step activities. All the lessons come with instructions that will drive the students to a complete, functional code. These activities are very directive to make sure that students keep progressing. When the activities are over, additional challenges are given to advance code through printed instructions. An activity contains supporting videos as shown with the [blink activity](/lessons/blink/activity).
### @video td/videos/blink-0
3) Quiz

View File

@ -2,7 +2,7 @@
create a love meter with the BBC micro:bit.
### @video td/videos/truth-or-dare-0
## Topic

View File

@ -4,7 +4,7 @@ A multi-player game that forces each player to reveal a secret or something funn
### ~avatar avatar
### @video td/videos/truth-or-dare-0
Welcome! This tutorial will teach how to program a game of truth or dare on the micro:bit. Let's get started!

View File

@ -2,7 +2,7 @@
### ~avatar avatar
### @video td/videos/truth-or-dare-0
The *Truth or dare!* game works as follows: a player spins the BBC micro:bit on the table.
When the micro:bit stops spinning, the player pointed by the arrow (displayed on screen) must press the button "A"

View File

@ -2,7 +2,7 @@
measure the acceleration on the micro:bit in the "z" direction.
### @video td/videos/zoomer-0
## Topic

View File

@ -4,7 +4,7 @@ Measure the acceleration on the micro:bit in the "z" direction.
### ~avatar avatar
### @video td/videos/zoomer-0
### ~

View File

@ -14,7 +14,7 @@ basic.forever(() => {
```
### Challenge 1
### @video td/videos/zoomer-2
We'll modify the code to display the `x` acceleration if the `A` button is pressed. For that, we need to store `acceleration (x)` in a new variable `ax` and use a `button (A) is pressed` to detect if the button is pressed.

View File

@ -10,5 +10,39 @@ to a microbit.
## Finding libraries
From the editor, the user clicks on **More** then **Add Package** and searches for the package.
To see the list of packages, click on **More** then **Show Files** to see the project file list.
To remove a package, click on the garbage button in the file list next to the package.
## Publishing libraries
Packages can be published from the pxt command line. We are still sorting out the details.
## Localizing libraries
It is possible to package localization strings for the **jsDoc** description associated to the API in the package.
When compiling a package, the PXT compiler generates a `strings.json` file under the `_locales/` folder.
This file contains a map from the symbol name to the en
```
{
...
"basic": "Provides access to basic micro:bit functionality.",
...
}
```
```
{
"basic.clearScreen": "Eteint toutes les diodes."
}
```
```
_locales/
_locales/fr/strings.json
_locales/pt-BR/strings.json
```

15
docs/projects.md Normal file
View File

@ -0,0 +1,15 @@
# Projects
### @short Projects
### ~column
## Beginner
* [Rock Paper Scissors](/projects/rock-paper-scissors)
### ~
### ~column

View File

@ -0,0 +1,34 @@
## Getting started
• Go to https://m.pxt.io/
• To create a new project, click new Project
Tap or click Blocks.
## Step 1
Use [show leds](/reference/basic/showLeds) and make your code look like this:
```blocks
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
```
Once you are done coding, don't forget to run your code with the Play button.
## Step 2
Add a [pause](/reference/basic/pause) to wait and [clear screen](/reference/basic/clearScreen) to turn off the LEDs.
```blocks
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
basic.pause(500);
basic.clearScreen();
```

View File

@ -0,0 +1,234 @@
# rock paper scissors
### ~avatar avatar
```sim
input.onGesture(Gesture.Shake, () => {
let img = Math.random(3)
if (img == 0) {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #
`)
} else if (img == 1) {
basic.showLeds(`
. . . . .
. # # # .
. # # # .
. # # # .
. . . . .
`)
} else {
basic.showLeds(`
# # . . #
# # . # .
. . # . .
# # . # .
# # . . #
`)
}
})
```
In this project, you will 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.
### ~
## Materials needed
* Your BBC micro:bit -- that's it!
## 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.
```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 `weapon`. (This variable is named `weapon` because
rock, paper, and scissors are the weapons you use to battle your friends!)
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 weapon = 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
`weapon` 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 weapon = Math.random(3)
if (weapon == 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 `weapon` is `1`.
Then add a ``show leds`` block with a picture of a rock.
```blocks
input.onGesture(Gesture.Shake, () => {
let weapon = Math.random(3)
if (weapon == 0) {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #
`)
} else if (weapon == 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 weapon = Math.random(3)
if (weapon == 0) {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #
`)
} else if (weapon == 1) {
basic.showLeds(`
. . . . .
. # # # .
. # # # .
. # # # .
. . . . .
`)
} else {
basic.showLeds(`
# # . . #
# # . # .
. . # . .
# # . # .
# # . . #
`)
}
})
```
### ~hint
You don't need to check if `weapon` 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! 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())
})
```
## Step 8: Hacking Rock Paper Scissors
How else can you make your game better?
Ever hear of [Rock Paper Scissors Spock Lizard](http://www.samkass.com/theories/RPSSL.html)?

5
docs/reference/String.md Normal file
View File

@ -0,0 +1,5 @@
# String
```cards
String.fromCharCode(0);
```

View File

@ -1,6 +1,7 @@
# Temperature
Get the ambient temperature (degree Celsius °C). The temperature is inferred from the the surface temperature of the various chips on the micro:bit.
Find the temperature where you are. The temperature is measured in Celsius (metric).
The micro:bit can find the temperature nearby by checking how hot its computer chips are.
```sig
input.temperature();
@ -8,24 +9,48 @@ input.temperature();
### Returns
* [Number](/reference/types/number) - temperature in degree Celsius °C.
* a [Number](/reference/types/number) that means the Celsius temperature.
### How does it work?
The BBC micro:bit does not have a dedicated temperature sensor. Instead, the temperature provided is actually the temperature of the silicon die on the main CPU. As the processor generally runs cold though (it is a high efficiency ARM core), the temperature is a good approximation of the ambient temperature... you might warm up if you give the processor a lot of work to do though, and don't [sleep](/reference/basic/pause)!
The temperature sensor has a high precision, but isn't trimmed for accuracy. In other words, it can sense changes in temperature very well, but there may be (and probably is) base line offset. i.e. it might return 20 degrees when it's actually 17, but it would return 21 when it is 18 etc.
The BBC micro:bit checks how hot its CPU (main computer chip) is.
Because the micro:bit does not usually get very hot, the temperature of the CPU
is usually close to the temperature of wherever you are.
The micro:bit might warm up a little if you make it work hard, though!
### Example: micro:bit thermometer
The following example uses the `temperature` and the `show number` to display the room temperature.
The following example uses `temperature` and `show number` to show the temperature of the room.
```sig
```blocks
basic.forever(() => {
let temp = input.temperature()
basic.showNumber(temp)
})
```
### Example: Fahrenheit thermometer
This program measures the temperature using Fahrenheit degrees.
Fahrenheit is a way of measuring temperature that is commonly used in the United States.
To make a Celsius temperature into a Fahrenheit one, multiply the Celsius temperature by
1.8 and add 32.
```blocks
basic.forever(() => {
let c = input.temperature()
let f = (c * 1.8) + 32
basic.showNumber(f)
})
```
### ~hint
Try comparing the temperature your micro:bit shows to a real thermometer in the same place.
You might be able to figure out how much to subtract from the number the micro:bit
shows to get the real temperature. Then you can change your program so the micro:bit is a
better thermometer.
### ~
### Lessons

View File

@ -20,5 +20,5 @@ basic.showNumber(i)
### See also
[while](/reference/loops/while), [if](/reference/logic/if), [show number](/reference/basic/show-number)
[repeat](/reference/loops/repeat), [while](/reference/loops/while), [if](/reference/logic/if), [show number](/reference/basic/show-number)

View File

@ -1,19 +1,16 @@
# Repeat
Repeat code a preset number of times.
Run part of the program the number of times you say.
### Block Editor
![](/static/mb/blocks/contents-0.png)
### Touch Develop
### Lessons
Touch Develop has no `repeat` loop. Instead you can used a for loop
[looper](/lessons/looper)
```
for (let i = 0; i < 5; i++) {
}
```
### See also
The loop above will repeat five (5) times.
[for](/reference/loops/for), [while](/reference/loops/while), [if](/reference/logic/if), [show number](/reference/basic/show-number)

View File

@ -8,6 +8,7 @@ pins.digitalWritePin(DigitalPin.P0, 0);
pins.analogReadPin(AnalogPin.P0);
pins.analogWritePin(AnalogPin.P0, 1023);
pins.analogSetPeriod(AnalogPin.P0, 20000);
pins.map(0, 0, 1023, 0, 4);
pins.onPulsed(DigitalPin.P0, PulseValue.High, () => {
});
@ -16,7 +17,6 @@ pins.servoWritePin(AnalogPin.P0, 180);
pins.servoSetPulse(AnalogPin.P0, 1500);
pins.i2cReadNumber(0, NumberFormat.Int8LE);
pins.i2cWriteNumber(0, 0, NumberFormat.Int8LE);
pins.map(0, 0, 1023, 0, 4);
pins.analogPitch(0, 0);
pins.analogSetPitchPin(AnalogPin.P0);
```

View File

@ -2,18 +2,6 @@
Registers code to run when a packet is received over ``radio``.
## Important Security Consideration
The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits.
This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place.
For serious applications, BLE should be considered a substantially more secure alternative.
```sig
radio.onDataReceived(() => {})
```
### Parameters
* body - is an action

View File

@ -1,26 +1,15 @@
# Receive Number
Reads the next radio packet if any and returns the first number.
## Important Security Consideration
The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits.
This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place.
For serious applications, BLE should be considered a substantially more secure alternative.
```sig
radio.receiveNumber()
```
Receives the next number sent by a micro:bit in the same ``radio`` group.
### Return value
* the first number [number](/reference/types/number) of the packet if any. `0` otherwise.
* the first [number](/reference/types/number) that the micro:bit received. If it did not receive any numbers, this function will return `0`.
### Examples
### Example: Simple number receiver
Read the number broadcasted by other micro:bits.
This example receives the number broadcasted another micro:bit and shows it
as a bar graph.
```blocks
radio.onDataReceived(() => {
@ -28,7 +17,42 @@ radio.onDataReceived(() => {
})
```
### Example: Light level receiver
This example shows the light level from the [light level sender example](/reference/input/send-number)
as a number.
```blocks
radio.setGroup(99)
basic.forever(() => {
let level = radio.receiveNumber()
basic.showNumber(level)
})
```
### Example: Mailbot
This example receives the light level from the [light level sender example](/reference/input/send-number)
and shows a text string like **ALERT** if the light level becomes much brighter.
To find when the mail arrives, you can put the light level sender in your mailbox and it will
tell you when someone opens the box. You can try this with a normal
box too, like a present for a friend.
```blocks
radio.setGroup(99)
let max = 0
basic.forever(() => {
let level = radio.receiveNumber()
if (level > max) {
max = level
}
if (max > 10) {
basic.showString("ALERT")
}
})
```
### See also
[receive number](/reference/input/receive-number), [on data received](/reference/radio/on-data-received)
[send number](/reference/input/send-number), [on data received](/reference/radio/on-data-received)

View File

@ -0,0 +1,86 @@
# Receive String
Find the next string sent by `radio` from another micro:bit.
```sig
radio.receiveString()
```
### Return value
* the first [string](/reference/types/string) that was sent. If no string was sent, then this function returns an empty (blank) string.
### Example: Simple receiver
Show the string sent by another micro:bit.
```blocks
radio.onDataReceived(() => {
basic.showString(radio.receiveString());
});
```
### Example: Two-way radio
If you load this program onto two or more micro:bits, you can send a code word from one of them to the others by pressing button `A`.
The other micro:bits will receive the code word and then show it.
```blocks
input.onButtonPressed(Button.A, () => {
radio.sendString("Codeword: TRIMARAN")
basic.showString("SENT");
})
radio.onDataReceived(() => {
basic.showString(radio.receiveString());
});
```
### ~hint
A radio that can both transmit and receive is called a _transceiver_.
### ~
### Example: Mood radio
This is a simple program to send whether you are happy or sad over ```radio```.
Use the `A` or `B` button to select an emotion.
This program will also receive your friend's mood.
```blocks
let data: string = "";
input.onButtonPressed(Button.A, () => {
radio.sendString("H");
});
input.onButtonPressed(Button.B, () => {
radio.sendString("S");
});
radio.onDataReceived(() => {
data = radio.receiveString();
if ("H" == data) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .
`);
} else if ("S" == data) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #
`);
} else {
basic.showString("?");
}
});
```
### See also
[send string](/reference/radio/send-string), [on data received](/reference/radio/on-data-received)

View File

@ -1,26 +1,16 @@
# Send Number
Broadcasts a number data packet to other micro:bits connected via ``radio``.
## Important Security Consideration
The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits.
This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place.
For serious applications, BLE should be considered a substantially more secure alternative.
```sig
radio.sendNumber(0)
```
Broadcast a number to other micro:bits connected via ``radio``.
### Parameters
* packet - a number to be transmitted.
* num - a number to send.
### Examples
### Example: Broadcasting acceleration
Broadcasts the value of ``acceleration`` x to other micro:bits.
This example broadcasts the value of your micro:bit's ``acceleration`` in the `x` direction
(left and right) to other micro:bits.
This kind of program might be useful in a model car or model rocket.
```blocks
input.onButtonPressed(Button.A, () => {
@ -28,6 +18,20 @@ input.onButtonPressed(Button.A, () => {
})
```
### Light level sender
This example broadcasts the level of the light around it.
You can do some interesting things with it if you use it along with the
[Mailbot](/reference/radio/receive-number) example.
```blocks
radio.setGroup(99)
basic.forever(() => {
let level = input.lightLevel()
radio.sendNumber(level)
})
```
### See also
[receive number](/reference/radio/receive-number), [on data received](/reference/radio/on-data-received)

View File

@ -0,0 +1,39 @@
# Send String
Sends a string to other micro:bits in the area connected by radio.
```sig
radio.sendString("Hello!")
```
### Parameters
* `text` is a [String](/reference/types/string) to send by radio.
### Example: Two-way radio
If you load this program onto two or more micro:bits, you can send a code word from one of them to the others by pressing button `A`.
The other micro:bits will receive the code word and then show it.
```blocks
input.onButtonPressed(Button.A, () => {
radio.sendString("Codeword: TRIMARAN")
basic.showString("SENT");
})
radio.onDataReceived(() => {
basic.showString(radio.receiveString());
});
```
### ~hint
A radio that can both transmit and receive is called a _transceiver_.
### ~
### See also
[receive string](/reference/radio/receive-string), [on data received](/reference/radio/on-data-received)

View File

@ -4,18 +4,6 @@ Sets the group id for ``radio`` communications. A micro:bit can only listen to o
Unless specified, the group id is automatically inferred from the script source. Every script with the same exact source code with start with the same group id.
## Important Security Consideration
The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits.
This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place.
For serious applications, BLE should be considered a substantially more secure alternative.
```sig
radio.setGroup(1)
```
### Parameters
* ``id`` -- a [number](/reference/types/number) between ``0`` and ``255``.

View File

@ -0,0 +1,38 @@
# Set Transmit Power
Sets the transmitter power for ``radio`` communications.
The power can be set to a value between 0 (-30dbm) and 7 (+4dbm).
## Range
At power level 7, in an open area without significant interference (coming from WiFi networks or other devices operating on the 2.4 GHz range), you can get a **range of over 70m**.
Indoors (or with additional interference), range will be significantly reduced.
## Important Security Consideration
The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits.
This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place.
For serious applications, BLE should be considered a substantially more secure alternative.
```sig
radio.setTransmitPower(1)
```
### Parameters
* ``power`` -- a [number](/reference/types/number) between ``0`` and ``7``.
### Example
Sets the transmitter power to full power at 7.
```blocks
radio.setTransmitPower(7)
```
### See also
[receive number](/reference/radio/receive-number), [send number](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)

View File

@ -0,0 +1,45 @@
# Write Value To Serial
Writes the full data received data via ``radio`` to serial in JSON format.
**Note** - This method only works for [send number](/reference/radio/send-number) and [send value](/reference/radio/send-value). It does not work for [send string](/reference/radio/send-string) (although a string can be sent with [send value](/reference/radio/send-value)).
## Data received format
The format for received data printed to serial is as follows
- [send number](/reference/radio/send-number) - ```{v:ValueSent,t:MicrobitTimeAlive,s:Unused}```
- [send value](/reference/radio/send-number) - ```{v:Value,t:MicrobitTimeAlive,s:Unused,n:"Name"}```
- [send string](/reference/radio/send-string) - ```{}``` (currently unavailable)
## Important Security Consideration
The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits.
This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place.
For serious applications, BLE should be considered a substantially more secure alternative.
```sig
radio.writeValueToSerial()
```
### Parameters
* None
### Examples
When ```radio``` data is received (after pressing A button on 2nd micro:bit), output temperature data to serial.
```blocks
input.onButtonPressed(Button.A, () => {
radio.sendNumber(input.temperature());
});
radio.onDataReceived(() => {
radio.writeValueToSerial();
});
```
Example output to serial when A button pressed:
```{v:27,t:323,s:0}```
### See also
[send number](/reference/radio/send-number), [send value](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)

View File

@ -8,4 +8,5 @@ serial.writeNumber(0);
serial.writeValue(x, 0);
serial.writeString("");
serial.readLine();
serial.redirect(SerialPin.P0, SerialPin.P0, BaudRate.BaudRate115200);
```

View File

@ -1,34 +1,34 @@
# Assignment Operator
Set the value for local and global variables.
Use an equals sign to make a [variable](/reference/variables/var) store the [number](/reference/types/number)
or [string](/reference/types/string) you say.
### @parent blocks/operators
When you use the equals sign to store something in a variable, the equals sign is called
an *assignment operator*, and what you store is called a *value*.
Set or change the value of a variable
### Storing numbers in variables
This program makes the variable `item` equal `5` and then shows it on the [LED screen](/device/screen).
````blocks
let item = 0
let item = 5
basic.showNumber(item)
````
Use the assignment operator to set or change the value of a [variable](/reference/variables/var).
### Storing strings in variables
### Declare a variable
Declare a new *local* variable using the [variable](/reference/variables/var) statement and the assignment operator. Like this:
This program makes the variable `name` equal `Joe` and then shows it on the [LED screen](/device/screen).
````blocks
let num1 = 42;
let name = "Joe";
let name = "Joe"
basic.showString(name);
````
The variable's name is on the left of the assignment operator and the variable's value is on the right:
````blocks
let num1 = 42
````
### Notes
* You can use the assignment operator with variables of each of the supported [types](/reference/types).
You can use the assignment operator with variables of
every [type](/reference/types). A *type* is which kind of thing
a variable can store, like a number or string.
### Lessons

Some files were not shown because too many files have changed in this diff Show More