diff --git a/.gitignore b/.gitignore index 961ea959..46028121 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,11 @@ node_modules +yotta_modules +yotta_targets built typings tmp temp -projects +projects/** win10/app/bin win10/app/bld win10/*.opendb diff --git a/README.md b/README.md index 6071ca90..0a1d099b 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,53 @@ # 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) [![Build Status](https://travis-ci.org/Microsoft/pxt-microbit.svg?branch=master)](https://travis-ci.org/Microsoft/pxt-microbit) -# Getting started +## Local server -Please follow instructions at https://github.com/Microsoft/pxt#running-a-target-from-localhost +### Setup + +The following commands are a 1-time setup after synching the repo on your machine. + +* install the PXT command line +``` +npm install -g pxt +``` +* install the dependencies +``` +npm install +``` + +### Running + +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. - -### Sideloading - -* Open Windows **settings** and search for **Developer options** -* Enable the developer mode. -* Find the latest build under ``win10/app/AppPackages/latest`` and run the ``Add-AppDevPackage.ps1`` PowerShell script (mouse right-click, then `run with PowerShell`) +that wraps ``m.pxt.io`` and provides additional features. ### Building diff --git a/cmds/cmds.ts b/cmds/cmds.ts index bb6e4b76..2bfd7e5d 100644 --- a/cmds/cmds.ts +++ b/cmds/cmds.ts @@ -1,8 +1,8 @@ /// -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 = 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) })) diff --git a/cmds/tsconfig.json b/cmds/tsconfig.json index d439cadb..7d57cc95 100644 --- a/cmds/tsconfig.json +++ b/cmds/tsconfig.json @@ -8,6 +8,6 @@ "module": "commonjs", "rootDir": ".", "newLine": "LF", - "sourceMap": true + "sourceMap": false } } diff --git a/docs/about.md b/docs/about.md index f5164ac4..7bf880de 100644 --- a/docs/about.md +++ b/docs/about.md @@ -26,7 +26,7 @@ input.onButtonPressed(Button.B, () => { The [BBC micro:bit](https://www.microbit.co.uk) is a [pocket-size computer](/device) with a 5x5 display of 25 LEDs, Bluetooth and sensors that can be programmed by anyone. The BBC micro:bit was made possible by many [partners](https://www.microbit.co.uk/partners). -The micro:bit provides a fun introduction to programming and making – switch on, program it to do something fun – wear it, customize it. +The micro:bit provides an easy and fun introduction to programming and making – switch on, program it to do something fun – wear it, customize it. Just like Arduino, the micro:bit can be connected to and interact with sensors, displays, and other devices. ## Blocks or JavaScript diff --git a/docs/docs.md b/docs/docs.md index 4cbce65c..78937dc3 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -1,8 +1,35 @@ # Documentation -Welcome to the documentation. +```sim +basic.forever(() => { + basic.showString("DOCS "); +}) +input.onButtonPressed(Button.A, () => { + led.stopAnimation(); + basic.showLeds(` +. . . . . +. # . # . +. . . . . +# . . . # +. # # # .`); +}); +input.onButtonPressed(Button.B, () => { + led.stopAnimation(); + basic.showLeds(` +. # . # . +# . # . # +# . . . # +. # . # . +. . # . .`); +}); +``` +* **[getting started](/getting-started)** * Browse the [API reference](/reference) * Learn more about the [device](/device) * Get started with [lessons](/lessons) -* Learn about [libraries](/libraries) (possibly using C++) +* Follow up with the [release notes](/release-notes) + +### Developers + +* Learn about [packages](/packages) (possibly using C++ or ARM thumb) diff --git a/docs/getting-started.md b/docs/getting-started.md new file mode 100644 index 00000000..e160b0fd --- /dev/null +++ b/docs/getting-started.md @@ -0,0 +1,204 @@ +# Getting started + +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! + +### Show LEDs + +Draw something in the editor with this block. You can draw another +smiley face, or try something else. + +```shuffle +basic.showLeds(` + . . . . . + . # . # . + . . . . . + # . . . # + . # # # . + `) +``` + +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! + +### Show animation forever + +Show one picture after another by snapping blocks together to create an +animation (like a cartoon)! + +```blocks + basic.showLeds(` + . . . . . + . # . # . + . . . . . + # . . . # + . # # # . + `) + basic.showLeds(` + . . . . . + . # . # . + . . . . . + . # # # . + # . . . # + `) +``` + +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! + +### Repeat Forever + +Make an animation that never stops with the ``forever`` block. + +Unscramble these blocks in the editor to make an animation that first +shows a happy face, then an unhappy face, then a happy face, and never +stops. + +```shuffle +basic.forever(() => { + basic.showLeds(` + . . . . . + . # . # . + . . . . . + # . . . # + . # # # . + `) + basic.showLeds(` + . . . . . + . # . # . + . . . . . + . # # # . + # . . . # + `) +}); +``` + +### Your turn! + +You can also change the pictures to make your own animation. +Make your own awesome animation with the ``show leds`` and ``forever`` +blocks. + +#### ~hint + +You can make your animation longer if you use more than two pictures. + +#### ~ + +### Button A and B + +This program will show the word `banana` on the LED +screen when you press button `B`. + +```blocks +input.onButtonPressed(Button.B, () => { + basic.showString("banana"); +}); +``` + +Now try to unscramble these blocks in the editor so that the micro:bit +shows **YES** when you press button `A` and **NO** when when you press +button `B`. All of the blocks under `on button A pressed` or +`on button B pressed` should run when you press that button. + +```shuffle +input.onButtonPressed(Button.A, () => { + basic.showString("YES"); +}); +input.onButtonPressed(Button.B, () => { + basic.showString("NO"); +}); +``` + +### 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 +shakes the micro:bit. + +```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 +oval picture at the top of the board). + +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 the +micro:bit itself! + +```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 +metal bar 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``. + +```shuffle +input.onPinPressed(TouchPin.P0, () => { + basic.showLeds(` +. . . . . +. # . # . +. . . . . +# . . . # +. # # # .`); +}); +``` + +### Your turn! + +Use the screen, buttons, gestures, and pins to make your own fun game +with the BBC micro:bit! diff --git a/docs/lessons.md b/docs/lessons.md index 58790875..9f07af5d 100644 --- a/docs/lessons.md +++ b/docs/lessons.md @@ -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) diff --git a/docs/lessons/answering-machine.md b/docs/lessons/answering-machine.md index 9a520b44..51d47eab 100644 --- a/docs/lessons/answering-machine.md +++ b/docs/lessons/answering-machine.md @@ -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 diff --git a/docs/lessons/answering-machine/activity.md b/docs/lessons/answering-machine/activity.md index a40e1241..b41ea8c0 100644 --- a/docs/lessons/answering-machine/activity.md +++ b/docs/lessons/answering-machine/activity.md @@ -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! diff --git a/docs/lessons/answering-machine/challenges.md b/docs/lessons/answering-machine/challenges.md index 5116e590..0a03be08 100644 --- a/docs/lessons/answering-machine/challenges.md +++ b/docs/lessons/answering-machine/challenges.md @@ -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 diff --git a/docs/lessons/beautiful-image.md b/docs/lessons/beautiful-image.md index 27973d03..8bb450d9 100644 --- a/docs/lessons/beautiful-image.md +++ b/docs/lessons/beautiful-image.md @@ -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 diff --git a/docs/lessons/beautiful-image/activity.md b/docs/lessons/beautiful-image/activity.md index d4d4524a..fcfc0e1a 100644 --- a/docs/lessons/beautiful-image/activity.md +++ b/docs/lessons/beautiful-image/activity.md @@ -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. ### ~ diff --git a/docs/lessons/beautiful-image/challenges.md b/docs/lessons/beautiful-image/challenges.md index 802c8c76..4a4a54b2 100644 --- a/docs/lessons/beautiful-image/challenges.md +++ b/docs/lessons/beautiful-image/challenges.md @@ -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 diff --git a/docs/lessons/blink.md b/docs/lessons/blink.md index 74a96e27..7e4bd017 100644 --- a/docs/lessons/blink.md +++ b/docs/lessons/blink.md @@ -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 diff --git a/docs/lessons/blink/activity.md b/docs/lessons/blink/activity.md index 647bfcef..b9ef94bb 100644 --- a/docs/lessons/blink/activity.md +++ b/docs/lessons/blink/activity.md @@ -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 diff --git a/docs/lessons/blink/challenges.md b/docs/lessons/blink/challenges.md index 3baf3151..63bdb9ec 100644 --- a/docs/lessons/blink/challenges.md +++ b/docs/lessons/blink/challenges.md @@ -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 diff --git a/docs/lessons/catch-the-egg-game.md b/docs/lessons/catch-the-egg-game.md index 079b6df5..1e66afbc 100644 --- a/docs/lessons/catch-the-egg-game.md +++ b/docs/lessons/catch-the-egg-game.md @@ -2,8 +2,6 @@ A game to catch eggs in a basket. -### @video td/videos/catch-the-egg-game-0 - ## Topic Variables diff --git a/docs/lessons/catch-the-egg-game/activity.md b/docs/lessons/catch-the-egg-game/activity.md index e7479558..ea0f7b50 100644 --- a/docs/lessons/catch-the-egg-game/activity.md +++ b/docs/lessons/catch-the-egg-game/activity.md @@ -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 diff --git a/docs/lessons/compass.md b/docs/lessons/compass.md index 2278e2f6..6348e0e6 100644 --- a/docs/lessons/compass.md +++ b/docs/lessons/compass.md @@ -2,8 +2,6 @@ create a die on the BBC micro:bit. -### @video td/videos/compass-0 - ## Topic If (Conditionals) diff --git a/docs/lessons/counter.md b/docs/lessons/counter.md index 18afef28..7721de6a 100644 --- a/docs/lessons/counter.md +++ b/docs/lessons/counter.md @@ -2,8 +2,6 @@ Learn how to create a counter with with on button pressed. -### @video td/videos/counter-0 - ## Topic Variables diff --git a/docs/lessons/counter/activity.md b/docs/lessons/counter/activity.md index 50725090..e3e1d251 100644 --- a/docs/lessons/counter/activity.md +++ b/docs/lessons/counter/activity.md @@ -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! ### ~ diff --git a/docs/lessons/counter/challenges.md b/docs/lessons/counter/challenges.md index 5dc0acab..8d478cb3 100644 --- a/docs/lessons/counter/challenges.md +++ b/docs/lessons/counter/challenges.md @@ -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`. diff --git a/docs/lessons/die-roll.md b/docs/lessons/dice-roll.md similarity index 81% rename from docs/lessons/die-roll.md rename to docs/lessons/dice-roll.md index 622292ea..c0f13b95 100644 --- a/docs/lessons/die-roll.md +++ b/docs/lessons/dice-roll.md @@ -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 diff --git a/docs/lessons/die-roll/activity.md b/docs/lessons/dice-roll/activity.md similarity index 81% rename from docs/lessons/die-roll/activity.md rename to docs/lessons/dice-roll/activity.md index 3f6940fc..51d530fa 100644 --- a/docs/lessons/die-roll/activity.md +++ b/docs/lessons/dice-roll/activity.md @@ -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)! ### ~ diff --git a/docs/lessons/die-roll/challenges.md b/docs/lessons/dice-roll/challenges.md similarity index 86% rename from docs/lessons/die-roll/challenges.md rename to docs/lessons/dice-roll/challenges.md index 8e29ba66..1a3d0bbd 100644 --- a/docs/lessons/die-roll/challenges.md +++ b/docs/lessons/dice-roll/challenges.md @@ -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, () => { diff --git a/docs/lessons/die-roll/quiz-answers.md b/docs/lessons/dice-roll/quiz-answers.md similarity index 93% rename from docs/lessons/die-roll/quiz-answers.md rename to docs/lessons/dice-roll/quiz-answers.md index 758359dc..fa87d611 100644 --- a/docs/lessons/die-roll/quiz-answers.md +++ b/docs/lessons/dice-roll/quiz-answers.md @@ -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. diff --git a/docs/lessons/die-roll/quiz.md b/docs/lessons/dice-roll/quiz.md similarity index 84% rename from docs/lessons/die-roll/quiz.md rename to docs/lessons/dice-roll/quiz.md index bf796902..b4afaf28 100644 --- a/docs/lessons/die-roll/quiz.md +++ b/docs/lessons/dice-roll/quiz.md @@ -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! diff --git a/docs/lessons/digi-yoyo.md b/docs/lessons/digi-yoyo.md index 7a4ecb80..06643f82 100644 --- a/docs/lessons/digi-yoyo.md +++ b/docs/lessons/digi-yoyo.md @@ -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 diff --git a/docs/lessons/digi-yoyo/activity.md b/docs/lessons/digi-yoyo/activity.md index 86ad9043..c65c3a2a 100644 --- a/docs/lessons/digi-yoyo/activity.md +++ b/docs/lessons/digi-yoyo/activity.md @@ -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! ### ~ diff --git a/docs/lessons/digi-yoyo/challenges.md b/docs/lessons/digi-yoyo/challenges.md index 4665babf..78fc8674 100644 --- a/docs/lessons/digi-yoyo/challenges.md +++ b/docs/lessons/digi-yoyo/challenges.md @@ -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`! diff --git a/docs/lessons/flashing-heart.md b/docs/lessons/flashing-heart.md index eb711aae..6ca3c7e8 100644 --- a/docs/lessons/flashing-heart.md +++ b/docs/lessons/flashing-heart.md @@ -2,8 +2,6 @@ Learn how to create LED images with a global variable. -### @video td/videos/flashing-heart-0 - ## Topic Pause diff --git a/docs/lessons/flashing-heart/activity.md b/docs/lessons/flashing-heart/activity.md index c9c866e8..c1481c8b 100644 --- a/docs/lessons/flashing-heart/activity.md +++ b/docs/lessons/flashing-heart/activity.md @@ -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. ### ~ diff --git a/docs/lessons/flashing-heart/challenges.md b/docs/lessons/flashing-heart/challenges.md index dab0bc4d..fdbdab21 100644 --- a/docs/lessons/flashing-heart/challenges.md +++ b/docs/lessons/flashing-heart/challenges.md @@ -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. diff --git a/docs/lessons/game-counter.md b/docs/lessons/game-counter.md index 29ea361a..04f6939d 100644 --- a/docs/lessons/game-counter.md +++ b/docs/lessons/game-counter.md @@ -2,8 +2,6 @@ Learn how to create a counter with with on button pressed. -### @video td/videos/counter-0 - ## Topic Game Library diff --git a/docs/lessons/game-counter/activity.md b/docs/lessons/game-counter/activity.md index 49305571..0c44cef8 100644 --- a/docs/lessons/game-counter/activity.md +++ b/docs/lessons/game-counter/activity.md @@ -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`. diff --git a/docs/lessons/game-counter/challenges.md b/docs/lessons/game-counter/challenges.md index b472721d..25786cf4 100644 --- a/docs/lessons/game-counter/challenges.md +++ b/docs/lessons/game-counter/challenges.md @@ -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`. diff --git a/docs/lessons/guess-the-number.md b/docs/lessons/guess-the-number.md index 7b825d5a..37beeb7a 100644 --- a/docs/lessons/guess-the-number.md +++ b/docs/lessons/guess-the-number.md @@ -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 diff --git a/docs/lessons/guess-the-number/activity.md b/docs/lessons/guess-the-number/activity.md index d6846948..f6569481 100644 --- a/docs/lessons/guess-the-number/activity.md +++ b/docs/lessons/guess-the-number/activity.md @@ -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! ### ~ diff --git a/docs/lessons/guess-the-number/challenges.md b/docs/lessons/guess-the-number/challenges.md index 3c6ec6af..8f466d53 100644 --- a/docs/lessons/guess-the-number/challenges.md +++ b/docs/lessons/guess-the-number/challenges.md @@ -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 diff --git a/docs/lessons/guess-the-number/tutorial.md b/docs/lessons/guess-the-number/tutorial.md index 3994e00d..b9202c81 100644 --- a/docs/lessons/guess-the-number/tutorial.md +++ b/docs/lessons/guess-the-number/tutorial.md @@ -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! ### ~ diff --git a/docs/lessons/looper.md b/docs/lessons/looper.md index 95ae0284..6785a183 100644 --- a/docs/lessons/looper.md +++ b/docs/lessons/looper.md @@ -2,8 +2,6 @@ Learn to control blinking LEDs. -### @video td/videos/looper-0 - ## Topic For Loop diff --git a/docs/lessons/looper/activity.md b/docs/lessons/looper/activity.md index eb973f8f..47bc47d6 100644 --- a/docs/lessons/looper/activity.md +++ b/docs/lessons/looper/activity.md @@ -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`. diff --git a/docs/lessons/looper/challenges.md b/docs/lessons/looper/challenges.md index 7559e2d9..5bf0c3e0 100644 --- a/docs/lessons/looper/challenges.md +++ b/docs/lessons/looper/challenges.md @@ -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 diff --git a/docs/lessons/love-meter.md b/docs/lessons/love-meter.md index c24a770d..822b4205 100644 --- a/docs/lessons/love-meter.md +++ b/docs/lessons/love-meter.md @@ -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 diff --git a/docs/lessons/love-meter/activity.md b/docs/lessons/love-meter/activity.md index b6704b21..687592a7 100644 --- a/docs/lessons/love-meter/activity.md +++ b/docs/lessons/love-meter/activity.md @@ -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! ### ~ diff --git a/docs/lessons/love-meter/challenges.md b/docs/lessons/love-meter/challenges.md index f2a4d7c0..ed3b3b73 100644 --- a/docs/lessons/love-meter/challenges.md +++ b/docs/lessons/love-meter/challenges.md @@ -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 diff --git a/docs/lessons/lucky-7.md b/docs/lessons/lucky-7.md index 83074c6c..b670450e 100644 --- a/docs/lessons/lucky-7.md +++ b/docs/lessons/lucky-7.md @@ -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 diff --git a/docs/lessons/lucky-7/activity.md b/docs/lessons/lucky-7/activity.md index f172296e..373f7c25 100644 --- a/docs/lessons/lucky-7/activity.md +++ b/docs/lessons/lucky-7/activity.md @@ -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. ### ~ diff --git a/docs/lessons/lucky-7/challenges.md b/docs/lessons/lucky-7/challenges.md index 2393c025..5c02261e 100644 --- a/docs/lessons/lucky-7/challenges.md +++ b/docs/lessons/lucky-7/challenges.md @@ -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 diff --git a/docs/lessons/magic-logo.md b/docs/lessons/magic-logo.md index 9100e302..999bd90a 100644 --- a/docs/lessons/magic-logo.md +++ b/docs/lessons/magic-logo.md @@ -2,7 +2,7 @@ show an image that points up when the logo is up. -### @video td/videos/magic-logo-0 + ## Topic diff --git a/docs/lessons/magic-logo/activity.md b/docs/lessons/magic-logo/activity.md index 005745f3..6a0da659 100644 --- a/docs/lessons/magic-logo/activity.md +++ b/docs/lessons/magic-logo/activity.md @@ -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. ### ~ diff --git a/docs/lessons/magic-logo/challenges.md b/docs/lessons/magic-logo/challenges.md index dff322f0..131f0726 100644 --- a/docs/lessons/magic-logo/challenges.md +++ b/docs/lessons/magic-logo/challenges.md @@ -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(` diff --git a/docs/lessons/night-light.md b/docs/lessons/night-light.md index 556cb205..9ee37f63 100644 --- a/docs/lessons/night-light.md +++ b/docs/lessons/night-light.md @@ -2,8 +2,6 @@ change the brightness of the BBC micro:bit. -### @video td/videos/night-light-0 - ## Topic Set Brightness diff --git a/docs/lessons/night-light/activity.md b/docs/lessons/night-light/activity.md index 30f049ae..96422b32 100644 --- a/docs/lessons/night-light/activity.md +++ b/docs/lessons/night-light/activity.md @@ -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! ### ~ diff --git a/docs/lessons/night-light/challenges.md b/docs/lessons/night-light/challenges.md index 3187a914..c12fbe86 100644 --- a/docs/lessons/night-light/challenges.md +++ b/docs/lessons/night-light/challenges.md @@ -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. diff --git a/docs/lessons/night-light/offset-image/activity.md b/docs/lessons/night-light/offset-image/activity.md index 32a04179..de48f831 100644 --- a/docs/lessons/night-light/offset-image/activity.md +++ b/docs/lessons/night-light/offset-image/activity.md @@ -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. diff --git a/docs/lessons/rock-paper-scissors.md b/docs/lessons/rock-paper-scissors.md index c3f8e03f..97ba0239 100644 --- a/docs/lessons/rock-paper-scissors.md +++ b/docs/lessons/rock-paper-scissors.md @@ -2,7 +2,7 @@ a game against the BBC micro:bit. -### @video td/videos/rock-paper-scissors-0 + ## Topic diff --git a/docs/lessons/rock-paper-scissors/activity.md b/docs/lessons/rock-paper-scissors/activity.md index 6e22c58e..d73ebe18 100644 --- a/docs/lessons/rock-paper-scissors/activity.md +++ b/docs/lessons/rock-paper-scissors/activity.md @@ -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! diff --git a/docs/lessons/rotation-animation/challenges.md b/docs/lessons/rotation-animation/challenges.md index 7a8eec24..5f6eab4e 100644 --- a/docs/lessons/rotation-animation/challenges.md +++ b/docs/lessons/rotation-animation/challenges.md @@ -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. diff --git a/docs/lessons/screen-wipe.md b/docs/lessons/screen-wipe.md index 7e847bcc..02905d16 100644 --- a/docs/lessons/screen-wipe.md +++ b/docs/lessons/screen-wipe.md @@ -2,7 +2,7 @@ clear the screen by pressing button "A". -### @video td/videos/screen-wipe-0 + ## Topic diff --git a/docs/lessons/screen-wipe/activity.md b/docs/lessons/screen-wipe/activity.md index 9eea22ee..28a53a73 100644 --- a/docs/lessons/screen-wipe/activity.md +++ b/docs/lessons/screen-wipe/activity.md @@ -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. diff --git a/docs/lessons/screen-wipe/challenges.md b/docs/lessons/screen-wipe/challenges.md index b4ea48cb..756e67d2 100644 --- a/docs/lessons/screen-wipe/challenges.md +++ b/docs/lessons/screen-wipe/challenges.md @@ -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. diff --git a/docs/lessons/smiley.md b/docs/lessons/smiley.md index 981f322a..f5b611b2 100644 --- a/docs/lessons/smiley.md +++ b/docs/lessons/smiley.md @@ -2,7 +2,7 @@ design a blinking image lesson #docs -### @video td/videos/smiley-0 + ## Topic diff --git a/docs/lessons/smiley/activity.md b/docs/lessons/smiley/activity.md index c1c43e7b..72db85eb 100644 --- a/docs/lessons/smiley/activity.md +++ b/docs/lessons/smiley/activity.md @@ -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! diff --git a/docs/lessons/smiley/challenges.md b/docs/lessons/smiley/challenges.md index 37e0db18..9caf3479 100644 --- a/docs/lessons/smiley/challenges.md +++ b/docs/lessons/smiley/challenges.md @@ -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. diff --git a/docs/lessons/snowflake-fall.md b/docs/lessons/snowflake-fall.md index c25c7d59..07969418 100644 --- a/docs/lessons/snowflake-fall.md +++ b/docs/lessons/snowflake-fall.md @@ -2,7 +2,7 @@ design a blinking rectangle animation. -### @video td/videos/snowflake-fall-0 + ## Topic diff --git a/docs/lessons/snowflake-fall/activity.md b/docs/lessons/snowflake-fall/activity.md index bee88370..f5cbc842 100644 --- a/docs/lessons/snowflake-fall/activity.md +++ b/docs/lessons/snowflake-fall/activity.md @@ -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! diff --git a/docs/lessons/snowflake-fall/challenges.md b/docs/lessons/snowflake-fall/challenges.md index 99d3efe3..833e1a18 100644 --- a/docs/lessons/snowflake-fall/challenges.md +++ b/docs/lessons/snowflake-fall/challenges.md @@ -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. diff --git a/docs/lessons/speed-button.md b/docs/lessons/speed-button.md index 638c09bb..c3304b83 100644 --- a/docs/lessons/speed-button.md +++ b/docs/lessons/speed-button.md @@ -2,7 +2,7 @@ code a speed game by declaring Booleans on the BBC micro:bit. -### @video td/videos/speed-button-3 + ## Topic diff --git a/docs/lessons/speed-button/activity.md b/docs/lessons/speed-button/activity.md index 8d87d6f5..810f20f7 100644 --- a/docs/lessons/speed-button/activity.md +++ b/docs/lessons/speed-button/activity.md @@ -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. diff --git a/docs/lessons/spinner.md b/docs/lessons/spinner.md index 528d85ee..0ded84bc 100644 --- a/docs/lessons/spinner.md +++ b/docs/lessons/spinner.md @@ -2,7 +2,7 @@ a spin the BBC micro:bit game with the input on shake. -### @video td/videos/spinner-0 + ## Topic diff --git a/docs/lessons/spinner/activity.md b/docs/lessons/spinner/activity.md index 7626c77c..425612e4 100644 --- a/docs/lessons/spinner/activity.md +++ b/docs/lessons/spinner/activity.md @@ -4,7 +4,7 @@ Create an arrow that randomly points to a player. ### ~avatar avatar -### @video td/videos/spinner-0 + ### ~ diff --git a/docs/lessons/strobe-light.md b/docs/lessons/strobe-light.md index 04e8e35a..117d7182 100644 --- a/docs/lessons/strobe-light.md +++ b/docs/lessons/strobe-light.md @@ -2,7 +2,7 @@ Learn how to create a blinking LED script. -### @video td/videos/strobe-light-0 + ## Topic diff --git a/docs/lessons/strobe-light/activity.md b/docs/lessons/strobe-light/activity.md index 27f3e52e..2d70ba92 100644 --- a/docs/lessons/strobe-light/activity.md +++ b/docs/lessons/strobe-light/activity.md @@ -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! diff --git a/docs/lessons/strobe-light/challenges.md b/docs/lessons/strobe-light/challenges.md index 3afd932a..75d77a32 100644 --- a/docs/lessons/strobe-light/challenges.md +++ b/docs/lessons/strobe-light/challenges.md @@ -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. diff --git a/docs/lessons/teach.md b/docs/lessons/teach.md index 6cf87ed7..6b9d24ba 100644 --- a/docs/lessons/teach.md +++ b/docs/lessons/teach.md @@ -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 diff --git a/docs/lessons/truth-or-dare.md b/docs/lessons/truth-or-dare.md index 88f728ea..25899676 100644 --- a/docs/lessons/truth-or-dare.md +++ b/docs/lessons/truth-or-dare.md @@ -2,7 +2,7 @@ create a love meter with the BBC micro:bit. -### @video td/videos/truth-or-dare-0 + ## Topic diff --git a/docs/lessons/truth-or-dare/activity.md b/docs/lessons/truth-or-dare/activity.md index 09b9bfb6..fba91d63 100644 --- a/docs/lessons/truth-or-dare/activity.md +++ b/docs/lessons/truth-or-dare/activity.md @@ -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! diff --git a/docs/lessons/truth-or-dare/tutorial.md b/docs/lessons/truth-or-dare/tutorial.md index ad2d993f..d58ea784 100644 --- a/docs/lessons/truth-or-dare/tutorial.md +++ b/docs/lessons/truth-or-dare/tutorial.md @@ -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" diff --git a/docs/lessons/zoomer.md b/docs/lessons/zoomer.md index 3c592b37..a839b6a6 100644 --- a/docs/lessons/zoomer.md +++ b/docs/lessons/zoomer.md @@ -2,7 +2,7 @@ measure the acceleration on the micro:bit in the "z" direction. -### @video td/videos/zoomer-0 + ## Topic diff --git a/docs/lessons/zoomer/activity.md b/docs/lessons/zoomer/activity.md index ddfb663e..ad595a38 100644 --- a/docs/lessons/zoomer/activity.md +++ b/docs/lessons/zoomer/activity.md @@ -4,7 +4,7 @@ Measure the acceleration on the micro:bit in the "z" direction. ### ~avatar avatar -### @video td/videos/zoomer-0 + ### ~ diff --git a/docs/lessons/zoomer/challenges.md b/docs/lessons/zoomer/challenges.md index 6698ffb4..aa07bd0a 100644 --- a/docs/lessons/zoomer/challenges.md +++ b/docs/lessons/zoomer/challenges.md @@ -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. diff --git a/docs/libraries.md b/docs/libraries.md deleted file mode 100644 index 7738fecd..00000000 --- a/docs/libraries.md +++ /dev/null @@ -1,14 +0,0 @@ -# Extensions - -You can publish libraries (also known as packages or extensions) -that users can then add to their scripts. These typically -provide a driver for a particular hardware device you can connect -to a microbit. - -* [Sample C++ extension](https://github.com/Microsoft/pxt-microbit-cppsample) -* [Sample TypeScript extension](https://github.com/Microsoft/pxt-microbit/tree/master/libs/i2c-fram) - -## Finding libraries - -## Publishing libraries - diff --git a/docs/microbit-reference.md b/docs/microbit-reference.md deleted file mode 100644 index 2feeb623..00000000 --- a/docs/microbit-reference.md +++ /dev/null @@ -1,23 +0,0 @@ -# microbit Reference - -```namespaces -basic.showNumber(0); -input.onButtonPressed(Button.A, () => { - -}); -led.plot(0, 0); -music.playTone(0, 0); -game.addScore(1); -images.createImage(` -. . . . . -. . . . . -. . # . . -. . . . . -. . . . . -`); -pins.digitalReadPin(DigitalPin.P0); -serial.writeValue(x, 0); -control.inBackground(() => { - -}); -``` diff --git a/docs/open-source.md b/docs/open-source.md new file mode 100644 index 00000000..62868f47 --- /dev/null +++ b/docs/open-source.md @@ -0,0 +1,9 @@ +# Open Source + +The editor is open source on GitHub under the MIT license. Contributions are welcome, please check our GitHub repos. + +### Repos + +* [microbit/pxt](https://github.com/Microsoft/pxt), programming experience toolkit (PXT) +* [microsoft/pxt-microbit](https://github.com/Microsoft/pxt-microbit), PXT target for BBC micro:bit +* [microsoft/pxt-microbit-core](https://github.com/Microsoft/pxt-microbit-core), Yotta module used to build the BBC micro:bit runtime diff --git a/docs/packages.md b/docs/packages.md new file mode 100644 index 00000000..f1521f8e --- /dev/null +++ b/docs/packages.md @@ -0,0 +1,48 @@ +# Extensions + +You can publish libraries (also known as packages or extensions) +that users can then add to their scripts. These typically +provide a driver for a particular hardware device you can connect +to a microbit. + +* [Sample C++ extension](https://github.com/Microsoft/pxt-microbit-cppsample) +* [Sample TypeScript extension](https://github.com/Microsoft/pxt-microbit/tree/master/libs/i2c-fram) + +## 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 +``` diff --git a/docs/projects.md b/docs/projects.md new file mode 100644 index 00000000..8343f52a --- /dev/null +++ b/docs/projects.md @@ -0,0 +1,15 @@ +# Projects + + +### @short Projects + +### ~column + +## Beginner + +* [Rock Paper Scissors](/projects/rock-paper-scissors) + +### ~ + +### ~column + diff --git a/docs/projects/a1-display.md b/docs/projects/a1-display.md new file mode 100644 index 00000000..67c37c08 --- /dev/null +++ b/docs/projects/a1-display.md @@ -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(); +``` \ No newline at end of file diff --git a/docs/projects/rock-paper-scissors.md b/docs/projects/rock-paper-scissors.md new file mode 100644 index 00000000..df597ee4 --- /dev/null +++ b/docs/projects/rock-paper-scissors.md @@ -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)? diff --git a/docs/reference.md b/docs/reference.md index 669ddf45..dfe1acaf 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -9,8 +9,9 @@ basic.showNumber(0); input.onButtonPressed(Button.A, () => { }); -led.plot(0, 0); music.playTone(0, 0); +led.plot(0, 0); +radio.sendNumber(0); game.addScore(1); images.createImage(` . . . . . diff --git a/docs/reference/String.md b/docs/reference/String.md new file mode 100644 index 00000000..2e875b5f --- /dev/null +++ b/docs/reference/String.md @@ -0,0 +1,5 @@ +# String + +```cards +String.fromCharCode(0); +``` diff --git a/docs/reference/basic/clear-screen.md b/docs/reference/basic/clear-screen.md index 0d03227c..eed059e8 100644 --- a/docs/reference/basic/clear-screen.md +++ b/docs/reference/basic/clear-screen.md @@ -8,7 +8,7 @@ basic.clearScreen() ### Example: vanishing heart -The following code displays a heart on the screen and then turns off all the LED lights using `clear screen`: +The following code shows a heart on the screen and then turns off all the LED lights using `clear screen`: ```blocks basic.showLeds(` diff --git a/docs/reference/basic/forever.md b/docs/reference/basic/forever.md index 9b4a0a24..c666badc 100644 --- a/docs/reference/basic/forever.md +++ b/docs/reference/basic/forever.md @@ -1,6 +1,7 @@ # Forever -Repeat code [in the background](/reference/control/in-background) forever. +Keep running part of a program +[in the background](/reference/control/in-background). ```sig basic.forever(() => { @@ -9,7 +10,9 @@ basic.forever(() => { ### Example: compass -The following example constantly checks the [compass heading](/reference/input/compass-heading) and updates the screen with the direction. +The following example constantly checks the +[compass heading](/reference/input/compass-heading) +and updates the screen with the direction. ```blocks basic.forever(() => { @@ -30,7 +33,9 @@ basic.forever(() => { ### Example: counter -The following example continually shows the current value of a global variable: +The following example keeps showing the [number](/reference/types/number) stored in a global variable. +When you press button `A`, the number gets bigger. +You can use a program like this to count things with your BBC micro:bit. ```blocks let num = 0 @@ -42,9 +47,12 @@ input.onButtonPressed(Button.A, () => { }) ``` -### Contention for the LED display +### Competing for the LED screen -If you have multiple processes that each show something on the LED screen, you may get unexpected results. Try, for example: +If different parts of a program are each trying +to show something on the LED screen at the same time, +you may get unexpected results. +Try this on your micro:bit: ```blocks basic.forever(() => { diff --git a/docs/reference/basic/pause.md b/docs/reference/basic/pause.md index 776be176..a6bb0d10 100644 --- a/docs/reference/basic/pause.md +++ b/docs/reference/basic/pause.md @@ -1,6 +1,7 @@ # Pause -Pause program execution for the specified number of milliseconds. This function is helpful when you need to slow down your program's execution. +Pause the program for the number of milliseconds you say. +You can use this function to slow your program down. ```sig basic.pause(400) @@ -8,11 +9,13 @@ basic.pause(400) ### Parameters -* ``ms`` - the number of milliseconds that you want to pause (100 = 1/10 second, 1000 milliseconds = 1 second) +* ``ms`` is the number of milliseconds that you want to pause (100 milliseconds = 1/10 second, and 1000 milliseconds = 1 second). ### Example: diagonal line -The following example code turns on LED `0, 0` thru `4, 4`, pausing 500 milliseconds after each LED. Without `pause`, the code would run so fast that you wouldn't see each individual LED turning on. +This example draws a diagonal line by turning on LED `0, 0` (top left) through LED `4, 4` (bottom right). +The program pauses 500 milliseconds after turning on each LED. +Without `pause`, the program would run so fast that you would not have time to see each LED turning on. ```blocks for (let i = 0; i < 5; i++) { diff --git a/docs/reference/basic/show-animation.md b/docs/reference/basic/show-animation.md index 2b7bef83..3a099c7d 100644 --- a/docs/reference/basic/show-animation.md +++ b/docs/reference/basic/show-animation.md @@ -1,6 +1,6 @@ # Show Animation -Show a series of image frames on the [LED screen](/device/screen), pausing the specified time after each frame. +Show a group of image frames (pictures) one after another on the [LED screen](/device/screen). It pauses the amount of time you tell it after each frame. ```sig basic.showAnimation(` @@ -14,10 +14,14 @@ basic.showAnimation(` ### Parameters -* `leds` - [String](/reference/types/string); a series of LED on/off states -* `interval` - [Number](/reference/types/number); the number of milliseconds to pause after each image frame +* `leds` is a [String](/reference/types/string) that shows which LEDs are on and off, in groups one after another. +* `interval` is an optional [Number](/reference/types/number). It means the number of milliseconds to pause after each image frame. -### Show a series of image frames +### Example: Animating a group of image frames + +In this animation, each row is 15 spaces wide because +there are three frames in the animation, and each frame is +five spaces wide, just like the screen on the BBC micro:bit. ``` basic.showAnimation(` @@ -31,13 +35,17 @@ basic.showAnimation(` ### ~hint -If the series of images appear too fast, increase the value of the *interval* parameter. +If the animation is too fast, make `interval` bigger. ### ~ -### Example: animating frames +### Example: animating frames with a pause -The following example creates an image with six frames and then shows each frame o the screen, pausing 500 milliseconds after each frame: +This example shows six frames on the screen, pausing 500 milliseconds after each frame. + +In this animation, each row is 30 spaces wide because +there are six frames in the animation, and each frame is +five spaces wide, just like the screen. ``` basic.showAnimation(` @@ -51,7 +59,7 @@ basic.showAnimation(` ### ~hint -Use [forever](/reference/basic/forever) to continually repeat an animation +Use [forever](/reference/basic/forever) to show an animation over and over. ### ~ diff --git a/docs/reference/basic/show-leds.md b/docs/reference/basic/show-leds.md index 45a6d057..e5419057 100644 --- a/docs/reference/basic/show-leds.md +++ b/docs/reference/basic/show-leds.md @@ -15,12 +15,13 @@ basic.showLeds(` ### Parameters -* ``leds`` - a series of LED on/off states that form an image (see steps below) -* (optional) ``ms`` - [Number](/reference/types/number) - time to wait after displaying image. In blocks, ``ms`` is 400 by default. +* `leds` is a [String](/reference/types/string) that shows which LEDs are on and off. +* `ms` is an optional [Number](/reference/types/number) that shows how many milliseconds to wait after showing a picture. +If you are programming with blocks, `ms` starts out as 400 milliseconds. -### Example - Block Editor +### Example -1. Open the `basic` category and select the `show leds` blocks. +Open the `basic` card in the Block Editor and select the `show leds` blocks. ```blocks basic.showLeds(` @@ -33,7 +34,7 @@ basic.showLeds(` ) ``` -In JavaScript, the led off is represented by a `.` and the led on by a `#` character. +If you are programming in JavaScript, `#` means an LED that is turned on and `.` means an LED that is turned off. ### Lessons diff --git a/docs/reference/basic/show-number.md b/docs/reference/basic/show-number.md index 16cc8c6f..68b18bab 100644 --- a/docs/reference/basic/show-number.md +++ b/docs/reference/basic/show-number.md @@ -1,6 +1,6 @@ # Show Number -Show a number on the [LED screen](/device/screen), one digit at a time (scrolling from left to right) +Show a number on the [LED screen](/device/screen). It will slide left if it has more than one digit. ~~~~sig basic.showNumber(2, 150) @@ -8,18 +8,18 @@ basic.showNumber(2, 150) ### Parameters -* value - a [Number](/reference/types/number) -* (optional) interval (ms) - [Number](/reference/types/number); the time (in milliseconds) before scrolling by one LED; the larger the number, the slower the scroll +* `value` is a [Number](/reference/types/number). +* `interval` is an optional [Number](/reference/types/number). It means the number of milliseconds before sliding the `value` left by one LED each time. Bigger intervals make the sliding slower. -### ~ +### Examples: -To display the number 10: +To show the number 10: ~~~~blocks basic.showNumber(10) ~~~~ -To display the number stored in the `x` variable: +To show the number stored in a variable: ~~~~blocks let x = 1 @@ -28,19 +28,19 @@ basic.showNumber(x) ### Example: count to 5 -This example uses a [for](/reference/loops/for) loop to show numbers ``1`` through ``5`` on the screen: +This example uses a [for](/reference/loops/for) loop to show numbers ``0`` through ``5`` on the screen: ~~~~blocks -for (let i = 0; i < 5; i++) { - basic.showNumber(i + 1) +for (let i = 0; i < 6; i++) { + basic.showNumber(i) basic.pause(200) } ~~~~ ### Other show functions -* use [show string](/reference/basic/show-string) to show a string on the screen -* use [show animation](/reference/basic/show-animation) to show a series of images on the screen +* Use [show string](/reference/basic/show-string) to show a [String](/reference/types/string) with letters on the screen. +* Use [show animation](/reference/basic/show-animation) to show a group of pictures on the screen, one after another. ### Lessons diff --git a/docs/reference/basic/show-string.md b/docs/reference/basic/show-string.md index c8ef05a5..74427656 100644 --- a/docs/reference/basic/show-string.md +++ b/docs/reference/basic/show-string.md @@ -1,6 +1,6 @@ # Show String -Show a string on the [LED screen](/device/screen) one character at a time (scrolling from left to right). +Show a number on the [LED screen](/device/screen). It will slide left if it is bigger than the screen. ```sig basic.showString("Hello!") @@ -8,18 +8,18 @@ basic.showString("Hello!") ### Parameters -* `text` - a [String](/reference/types/string) -* (optional) `ms` - [Number](/reference/types/number); the time (in milliseconds) before scrolling left by one LED; the larger the number, the slower the scroll +* `text` is a [String](/reference/types/string). It can contain letters, numbers, and punctuation. +* `ms` is an optional [Number](/reference/types/number). It means the number of milliseconds before sliding the [String](/reference/types/string) left by one LED each time. Bigger intervals make the sliding slower. ### Examples: -To display Hello: +To show the word **Hello**: ```blocks basic.showString("Hello") ``` -To display the content of a string variable: +To show what is stored in a [String](/reference/types/string) variable: ```blocks let s = "Hi" @@ -28,8 +28,8 @@ basic.showString(s) ### Other show functions -* use [show number](/reference/basic/show-number) to show a number on the screen -* use [show animation](/reference/basic/show-animation) to show a series of images on the screen +* Use [show number](/reference/basic/show-number) to show a number on the [LED screen](/device/screen). +* Use [show animation](/reference/basic/show-animation) to show a group of pictures on the screen, one after another. ### Lessons diff --git a/docs/reference/input/button-is-pressed.md b/docs/reference/input/button-is-pressed.md index 6bb974cf..0f8e073e 100644 --- a/docs/reference/input/button-is-pressed.md +++ b/docs/reference/input/button-is-pressed.md @@ -1,6 +1,6 @@ # Button Is Pressed -Get the state of an input button. The micro:bit has two input buttons: A and B. +Check whether a button is pressed right now. The micro:bit has two buttons: button `A` and button `B`. ```sig input.buttonIsPressed(Button.A); @@ -8,24 +8,26 @@ input.buttonIsPressed(Button.A); ### Parameters -* name - [String](/reference/types/string); input button "A", "B", or "A+B" (both input buttons) +* ``name`` is a [String](/reference/types/string). You should store `A` in it to check the left button, `B` to check the right button, or `A+B` to check both at the same time. ### Returns -* [Boolean](/reference/types/boolean) - `true` if pressed, `false` if not pressed +* [Boolean](/reference/types/boolean) that is `true` if the button you are checking is pressed, `false` if it is not pressed. ### Example -The following code uses an [if](/reference/logic/if) statement to run code, depending on whether or not the A button is pressed: +This program uses an [if](/reference/logic/if) to run +one part of the program if the `A` button is pressed, and +another part if it is not pressed. ```blocks basic.forever(() => { let pressed = input.buttonIsPressed(Button.A) if (pressed) { - // this code runs if the A button is pressed + // this part runs if the A button is pressed basic.showNumber(1, 150) } else { - // this code runs if the A button is *not* pressed + // this part runs if the A button is *not* pressed basic.showNumber(0, 150) } }) diff --git a/docs/reference/input/light-level.md b/docs/reference/input/light-level.md index 2b847283..a45ef8d0 100644 --- a/docs/reference/input/light-level.md +++ b/docs/reference/input/light-level.md @@ -1,8 +1,14 @@ # Light Level -Gets the light level from ``0`` (dark) to ``255`` (bright). The light is measured by using various LEDs from the screen. +Find the light level (how bright or dark it is) where you are. +The light level ``0`` means darkness and ``255`` means bright light. +The BBC micro:bit measures the light around it by using some of the +LEDs on the [LED screen](/device/screen). -This function will return ``0`` on the first call to this method, a light reading will be available after the display has activated the light sensor for the first time. +The first time you use it, this function will say ``0``. +After that, it will say the real light level. +This is because the light sensor (the part that can find the light level) +has to be turned on first. ```sig input.lightLevel(); @@ -10,11 +16,26 @@ input.lightLevel(); ### Returns -* [Number](/reference/types/number) - light level from ``0`` (dark) to ``255`` (bright). +* a [Number](/reference/types/number) that means a light level from ``0`` (dark) to ``255`` (bright). + +### Example: show light level + +When you press button `B` on the microbit, this +program shows the light level +on the [LED screen](/device/screen). + +```blocks +input.onButtonPressed(Button.B, () => { + let level = input.lightLevel() + basic.showNumber(level) +}) +``` ### Example: chart light level -Use `plot bar chart` to visual the influence of various light source on the light level. +This program shows the light level with a [bar chart](/reference/led/plot-bar-graph) on the micro:bit screen. +If you carry the micro:bit around to different places with different light levels, +the bar chart will change. ```blocks basic.forever(() => { diff --git a/docs/reference/input/on-button-pressed.md b/docs/reference/input/on-button-pressed.md index 8d262566..6fbf7583 100644 --- a/docs/reference/input/on-button-pressed.md +++ b/docs/reference/input/on-button-pressed.md @@ -1,6 +1,9 @@ # On Button Pressed -Register an [event handler](/reference/event-handler) that will execute whenever an input button (A, B, or A and B together) is pressed during program execution. When [running code](/device/simulator) with this function in a web browser, click an on-screen input button - labelled A or B. +Start an [event handler](/reference/event-handler) (part of the program that will run when something happens, like when a button is pressed). +This handler works when button `A` or `B` is pressed, or `A` and `B` together. +When you are using this function in a web browser, click the buttons on the screen instead of the ones +on the BBC micro:bit. ```sig input.onButtonPressed(Button.A, () => {}) @@ -8,7 +11,8 @@ input.onButtonPressed(Button.A, () => {}) ### Example: count button clicks -This example counts how many times the left or right input button is pressed. Each time a button is pressed, the global count variable is increased by 1 and displayed on the screen. +This example counts how many times you press the `A` button. +Each time you press the button, the [LED screen](/device/screen) shows the `count` variable getting bigger. ```blocks let count = 0 @@ -19,22 +23,29 @@ input.onButtonPressed(Button.A, () => { }) ``` -### Example: roll a dice +### Example: roll dice -This example generates a random number when you press the B input button, and then displays a random die image: +This example shows a number from 1 to 6 when you press the `B` button. ```blocks input.onButtonPressed(Button.B, () => { - let dice = Math.random(6) + let dice = Math.random(6) + 1 basic.showNumber(dice) }) ``` +### ~hint + +This program adds a `1` to `random(6)` so the numbers on the dice will come out right. +Otherwise, sometimes they would show a `0`. + +### ~ + ### Lessons [smiley](/lessons/smiley), [answering machine](/lessons/answering-machine), [screen wipe](/lessons/screen-wipe), [rotation animation](/lessons/rotation-animation) ### See also -[button is pressed](/reference/input/button-is-pressed), [forever](/reference/basic/forever) +[button is pressed](/reference/input/button-is-pressed), [forever](/reference/basic/forever), [random](/reference/math/math) diff --git a/docs/reference/input/running-time.md b/docs/reference/input/running-time.md index 282b7946..df0651b8 100644 --- a/docs/reference/input/running-time.md +++ b/docs/reference/input/running-time.md @@ -1,6 +1,6 @@ # Running Time -Get the number of milliseconds elapsed since the script began. 1,000 milliseconds = 1 second. +Find how long it has been since the program started. ```sig input.runningTime(); @@ -8,15 +8,20 @@ input.runningTime(); ### Returns -* [Number](/reference/types/number) +* the [Number](/reference/types/number) of milliseconds since the program started. +(One second is 1000 milliseconds.) ### Example: elapsed time -This code gets the elapsed time since the start of the program execution and displays it on the screen. +When you press button `B` on the microbit, this +program finds the number of milliseconds since the program started +and shows it on the [LED screen](/device/screen). ```blocks -let now = input.runningTime() -basic.showNumber(now) +input.onButtonPressed(Button.B, () => { + let now = input.runningTime() + basic.showNumber(now) +}) ``` ### Lessons diff --git a/docs/reference/input/temperature.md b/docs/reference/input/temperature.md index d793d9cf..45d61953 100644 --- a/docs/reference/input/temperature.md +++ b/docs/reference/input/temperature.md @@ -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 diff --git a/docs/reference/led/brightness.md b/docs/reference/led/brightness.md index cb248b07..f6e2e4e1 100644 --- a/docs/reference/led/brightness.md +++ b/docs/reference/led/brightness.md @@ -1,6 +1,6 @@ # Brightness -Set the brightness of the [LED screen](/device/screen). +Find how bright the [LED screen](/device/screen) is. ```sig led.brightness(); @@ -8,11 +8,11 @@ led.brightness(); ### Returns -* [Number](/reference/types/number) - returns the LCD screen brightness as a number from 0 to 255. A return value of 255 means the screen brightness is at 100% and 127 is about 50% brightness. +* a [Number](/reference/types/number) that means how bright the screen is, from `0` (darkest) to `255` (brightest). For example, the number `127` means the screen is halfway bright. -### Example: maximum brightness +### Example: highest brightness -If the screen brightness is < 100%, the following code sets the brightness to 100% (255): +This program makes the screen completely bright if it is not that way already: ```blocks if (led.brightness() < 255) { diff --git a/docs/reference/led/plot-bar-graph.md b/docs/reference/led/plot-bar-graph.md index c4345c6a..5f3ea5fa 100644 --- a/docs/reference/led/plot-bar-graph.md +++ b/docs/reference/led/plot-bar-graph.md @@ -1,6 +1,7 @@ # Plot Bar Graph -Displays a vertical bar graph based on the value and high value. +Displays a bar graph of the numbers you say. +A bar graph is a kind of chart that shows numbers as lines with different lengths. ```sig led.plotBarGraph(2, 20); @@ -8,10 +9,18 @@ led.plotBarGraph(2, 20); ### Parameters -* value: [Number](/reference/types/number) , high : [Number](/reference/types/number) displays a vertical bar graph based on the value and high value +* `value` is a [Number](/reference/types/number) that means what you are measuring or trying to show. For example, if you are measuring the temperature of ice with the BBC micro:bit, `value` might be 0 because the temperature might be 0 degrees centigrade. +* `high` is a [Number](/reference/types/number) that means the highest possible number that the `value` parameter can be. This number is also the tallest that the lines in the bar chart can be. ### Example: chart acceleration +This program shows a bar graph of the [acceleration](/reference/input/acceleration) +in the `x` direction of the micro:bit. +The micro:bit's `x` direction is from left to right (or right to left). +The more you speed up moving the micro:bit in this direction, +the taller the lines in the bar graph will be, +until they are as tall as the parameter `high` says they can be. + ```blocks basic.forever(() => { let a = input.acceleration(Dimension.X); diff --git a/docs/reference/logic.md b/docs/reference/logic.md index 9a81e7ea..2ff4f982 100644 --- a/docs/reference/logic.md +++ b/docs/reference/logic.md @@ -1,39 +1,9 @@ # Logic -[if](/reference/logic/if) - -```blocks -if(true) { -} -``` - -[Boolean](/reference/types/boolean) values: *true*; *false* - -```blocks -true -false -``` - -Boolean binary operators: *and* (conjunction); *or* (disjunction) - -```blocks +```cards +if(true) {} +true; true && false; -true || false; -``` - -Boolean negation operator - -```blocks -!true -``` - -Comparison operators (=, !=, <, >, <=, >=) - -```blocks -0 == 0; -1 !- 0; -0 < 1; -1 > 0; -0 <= 1; -1 >= 0; +!true; +1 != 0; ``` diff --git a/docs/reference/logic/if.md b/docs/reference/logic/if.md index 824be5ae..48b28778 100644 --- a/docs/reference/logic/if.md +++ b/docs/reference/logic/if.md @@ -1,23 +1,26 @@ # If -Run code based on a condition. - ### @parent blocks/language Conditionally run code depending on whether a [Boolean](/reference/types/boolean) condition is true or false. -### Block Editor - -![](/static/mb/hourofcode-0.png) +```blocks +if(true) { +} +``` In the Block Editor, click on the dark blue gear icon (see above) to add an *else* or *if* to the current block. ### Example: adjusting screen brightness -![](/static/mb/blocks/game-library/pic0.png) +```blocks +if(input.lightLevel()<100){ + led.setBrightness(255); +} +``` -If the screen [brightness](/reference/led/brightness) is `< 100`, this code sets the brightness to `255`: +If the [light level](/input/light-level) is `< 100`, this code sets the brightness to `255`: ### Lessons diff --git a/docs/reference/loops.md b/docs/reference/loops.md index b55a6b2f..e436293d 100644 --- a/docs/reference/loops.md +++ b/docs/reference/loops.md @@ -1,26 +1,8 @@ # Loops -Repeat code. - - -[for](/reference/loops/for) - -```blocks +```cards for(let i = 0;i<5;i++) {} -``` - -[repeat](/reference/loops/repeat) - -![](/static/mb/blocks/contents-0.png) - -[while](/reference/loops/while) - -```blocks +for(let i = 1;i<5;i++) {} while(true) {} -``` - -[forever](/reference/basic/forever) - -```blocks basic.forever(() => {}) ``` diff --git a/docs/reference/loops/for.md b/docs/reference/loops/for.md index cc89b948..0f074456 100644 --- a/docs/reference/loops/for.md +++ b/docs/reference/loops/for.md @@ -1,20 +1,16 @@ # For -Repeat code a preset number of times. - ### @parent blocks/language +Run part of the program the number of times you say. -Repeat code a fixed number of times. +### Example: Count to 4 -### Block Editor +This program will show the numbers 0, 1, 2, 3, and 4 one after another on the LED screen. -![](/static/mb/events-0.png) - -The Block Editor *for* loop is different than the Touch Develop *for* loop in an important way. The above for loop will iterate *five* times, with the loop variable *i* taking on values 0, 1, 2, 3, and 4. The Touch Develop for loop shown below will iterate four times: - -``` -for (let k = 0; k < 4; k++) { +```blocks +for(let i = 0; i < 5; ++i) { +basic.showNumber(i) } ``` @@ -24,5 +20,5 @@ for (let k = 0; k < 4; k++) { ### See also -[while](/reference/loops/while), [if](/reference/logic/if) +[repeat](/reference/loops/repeat), [while](/reference/loops/while), [if](/reference/logic/if), [show number](/reference/basic/show-number) diff --git a/docs/reference/loops/repeat.md b/docs/reference/loops/repeat.md index 7706e6af..22065328 100644 --- a/docs/reference/loops/repeat.md +++ b/docs/reference/loops/repeat.md @@ -1,21 +1,16 @@ # Repeat -Repeat code a preset number of times. - -Repeat code a fixed 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) diff --git a/docs/reference/loops/while.md b/docs/reference/loops/while.md index 480ad647..e3e98159 100644 --- a/docs/reference/loops/while.md +++ b/docs/reference/loops/while.md @@ -1,23 +1,14 @@ # While -Repeat code in a loop while a condition is true. - ### @parent blocks/language Repeat code while a [Boolean](/reference/types/boolean) `condition` is true. -### ~hide - +```blocks +while(true) { +} ``` -let condition = false -``` - -### ~ - -### Block Editor - -![](/static/mb/string-0.png) The while loop has a *condition* that evaluates to a [Boolean](/reference/types/boolean) value. After the `do` keyword, add the code that you want to run while the `condition` is `true`. The while loop concludes with `end while`. @@ -27,11 +18,13 @@ The condition is tested before any code runs. Which means that if the condition The following example uses a while loop to make a diagonal line on the LED screen (points `0, 0`, `1, 1`, `2, 2`, `3, 3`, `4, 4`). -// index is set to 4 - -![](/static/mb/blocks/var-10.png) - -// subtract 1 from `index` each time through loop +```blocks +let index = 4; +while(index >= 0) { + led.plot(index, index); + index--; +} +``` ### Lessons diff --git a/docs/reference/music/play-tone.md b/docs/reference/music/play-tone.md index 57b06cf9..037c8140 100644 --- a/docs/reference/music/play-tone.md +++ b/docs/reference/music/play-tone.md @@ -1,10 +1,10 @@ # Play Tone -Plays a music tone through pin ``P0`` for the given duration. +Play a musical tone through pin ``P0`` of the micro:bit for as long as you say. ## 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.playTone(440, 120) @@ -12,11 +12,14 @@ music.playTone(440, 120) ### Parameters -* `frequency` : [Number](/reference/types/number) - the frequency of the note (in Herz) -* `ms`: [Number](/reference/types/number) - the duration of the note (milliseconds) +* `Hz` is the [Number](/reference/types/number) of Hertz (the frequency, how high or low the tone is). +* `ms` is the [Number](/reference/types/number) of milliseconds that the tone lasts. ## Example +This example stores the musical note C in the variable `freq`. +Next, it plays that note for 1000 milliseconds (one second). + ```blocks let freq = music.noteFrequency(Note.C) music.playTone(freq, 1000) diff --git a/docs/reference/music/tempo.md b/docs/reference/music/tempo.md index 30f0bf61..830f14c3 100644 --- a/docs/reference/music/tempo.md +++ b/docs/reference/music/tempo.md @@ -1,16 +1,16 @@ # Tempo -Returns the tempo in beats per minute. +Finds the tempo (speed of a piece of music). ```sig music.tempo() ``` -### Parameters +### Returns -* Returns : [Number](/reference/types/number) - returns the tempo in beats per minute +* a [Number](/reference/types/number) that means the bpm (beats per minute, or number of beats in a minute of the music that the micro:bit is playing). ### See also -[play tone](/reference/music/play-tone), [ring tone](/reference/music/ring-tone) , [rest](/reference/music/rest), [set tempo](/reference/music/set-tempo), [change tempo by](/reference/music/change-tempo-by) +[play tone](/reference/music/play-tone), [ring tone](/reference/music/ring-tone), [rest](/reference/music/rest), [set tempo](/reference/music/set-tempo), [change tempo by](/reference/music/change-tempo-by) diff --git a/docs/reference/offline.md b/docs/reference/offline.md index 2ff572c9..e40e9b46 100644 --- a/docs/reference/offline.md +++ b/docs/reference/offline.md @@ -4,7 +4,7 @@ The micro:bit pins. ## How to work offline -If you have loaded the web app at some time in the past (by clicking on "my scripts" from the home page), then if you later open the same browser (whether you are online or offline) and type in [https://codemicrobit.com/](https://codemicrobit.com/), you will be able to access all the features of the web app. Note that it is important to end the URL with "/". +If you have loaded the web app at some time in the past (by clicking on "my scripts" from the home page), then if you later open the same browser (whether you are online or offline) and type in [https://m.pxt.io/](https://m.pxt.io/), you will be able to access all the features of the web app. Note that it is important to end the URL with "/". ## Save and load code using files diff --git a/docs/reference/pins.md b/docs/reference/pins.md index 7f7f2c36..7fece8ad 100644 --- a/docs/reference/pins.md +++ b/docs/reference/pins.md @@ -8,9 +8,15 @@ 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, () => { + +}); +pins.pulseDuration(); pins.servoWritePin(AnalogPin.P0, 180); pins.servoSetPulse(AnalogPin.P0, 1500); -pins.map(0, 0, 1023, 0, 4); +pins.i2cReadNumber(0, NumberFormat.Int8LE); +pins.i2cWriteNumber(0, 0, NumberFormat.Int8LE); pins.analogPitch(0, 0); pins.analogSetPitchPin(AnalogPin.P0); ``` diff --git a/docs/reference/radio.md b/docs/reference/radio.md index 27773d86..36150d2c 100644 --- a/docs/reference/radio.md +++ b/docs/reference/radio.md @@ -4,13 +4,17 @@ Communicate data using radio packets ```cards radio.sendNumber(0); -radio.sendNumbers(0, 0, 0, 0); +radio.sendValue("data", 0); +radio.sendString(""); radio.onDataReceived(() => { }); radio.receiveNumber(); radio.receivedNumberAt(0); +radio.receiveString(); radio.receivedSignalStrength(); radio.setGroup(0); radio.setTransmitPower(0); +radio.writeValueToSerial(); +radio.setTransmitSerialNumber(true); ``` diff --git a/docs/reference/radio/on-data-received.md b/docs/reference/radio/on-data-received.md index 61f2d6a2..b0095175 100644 --- a/docs/reference/radio/on-data-received.md +++ b/docs/reference/radio/on-data-received.md @@ -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 diff --git a/docs/reference/radio/receive-number.md b/docs/reference/radio/receive-number.md index 1d80eaff..8b25e601 100644 --- a/docs/reference/radio/receive-number.md +++ b/docs/reference/radio/receive-number.md @@ -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) diff --git a/docs/reference/radio/receive-string.md b/docs/reference/radio/receive-string.md new file mode 100644 index 00000000..f28765e9 --- /dev/null +++ b/docs/reference/radio/receive-string.md @@ -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) diff --git a/docs/reference/radio/send-number.md b/docs/reference/radio/send-number.md index 5236c969..45f70cf5 100644 --- a/docs/reference/radio/send-number.md +++ b/docs/reference/radio/send-number.md @@ -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) diff --git a/docs/reference/radio/send-string.md b/docs/reference/radio/send-string.md new file mode 100644 index 00000000..13320767 --- /dev/null +++ b/docs/reference/radio/send-string.md @@ -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) diff --git a/docs/reference/radio/set-group.md b/docs/reference/radio/set-group.md index 161085d4..a76de54d 100644 --- a/docs/reference/radio/set-group.md +++ b/docs/reference/radio/set-group.md @@ -1,28 +1,22 @@ # Set Group -Sets the group id for ``radio`` communications. A micro:bit can only listen to one group ID at any time. +Make a program have the group ID you tell it for sending and receiving +with ``radio``. A group is like a cable channel (a micro:bit can only +send or receive in one group at a time). A group ID is like the cable +channel number. -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) -``` +If you do not tell your program which group ID to use with this +function, it will figure out its own group ID by itself. If you load +the very same program onto two different micro:bits, they will be able +to talk to each other because they will have the same group ID. ### Parameters -* ``id`` -- a [number](/reference/types/number) between ``0`` and ``255``. +* ``id`` is a [number](/reference/types/number) from ``0`` to ``255``. ### Example -Sets the group to 128. +This program makes the group ID equal 128. ```blocks radio.setGroup(128) diff --git a/docs/reference/radio/set-transmit-power.md b/docs/reference/radio/set-transmit-power.md new file mode 100644 index 00000000..10c547dc --- /dev/null +++ b/docs/reference/radio/set-transmit-power.md @@ -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) diff --git a/docs/reference/radio/write-value-to-serial.md b/docs/reference/radio/write-value-to-serial.md new file mode 100644 index 00000000..a618b2b7 --- /dev/null +++ b/docs/reference/radio/write-value-to-serial.md @@ -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) diff --git a/docs/reference/serial.md b/docs/reference/serial.md index e4a373d0..4fdec09d 100644 --- a/docs/reference/serial.md +++ b/docs/reference/serial.md @@ -3,6 +3,10 @@ Reading and writing data over a serial connection. ```cards -serial.writeValue(x, 0); serial.writeLine(""); +serial.writeNumber(0); +serial.writeValue(x, 0); +serial.writeString(""); +serial.readLine(); +serial.redirect(SerialPin.P0, SerialPin.P0, BaudRate.BaudRate115200); ``` diff --git a/docs/reference/toc.md b/docs/reference/toc.md new file mode 100644 index 00000000..f5cbd987 --- /dev/null +++ b/docs/reference/toc.md @@ -0,0 +1,197 @@ +acceleration + +analog-pitch + +analog-read-pin + +analog-set-period + +analog-set-pitch-pin + +analog-write-pin + +assign + +boolean + +brightness + +button-is-pressed + +change + +change-score-by + +change-tempo + +change-var + +clear + +clear-screen + +compass-heading + +create-image + +digital-read-pin + +digital-write-pin + +fade-in + +fade-out + +for + +forever + +game-library + +game-over + +if + +image + +in-background + +light-level + +magnetic-force + +map + +math + +move + +number + +[on button pressed](/reference/input/on-button-pressed) + +on-data-received + +on-gamepad-button + +on-gesture + +on-pin-pressed + +on-signal-strength-changed + +pause + +pin-is-pressed + +pixel + +play-tone + +plot + +plot-all + +plot-bar-graph + +plot-frame + +plot-image + +plot-leds + +point + +position + +raise-alert-to + +receive-number + +receive-number + +repeat + +reports + +reset + +rest + +ring-tone + +rotation + +running-time + +score + +screenshot + +scroll-image + +send-number + +servo-set-pulse + +servo-write-pin + +set-brightness + +set-display-mode + +set-group + +set-pixel + +set-tempo + +show-animation + +show-frame + +show-image + +show-leds + +show-number + +show-string + +signal-strength + +start-countdown + +stop-animation + +string + +tell-camera-to + +tell-microphone-to + +tell-remote-control-to + +temperature + +tempo + +toggle + +toggle-all + +touching + +turn + +unplot + +var + +while + +width + +write-line + +write-value diff --git a/docs/reference/variables/assign.md b/docs/reference/variables/assign.md index de27860b..95f20dc6 100644 --- a/docs/reference/variables/assign.md +++ b/docs/reference/variables/assign.md @@ -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 diff --git a/docs/release-notes.md b/docs/release-notes.md new file mode 100644 index 00000000..55bc15e6 --- /dev/null +++ b/docs/release-notes.md @@ -0,0 +1,18 @@ +# Release notes + +```sim +basic.forever(() => { basic.showString("RELEASE NOTES"); }); +``` + +## June 2016 + +* It is now possible to stream data into the cloud (Azure) from the PXT editor. Simply click on the log view to get started. +* Documentation column pops up for large screen to avoid switching between docs and editor. + +## May 2016 + +We're happy to announce [m.pxt.io](https://m.pxt.io), an Blocks/JavaScript editor for the [BBC micro:bit](https://www.microbit.co.uk). +The editor is [open source](/open-source) on GitHub. Send us your PR! + +This release contains a Block/JavaScript editor, new simulator that supports multiple micro:bit instances, new documentation engine, +all the blocks from the Microsoft Block Editor in the BBC micro:bit web site. \ No newline at end of file diff --git a/docs/static/favicon.png b/docs/static/favicon.png new file mode 100644 index 00000000..1bbdb910 Binary files /dev/null and b/docs/static/favicon.png differ diff --git a/docs/static/icons/android-chrome-144x144.png b/docs/static/icons/android-chrome-144x144.png new file mode 100644 index 00000000..544f4f49 Binary files /dev/null and b/docs/static/icons/android-chrome-144x144.png differ diff --git a/docs/static/icons/android-chrome-192x192.png b/docs/static/icons/android-chrome-192x192.png new file mode 100644 index 00000000..38841bac Binary files /dev/null and b/docs/static/icons/android-chrome-192x192.png differ diff --git a/docs/static/icons/android-chrome-36x36.png b/docs/static/icons/android-chrome-36x36.png new file mode 100644 index 00000000..7bbbdd15 Binary files /dev/null and b/docs/static/icons/android-chrome-36x36.png differ diff --git a/docs/static/icons/android-chrome-48x48.png b/docs/static/icons/android-chrome-48x48.png new file mode 100644 index 00000000..bc7def5b Binary files /dev/null and b/docs/static/icons/android-chrome-48x48.png differ diff --git a/docs/static/icons/android-chrome-72x72.png b/docs/static/icons/android-chrome-72x72.png new file mode 100644 index 00000000..6584746b Binary files /dev/null and b/docs/static/icons/android-chrome-72x72.png differ diff --git a/docs/static/icons/android-chrome-96x96.png b/docs/static/icons/android-chrome-96x96.png new file mode 100644 index 00000000..e6204321 Binary files /dev/null and b/docs/static/icons/android-chrome-96x96.png differ diff --git a/docs/static/icons/apple-touch-icon-114x114.png b/docs/static/icons/apple-touch-icon-114x114.png new file mode 100644 index 00000000..8b999865 Binary files /dev/null and b/docs/static/icons/apple-touch-icon-114x114.png differ diff --git a/docs/static/icons/apple-touch-icon-120x120.png b/docs/static/icons/apple-touch-icon-120x120.png new file mode 100644 index 00000000..ca7a9af1 Binary files /dev/null and b/docs/static/icons/apple-touch-icon-120x120.png differ diff --git a/docs/static/icons/apple-touch-icon-144x144.png b/docs/static/icons/apple-touch-icon-144x144.png new file mode 100644 index 00000000..75bb35ac Binary files /dev/null and b/docs/static/icons/apple-touch-icon-144x144.png differ diff --git a/docs/static/icons/apple-touch-icon-152x152.png b/docs/static/icons/apple-touch-icon-152x152.png new file mode 100644 index 00000000..cbbf5c56 Binary files /dev/null and b/docs/static/icons/apple-touch-icon-152x152.png differ diff --git a/docs/static/icons/apple-touch-icon-180x180.png b/docs/static/icons/apple-touch-icon-180x180.png new file mode 100644 index 00000000..9f071c4e Binary files /dev/null and b/docs/static/icons/apple-touch-icon-180x180.png differ diff --git a/docs/static/icons/apple-touch-icon-57x57.png b/docs/static/icons/apple-touch-icon-57x57.png new file mode 100644 index 00000000..94c46299 Binary files /dev/null and b/docs/static/icons/apple-touch-icon-57x57.png differ diff --git a/docs/static/icons/apple-touch-icon-60x60.png b/docs/static/icons/apple-touch-icon-60x60.png new file mode 100644 index 00000000..3a9a4eee Binary files /dev/null and b/docs/static/icons/apple-touch-icon-60x60.png differ diff --git a/docs/static/icons/apple-touch-icon-72x72.png b/docs/static/icons/apple-touch-icon-72x72.png new file mode 100644 index 00000000..4b2efcaa Binary files /dev/null and b/docs/static/icons/apple-touch-icon-72x72.png differ diff --git a/docs/static/icons/apple-touch-icon-76x76.png b/docs/static/icons/apple-touch-icon-76x76.png new file mode 100644 index 00000000..550e12a8 Binary files /dev/null and b/docs/static/icons/apple-touch-icon-76x76.png differ diff --git a/docs/static/icons/apple-touch-icon-precomposed.png b/docs/static/icons/apple-touch-icon-precomposed.png new file mode 100644 index 00000000..66489dfc Binary files /dev/null and b/docs/static/icons/apple-touch-icon-precomposed.png differ diff --git a/docs/static/icons/apple-touch-icon.png b/docs/static/icons/apple-touch-icon.png new file mode 100644 index 00000000..9f071c4e Binary files /dev/null and b/docs/static/icons/apple-touch-icon.png differ diff --git a/docs/static/icons/favicon-16x16.png b/docs/static/icons/favicon-16x16.png new file mode 100644 index 00000000..1a00843e Binary files /dev/null and b/docs/static/icons/favicon-16x16.png differ diff --git a/docs/static/icons/favicon-32x32.png b/docs/static/icons/favicon-32x32.png new file mode 100644 index 00000000..d8c9dc5d Binary files /dev/null and b/docs/static/icons/favicon-32x32.png differ diff --git a/docs/static/icons/favicon-96x96.png b/docs/static/icons/favicon-96x96.png new file mode 100644 index 00000000..e6204321 Binary files /dev/null and b/docs/static/icons/favicon-96x96.png differ diff --git a/docs/static/icons/mstile-144x144.png b/docs/static/icons/mstile-144x144.png new file mode 100644 index 00000000..544f4f49 Binary files /dev/null and b/docs/static/icons/mstile-144x144.png differ diff --git a/docs/static/icons/mstile-150x150.png b/docs/static/icons/mstile-150x150.png new file mode 100644 index 00000000..2293492c Binary files /dev/null and b/docs/static/icons/mstile-150x150.png differ diff --git a/docs/static/icons/mstile-310x150.png b/docs/static/icons/mstile-310x150.png new file mode 100644 index 00000000..68d528f7 Binary files /dev/null and b/docs/static/icons/mstile-310x150.png differ diff --git a/docs/static/icons/mstile-310x310.png b/docs/static/icons/mstile-310x310.png new file mode 100644 index 00000000..0741b6a1 Binary files /dev/null and b/docs/static/icons/mstile-310x310.png differ diff --git a/docs/static/icons/mstile-70x70.png b/docs/static/icons/mstile-70x70.png new file mode 100644 index 00000000..e5ba5c5e Binary files /dev/null and b/docs/static/icons/mstile-70x70.png differ diff --git a/docs/static/icons/safari-pinned-tab.svg b/docs/static/icons/safari-pinned-tab.svg new file mode 100644 index 00000000..90a14d4a --- /dev/null +++ b/docs/static/icons/safari-pinned-tab.svg @@ -0,0 +1,59 @@ + + + + +Created by potrace 1.11, written by Peter Selinger 2001-2013 + + + + + + + + + + + + diff --git a/docs/static/mb/projects/a1-display.png b/docs/static/mb/projects/a1-display.png new file mode 100644 index 00000000..58ec9d6e Binary files /dev/null and b/docs/static/mb/projects/a1-display.png differ diff --git a/docs/static/mb/projects/a10-watch.png b/docs/static/mb/projects/a10-watch.png new file mode 100644 index 00000000..a27b1891 Binary files /dev/null and b/docs/static/mb/projects/a10-watch.png differ diff --git a/docs/static/mb/projects/a2-buttons.png b/docs/static/mb/projects/a2-buttons.png new file mode 100644 index 00000000..cc4c2d7f Binary files /dev/null and b/docs/static/mb/projects/a2-buttons.png differ diff --git a/docs/static/mb/projects/a3-pins.png b/docs/static/mb/projects/a3-pins.png new file mode 100644 index 00000000..55fa7aad Binary files /dev/null and b/docs/static/mb/projects/a3-pins.png differ diff --git a/docs/static/mb/projects/a4-motion.png b/docs/static/mb/projects/a4-motion.png new file mode 100644 index 00000000..7e9e31f3 Binary files /dev/null and b/docs/static/mb/projects/a4-motion.png differ diff --git a/docs/static/mb/projects/a5-compass.png b/docs/static/mb/projects/a5-compass.png new file mode 100644 index 00000000..644008a9 Binary files /dev/null and b/docs/static/mb/projects/a5-compass.png differ diff --git a/docs/static/mb/projects/a6-music.png b/docs/static/mb/projects/a6-music.png new file mode 100644 index 00000000..2eaa244d Binary files /dev/null and b/docs/static/mb/projects/a6-music.png differ diff --git a/docs/static/mb/projects/a7-conductive.png b/docs/static/mb/projects/a7-conductive.png new file mode 100644 index 00000000..4ea87138 Binary files /dev/null and b/docs/static/mb/projects/a7-conductive.png differ diff --git a/docs/static/mb/projects/a8-network.png b/docs/static/mb/projects/a8-network.png new file mode 100644 index 00000000..6849a27e Binary files /dev/null and b/docs/static/mb/projects/a8-network.png differ diff --git a/docs/static/mb/projects/a9-radio.png b/docs/static/mb/projects/a9-radio.png new file mode 100644 index 00000000..22a863f1 Binary files /dev/null and b/docs/static/mb/projects/a9-radio.png differ diff --git a/docs/static/microbit.simplified.svg b/docs/static/microbit.simplified.svg index d0936987..0db9abfd 100644 --- a/docs/static/microbit.simplified.svg +++ b/docs/static/microbit.simplified.svg @@ -1 +1 @@ -(1,0)(3,0)(0,1)(2,1)(4,1)(0,2)(4,2)(1,3)(3,3)(2,4)P0, ANALOG INP1, ANALOG INP2, ANALOG INP3, ANALOG IN, LED Col 1P4, ANALOG IN, LED Col 2P8P13, SPI - SCKP18, +3v3GND+3v3GNDAB(1,0)(1,0)(1,0)(1,0)(1,0)(1,0) \ No newline at end of file +(1,0)(3,0)(0,1)(2,1)(4,1)(0,2)(4,2)(1,3)(3,3)(2,4)P0, ANALOG INP1, ANALOG INP2, ANALOG INP3, ANALOG IN, LED Col 1P4, ANALOG IN, LED Col 2P5, BUTTON AP6, LED Col 9P7, LED Col 8P8P9, LED Col 7P10, ANALOG IN, LED Col 3P11, BUTTON BP12, RESERVED ACCESSIBILITYP13, SPI - SCKP14, SPI - MISOP15, SPI - MOSIP16, SPI - Chip SelectP17, +3v3P18, +3v3P19, I2C - SCLP20, I2C - SDAGNDGND+3v3GNDAB \ No newline at end of file diff --git a/docs/windows10.md b/docs/windows10.md index fa1c09b9..dcb8d66b 100644 --- a/docs/windows10.md +++ b/docs/windows10.md @@ -2,7 +2,7 @@ ## Features -The Windows 10 App provides all the existing features of codemicrobit.com plus the following ones: +The Windows 10 App provides all the existing features of [m.pxt.io](https://m.pxt.io) plus the following ones: * **auto-upload**: the compiled .hex file is automatically deployed to all connected BBC micro:bits * **serial piping**: all serial data sent by connected BBC micro:bit is automatically imported and analyzed in the editor. @@ -12,7 +12,7 @@ The Windows 10 App provides all the existing features of codemicrobit.com plus t The following instructions allow to side-load the Windows 10 app. This is required until the app is in the store. * Search for “developer settings” in Windows 10 and put your computer in “Developer mode”. -* Download https://pxt.io/codemicrobit.appx and unzip it. **DO NOT try to install from a zipped folder.** +* Download https://m.pxt.io/codemicrobit.appx and unzip it. **DO NOT try to install from a zipped folder.** * Open the extracted folder, right-click on `Add-AppDevPackage.ps1` and click on `Run with PowerShell`. Follow the prompts… 4) In order to communicate with the micro:bit via serial, you need to install the [ARM mbed driver](https://developer.mbed.org/handbook/Windows-serial-configuration). diff --git a/libs/microbit-radio/_locales/microbit-radio-strings.json b/libs/microbit-radio/_locales/microbit-radio-strings.json new file mode 100644 index 00000000..9c61d0d4 --- /dev/null +++ b/libs/microbit-radio/_locales/microbit-radio-strings.json @@ -0,0 +1,101 @@ +{ + "basic": "Provides access to basic micro:bit functionality.", + "basic.clearScreen": "Turn off all LEDs", + "basic.forever": "Repeats the code forever in the background. On each iteration, allows other codes to run.", + "basic.pause": "Pause for the specified time in milliseconds", + "basic.plotLeds": "Draws an image on the LED screen.", + "basic.showAnimation": "Shows a sequence of LED screens as an animation.", + "basic.showLeds": "Draws an image on the LED screen.", + "basic.showNumber": "Scroll a number on the screen. If the number fits on the screen (i.e. is a single digit), do not scroll.", + "basic.showString": "Display text on the display, one character at a time. If the string fits on the screen (i.e. is one letter), does not scroll.", + "control": "Runtime and event utilities.", + "control.inBackground": "Schedules code that run in the background.", + "control.reset": "Resets the BBC micro:bit.", + "game": "A single-LED sprite game engine", + "game.addScore": "Adds points to the current score", + "game.gameOver": "Displays a game over animation.", + "game.score": "Gets the current score", + "game.setScore": "Sets the current score value", + "game.startCountdown": "Starts a game countdown timer", + "images": "Creation, manipulation and display of LED images.", + "images.createBigImage": "Creates an image with 2 frames.", + "images.createImage": "Creates an image that fits on the LED screen.", + "input": "Events and data from sensors", + "input.acceleration": "Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)", + "input.buttonIsPressed": "Get the button state (pressed or not) for ``A`` and ``B``.", + "input.calibrate": "Obsolete, compass calibration is automatic.", + "input.compassHeading": "Get the current compass compass heading in degrees.", + "input.lightLevel": "Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.", + "input.magneticForce": "Get the magnetic force value in ``micro-Teslas`` (``µT``). This function is not supported in the simulator.", + "input.onButtonPressed": "Do something when a button (``A``, ``B`` or both ``A+B``) is pressed", + "input.onGesture": "Attaches code to run when the screen is facing up.", + "input.onLogoDown": "Attaches code to run when the logo is oriented downwards and the board is vertical.", + "input.onLogoUp": "Attaches code to run when the logo is oriented upwards and the board is vertical.", + "input.onPinPressed": "Do something when a pin(``P0``, ``P1`` or both ``P2``) is pressed.", + "input.onScreenDown": "Attaches code to run when the screen is facing down.", + "input.onScreenUp": "Attaches code to run when the screen is facing up.", + "input.onShake": "Attaches code to run when the device is shaken.", + "input.pinIsPressed": "Get the pin state (pressed or not). Requires to hold the ground to close the circuit.", + "input.rotation": "The pitch of the device, rotation along the ``x-axis``, in degrees.", + "input.runningTime": "Gets the number of milliseconds elapsed since power on.", + "input.setAccelerometerRange": "Sets the accelerometer sample range in gravities.", + "input.temperature": "Gets the temperature in Celsius degrees (°C).", + "led": "Control of the LED screen.", + "led.brightness": "Get the screen brightness from 0 (off) to 255 (full bright).", + "led.fadeIn": "Fades in the screen display.", + "led.fadeOut": "Fades out the screen brightness.", + "led.plot": "Turn on the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.", + "led.plotAll": "Turns all LEDS on", + "led.plotBarGraph": "Displays a vertical bar graph based on the `value` and `high` value.\nIf `high` is 0, the chart gets adjusted automatically.", + "led.point": "Get the on/off state of the specified LED using x, y coordinates. (0,0) is upper left.", + "led.screenshot": "Takes a screenshot of the LED screen and returns an image.", + "led.setBrightness": "Set the screen brightness from 0 (off) to 255 (full bright).", + "led.setDisplayMode": "Sets the display mode between black and white and greyscale for rendering LEDs.", + "led.stopAnimation": "Cancels the current animation and clears other pending animations.", + "led.toggle": "Toggles a particular pixel", + "led.toggleAll": "Inverts the current LED display", + "led.unplot": "Turn off the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.", + "music": "Generation of music tones through pin ``P0``.", + "music.beat": "Returns the duration of a beat in milli-seconds", + "music.changeTempoBy": "Change the tempo by the specified amount", + "music.noteFrequency": "Gets the frequency of a note.", + "music.playTone": "Plays a tone through pin ``P0`` for the given duration.", + "music.rest": "Rests (plays nothing) for a specified time through pin ``P0``.", + "music.ringTone": "Plays a tone through pin ``P0``.", + "music.setTempo": "Sets the tempo to the specified amount", + "music.tempo": "Returns the tempo in beats per minute. Tempo is the speed (bpm = beats per minute) at which notes play. The larger the tempo value, the faster the notes will play.", + "pins": "Control currents in Pins for analog/digital signals, servos, i2c, ...", + "pins.analogPitch": "Emits a Pulse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.", + "pins.analogReadPin": "Read the connector value as analog, that is, as a value comprised between 0 and 1023.", + "pins.analogSetPeriod": "Configures the Pulse-width modulation (PWM) of the analog output to the given value in **microseconds** or `1/1000` milliseconds.\nIf this pin is not configured as an analog output (using `analog write pin`), the operation has no effect.", + "pins.analogSetPitchPin": "Sets the pin used when using `pins->analog pitch`.", + "pins.analogWritePin": "Set the connector value as analog. Value must be comprised between 0 and 1023.", + "pins.digitalReadPin": "Read the specified pin or connector as either 0 or 1", + "pins.digitalWritePin": "Set a pin or connector value to either 0 or 1.", + "pins.i2cReadNumber": "Read one number from 7-bit I2C address.", + "pins.i2cWriteNumber": "Write one number to a 7-bit I2C address.", + "pins.map": "Re-maps a number from one range to another. That is, a value of ``from low`` would get mapped to ``to low``, a value of ``from high`` to ``to high``, values in-between to values in-between, etc.", + "pins.onPulsed": "Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``.", + "pins.pulseDuration": "Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulse`` handler.", + "pins.servoSetPulse": "Configures this IO pin as an analog/pwm output, configures the period to be 20 ms, and sets the pulse width, based on the value it is given **microseconds** or `1/1000` milliseconds.", + "pins.servoWritePin": "Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).", + "radio": "Communicate data using radio packets", + "radio.onDataReceived": "Registers code to run when a packet is received over radio.", + "radio.receiveNumber": "Reads the next packet as a number from the radio queue.", + "radio.receiveString": "Reads the next packet as a string and returns it.", + "radio.receivedNumberAt": "Reads a number at a given index, between ``0`` and ``3``, from the packet received by ``receive number``. Not supported in simulator.", + "radio.receivedSignalStrength": "Gets the received signal strength indicator (RSSI) from the packet received by ``receive number``. Not supported in simulator.\nnamespace=radio", + "radio.sendNumber": "Broadcasts a number over radio to any connected micro:bit in the group.", + "radio.sendString": "Broadcasts a number over radio to any connected micro:bit in the group.", + "radio.sendValue": "Broadcasts a name / value pair along with the device serial number\nand running time to any connected BBC micro:bit in the group.", + "radio.setGroup": "Sets the group id for radio communications. A micro:bit can only listen to one group ID at any time.\n@ param id the group id between ``0`` and ``255``, 1 eg", + "radio.setTransmitPower": "Change the output power level of the transmitter to the given value.", + "radio.setTransmitSerialNumber": "Set the radio to transmit the serial number in each message.", + "radio.writeValueToSerial": "Reads a value sent with `stream value` and writes it\nto the serial stream as JSON", + "serial": "Reading and writing data over a serial connection.", + "serial.readLine": "Reads a line of text from the serial port.", + "serial.writeLine": "Prints a line of text to the serial", + "serial.writeNumber": "Prints a numeric value to the serial", + "serial.writeString": "Sends a piece of text through Serial connection.", + "serial.writeValue": "Writes a ``name: value`` pair line to the serial." +} \ No newline at end of file diff --git a/libs/microbit-radio/radio.cpp b/libs/microbit-radio/radio.cpp index f1731994..ab682448 100644 --- a/libs/microbit-radio/radio.cpp +++ b/libs/microbit-radio/radio.cpp @@ -43,7 +43,7 @@ namespace radio { */ //% help=radio/send-number //% weight=60 - //% blockId=radio_datagram_send block="send number %MESSAGE" blockGap=8 + //% blockId=radio_datagram_send block="send number %value" blockGap=8 void sendNumber(int value) { if (radioEnable() != MICROBIT_OK) return; uint32_t t = system_timer_current_time(); @@ -60,7 +60,7 @@ namespace radio { */ //% help=radio/send-value //% weight=59 - //% blockId=radio_datagram_send_value block="send|value %name|= %value" + //% blockId=radio_datagram_send_value block="send|value %name|= %value" blockGap=8 void sendValue(StringData* name, int value) { if (radioEnable() != MICROBIT_OK) return; @@ -81,6 +81,22 @@ namespace radio { uBit.radio.datagram.send(buf, 13 + len); } + /** + * Broadcasts a number over radio to any connected micro:bit in the group. + */ + //% help=radio/send-string + //% weight=58 + //% blockId=radio_datagram_send_string block="send string %msg" + void sendString(StringData* msg) { + if (radioEnable() != MICROBIT_OK) return; + + ManagedString s(msg); + if (s.length() > MICROBIT_RADIO_MAX_PACKET_SIZE) + s = s.substring(0, MICROBIT_RADIO_MAX_PACKET_SIZE); + + uBit.radio.datagram.send(s); + } + /** * Reads a value sent with `stream value` and writes it * to the serial stream as JSON @@ -159,7 +175,19 @@ namespace radio { packet = uBit.radio.datagram.recv(); return receivedNumberAt(0); } - + + /** + * Reads the next packet as a string and returns it. + */ + //% blockId=radio_datagram_receive_string block="receive string" blockGap=8 + //% weight=44 + //% help=radio/receive-string + StringData* receiveString() { + if (radioEnable() != MICROBIT_OK) return ManagedString().leakData(); + packet = uBit.radio.datagram.recv(); + return ManagedString(packet).leakData(); + } + /** * Gets the received signal strength indicator (RSSI) from the packet received by ``receive number``. Not supported in simulator. * namespace=radio diff --git a/libs/microbit-radio/radio.ts b/libs/microbit-radio/radio.ts index 942ca022..05f5c9ab 100644 --- a/libs/microbit-radio/radio.ts +++ b/libs/microbit-radio/radio.ts @@ -1,6 +1,6 @@ /** * Communicate data using radio packets */ -//% color=270 weight=34 +//% color=#E3008C weight=34 namespace radio { } diff --git a/libs/microbit-radio/shims.d.ts b/libs/microbit-radio/shims.d.ts index 2887f967..4e65dd5b 100644 --- a/libs/microbit-radio/shims.d.ts +++ b/libs/microbit-radio/shims.d.ts @@ -10,7 +10,7 @@ declare namespace radio { */ //% help=radio/send-number //% weight=60 - //% blockId=radio_datagram_send block="send number %MESSAGE" blockGap=8 shim=radio::sendNumber + //% blockId=radio_datagram_send block="send number %value" blockGap=8 shim=radio::sendNumber function sendNumber(value: number): void; /** @@ -21,9 +21,17 @@ declare namespace radio { */ //% help=radio/send-value //% weight=59 - //% blockId=radio_datagram_send_value block="send|value %name|= %value" shim=radio::sendValue + //% blockId=radio_datagram_send_value block="send|value %name|= %value" blockGap=8 shim=radio::sendValue function sendValue(name: string, value: number): void; + /** + * Broadcasts a number over radio to any connected micro:bit in the group. + */ + //% help=radio/send-string + //% weight=58 + //% blockId=radio_datagram_send_string block="send string %msg" shim=radio::sendString + function sendString(msg: string): void; + /** * Reads a value sent with `stream value` and writes it * to the serial stream as JSON @@ -58,6 +66,14 @@ declare namespace radio { //% blockId=radio_datagram_receive block="receive number" blockGap=8 shim=radio::receiveNumber function receiveNumber(): number; + /** + * Reads the next packet as a string and returns it. + */ + //% blockId=radio_datagram_receive_string block="receive string" blockGap=8 + //% weight=44 + //% help=radio/receive-string shim=radio::receiveString + function receiveString(): string; + /** * Gets the received signal strength indicator (RSSI) from the packet received by ``receive number``. Not supported in simulator. * namespace=radio diff --git a/libs/microbit/_locales/fr/strings.json b/libs/microbit/_locales/fr/strings.json new file mode 100644 index 00000000..a63599ad --- /dev/null +++ b/libs/microbit/_locales/fr/strings.json @@ -0,0 +1,3 @@ +{ + "basic.clearScreen": "Eteint toutes les diodes." +} \ No newline at end of file diff --git a/libs/microbit/_locales/microbit-strings.json b/libs/microbit/_locales/strings.json similarity index 88% rename from libs/microbit/_locales/microbit-strings.json rename to libs/microbit/_locales/strings.json index 3851926c..4e362f31 100644 --- a/libs/microbit/_locales/microbit-strings.json +++ b/libs/microbit/_locales/strings.json @@ -1,4 +1,6 @@ { + "Math.randomBoolean": "Generates a `true` or `false` value randomly, just like flipping a coin.", + "String.fromCharCode": "Make a string from the given ASCII character code.", "basic": "Provides access to basic micro:bit functionality.", "basic.clearScreen": "Turn off all LEDs", "basic.forever": "Repeats the code forever in the background. On each iteration, allows other codes to run.", @@ -72,10 +74,18 @@ "pins.analogWritePin": "Set the connector value as analog. Value must be comprised between 0 and 1023.", "pins.digitalReadPin": "Read the specified pin or connector as either 0 or 1", "pins.digitalWritePin": "Set a pin or connector value to either 0 or 1.", + "pins.i2cReadNumber": "Read one number from 7-bit I2C address.", + "pins.i2cWriteNumber": "Write one number to a 7-bit I2C address.", "pins.map": "Re-maps a number from one range to another. That is, a value of ``from low`` would get mapped to ``to low``, a value of ``from high`` to ``to high``, values in-between to values in-between, etc.", + "pins.onPulsed": "Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``.", + "pins.pulseDuration": "Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulsed`` handler.", "pins.servoSetPulse": "Configures this IO pin as an analog/pwm output, configures the period to be 20 ms, and sets the pulse width, based on the value it is given **microseconds** or `1/1000` milliseconds.", "pins.servoWritePin": "Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).", "serial": "Reading and writing data over a serial connection.", + "serial.readLine": "Reads a line of text from the serial port.", + "serial.redirect": "Dynamically configuring the serial instance to use pins other than USBTX and USBRX.", "serial.writeLine": "Prints a line of text to the serial", + "serial.writeNumber": "Prints a numeric value to the serial", + "serial.writeString": "Sends a piece of text through Serial connection.", "serial.writeValue": "Writes a ``name: value`` pair line to the serial." } \ No newline at end of file diff --git a/libs/microbit/basic.cpp b/libs/microbit/basic.cpp index 15a4a97d..3711b948 100644 --- a/libs/microbit/basic.cpp +++ b/libs/microbit/basic.cpp @@ -4,7 +4,7 @@ /** * Provides access to basic micro:bit functionality. */ -//% color=190 weight=100 +//% color=#0078D7 weight=100 namespace basic { /** diff --git a/libs/microbit/control.cpp b/libs/microbit/control.cpp index 051c512a..ed8479a5 100644 --- a/libs/microbit/control.cpp +++ b/libs/microbit/control.cpp @@ -141,7 +141,7 @@ namespace control { * @param value Component specific code indicating the cause of the event. * @param mode optional definition of how the event should be processed after construction (default is CREATE_AND_FIRE). */ - //% weight=21 blockGap=12 blockId="control_raise_event" block="raise event|from source %src=control_event_source|with value %value=control_event_value" blockExternalInputs=1 + //% weight=21 blockGap=12 blockId="control_raise_event" block="raise event|from source %src=control_event_source_id|with value %value=control_event_value_id" blockExternalInputs=1 //% mode.defl=CREATE_AND_FIRE void raiseEvent(int src, int value, EventCreationMode mode) { MicroBitEvent evt(src, value, (MicroBitEventLaunchMode)mode); @@ -150,11 +150,29 @@ namespace control { /** * Raises an event in the event bus. */ - //% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source|with value %value=control_event_value" + //% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source_id|with value %value=control_event_value_id" //% blockExternalInputs=1 void onEvent(int src, int value, Action handler) { registerWithDal(src, value, handler); } + + /** + * Gets the value of the last event executed on the bus + */ + //% blockId=control_event_value" block="event value" + //% weight=18 + int eventValue() { + return pxt::lastEvent.value; + } + + /** + * Gets the timestamp of the last event executed on the bus + */ + //% blockId=control_event_timestamp" block="event timestamp" + //% weight=19 blockGap=8 + int eventTimestamp() { + return pxt::lastEvent.timestamp; + } /** * Gets a friendly name for the device derived from the its serial number diff --git a/libs/microbit/control.ts b/libs/microbit/control.ts index 7c479fe3..f2d4ec1a 100644 --- a/libs/microbit/control.ts +++ b/libs/microbit/control.ts @@ -7,15 +7,15 @@ namespace control { /** * Returns the value of a C++ runtime constant */ - //% weight=19 weight=19 blockId="control_event_source" block="%id" - export function eventSource(id: EventBusSource) : number { + //% weight=2 weight=19 blockId="control_event_source_id" block="%id" blockGap=8 + export function eventSourceId(id: EventBusSource): number { return id; } /** * Returns the value of a C++ runtime constant */ - //% weight=19 weight=19 blockId="control_event_value" block="%id" - export function eventValue(id: EventBusValue) : number { + //% weight=1 weight=19 blockId="control_event_value_id" block="%id" + export function eventValueId(id: EventBusValue): number { return id; } @@ -23,8 +23,7 @@ namespace control { * Display specified error code and stop the program. */ //% shim=pxtrt::panic - export function panic(code:number) - { + export function panic(code: number) { } /** diff --git a/libs/microbit/dal.d.ts b/libs/microbit/dal.d.ts index bf7467a7..6c924ba1 100644 --- a/libs/microbit/dal.d.ts +++ b/libs/microbit/dal.d.ts @@ -86,7 +86,7 @@ declare const enum DAL { MICROBIT_DFU_HISTOGRAM_HEIGHT = 5, // built/yt/yotta_modules/microbit-dal/inc//bluetooth/MicroBitEventService.h // built/yt/yotta_modules/microbit-dal/inc//bluetooth/MicroBitIOPinService.h - MICROBIT_IO_PIN_SERVICE_PINCOUNT = 20, + MICROBIT_IO_PIN_SERVICE_PINCOUNT = 19, MICROBIT_IO_PIN_SERVICE_DATA_SIZE = 10, // built/yt/yotta_modules/microbit-dal/inc//bluetooth/MicroBitLEDService.h MICROBIT_BLE_MAXIMUM_SCROLLTEXT = 20, @@ -208,6 +208,7 @@ declare const enum DAL { MMA8653_SAMPLE_RANGES = 3, MMA8653_SAMPLE_RATES = 8, MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE = 1, + MICROBIT_ACCELEROMETER_EVT_NONE = 0, MICROBIT_ACCELEROMETER_EVT_TILT_UP = 1, MICROBIT_ACCELEROMETER_EVT_TILT_DOWN = 2, MICROBIT_ACCELEROMETER_EVT_TILT_LEFT = 3, @@ -229,18 +230,6 @@ declare const enum DAL { MICROBIT_ACCELEROMETER_GESTURE_DAMPING = 10, MICROBIT_ACCELEROMETER_SHAKE_DAMPING = 10, MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD = 4, - GESTURE_NONE = 0, - GESTURE_UP = 1, - GESTURE_DOWN = 2, - GESTURE_LEFT = 3, - GESTURE_RIGHT = 4, - GESTURE_FACE_UP = 5, - GESTURE_FACE_DOWN = 6, - GESTURE_FREEFALL = 7, - GESTURE_3G = 8, - GESTURE_6G = 9, - GESTURE_8G = 10, - GESTURE_SHAKE = 11, // built/yt/yotta_modules/microbit-dal/inc//drivers/MicroBitButton.h MICROBIT_BUTTON_EVT_DOWN = 1, MICROBIT_BUTTON_EVT_UP = 2, @@ -343,14 +332,22 @@ declare const enum DAL { IO_STATUS_ANALOG_IN = 0x04, IO_STATUS_ANALOG_OUT = 0x08, IO_STATUS_TOUCH_IN = 0x10, - IO_STATUS_EVENTBUS_ENABLED = 0x80, + IO_STATUS_EVENT_ON_EDGE = 0x20, + IO_STATUS_EVENT_PULSE_ON_EDGE = 0x40, MICROBIT_PIN_MAX_OUTPUT = 1023, MICROBIT_PIN_MAX_SERVO_RANGE = 180, MICROBIT_PIN_DEFAULT_SERVO_RANGE = 2000, MICROBIT_PIN_DEFAULT_SERVO_CENTER = 1500, + MICROBIT_PIN_EVENT_NONE = 0, + MICROBIT_PIN_EVENT_ON_EDGE = 1, + MICROBIT_PIN_EVENT_ON_PULSE = 2, + MICROBIT_PIN_EVENT_ON_TOUCH = 3, + MICROBIT_PIN_EVT_RISE = 2, + MICROBIT_PIN_EVT_FALL = 3, + MICROBIT_PIN_EVT_PULSE_HI = 4, + MICROBIT_PIN_EVT_PULSE_LO = 5, PIN_CAPABILITY_DIGITAL = 0x01, PIN_CAPABILITY_ANALOG = 0x02, - PIN_CAPABILITY_TOUCH = 0x04, // built/yt/yotta_modules/microbit-dal/inc//drivers/MicroBitRadio.h MICROBIT_RADIO_STATUS_INITIALISED = 0x0001, MICROBIT_RADIO_BASE_ADDRESS = 0x75626974, @@ -388,6 +385,7 @@ declare const enum DAL { MICROBIT_THERMOMETER_PERIOD = 1000, MICROBIT_THERMOMETER_EVT_UPDATE = 1, MICROBIT_THERMOMETER_ADDED_TO_IDLE = 2, + // built/yt/yotta_modules/microbit-dal/inc//drivers/TimedInterruptIn.h // built/yt/yotta_modules/microbit-dal/inc//platform/yotta_cfg_mappings.h // built/yt/yotta_modules/microbit-dal/inc//types/ManagedString.h // built/yt/yotta_modules/microbit-dal/inc//types/ManagedType.h diff --git a/libs/microbit/enums.d.ts b/libs/microbit/enums.d.ts index fadecb8f..c0b922f1 100644 --- a/libs/microbit/enums.d.ts +++ b/libs/microbit/enums.d.ts @@ -69,42 +69,52 @@ declare namespace basic { * Raised when shaken */ //% block=shake - Shake = 11, // GESTURE_SHAKE + Shake = 11, // MICROBIT_ACCELEROMETER_EVT_SHAKE /** * Raised when the logo is upward and the screen is vertical */ //% block="logo up" - LogoUp = 1, // GESTURE_UP + LogoUp = 1, // MICROBIT_ACCELEROMETER_EVT_TILT_UP /** * Raised when the logo is downward and the screen is vertical */ //% block="logo down" - LogoDown = 2, // GESTURE_DOWN + LogoDown = 2, // MICROBIT_ACCELEROMETER_EVT_TILT_DOWN /** * Raised when the screen is pointing down and the board is horizontal */ //% block="screen up" - ScreenUp = 5, // GESTURE_FACE_UP + ScreenUp = 5, // MICROBIT_ACCELEROMETER_EVT_FACE_UP /** * Raised when the screen is pointing up and the board is horizontal */ //% block="screen down" - ScreenDown = 6, // GESTURE_FACE_DOWN + ScreenDown = 6, // MICROBIT_ACCELEROMETER_EVT_FACE_DOWN /** * Raised when the screen is pointing left */ //% block="tilt left" - TiltLeft = 3, // GESTURE_LEFT + TiltLeft = 3, // MICROBIT_ACCELEROMETER_EVT_TILT_LEFT /** * Raised when the screen is pointing right */ //% block="tilt right" - TiltRight = 4, // GESTURE_RIGHT + TiltRight = 4, // MICROBIT_ACCELEROMETER_EVT_TILT_RIGHT /** * Raised when the board is falling! */ //% block="free fall" - FreeFall = 7, // GESTURE_FREEFALL + FreeFall = 7, // MICROBIT_ACCELEROMETER_EVT_FREEFALL + /** + * Raised when a 3G shock is detected + */ + //% block="3g" + ThreeG = 8, // MICROBIT_ACCELEROMETER_EVT_3G + /** + * Raised when a 6G shock is detected + */ + //% block="6g" + SixG = 9, // MICROBIT_ACCELEROMETER_EVT_6G } declare namespace input { } @@ -262,8 +272,35 @@ declare namespace led { P4 = 11, // MICROBIT_ID_IO_P4 P10 = 17, // MICROBIT_ID_IO_P10 } + + + declare enum PulseValue { + High = 4, // MICROBIT_PIN_EVT_PULSE_HI + Low = 5, // MICROBIT_PIN_EVT_PULSE_LO + } declare namespace pins { } + + + declare enum SerialPin { + P0 = 7, // MICROBIT_ID_IO_P0 + P1 = 8, // MICROBIT_ID_IO_P1 + P2 = 9, // MICROBIT_ID_IO_P2 + P8 = 15, // MICROBIT_ID_IO_P8 + P12 = 19, // MICROBIT_ID_IO_P12 + P13 = 20, // MICROBIT_ID_IO_P13 + P14 = 21, // MICROBIT_ID_IO_P14 + P15 = 22, // MICROBIT_ID_IO_P15 + P16 = 23, // MICROBIT_ID_IO_P16 + } + + + declare enum BaudRate { + //% block=115200 + BaudRate115200 = 115200, + //% block=9600 + BaudRate9600 = 9600, + } declare namespace serial { } @@ -281,7 +318,5 @@ declare namespace serial { Int32BE = 10, // UInt32, } -declare namespace storage { -} // Auto-generated. Do not edit. Really. diff --git a/libs/microbit/game.ts b/libs/microbit/game.ts index 6fbd21cb..408316e6 100644 --- a/libs/microbit/game.ts +++ b/libs/microbit/game.ts @@ -21,19 +21,19 @@ enum LedSpriteProperty { /** * A single-LED sprite game engine */ -//% color=176 weight=32 +//% color=#008272 weight=32 namespace game { - var _score: number = 0; - var _life: number = 3; - var _startTime: number = 0; - var _endTime: number = 0; - var _isGameOver: boolean = false; - var _countdownPause: number = 0; - var _level: number = 1; - var _gameId: number = 0; - var img: Image; - var sprites: LedSprite[]; - + let _score: number = 0; + let _life: number = 3; + let _startTime: number = 0; + let _endTime: number = 0; + let _isGameOver: boolean = false; + let _countdownPause: number = 0; + let _level: number = 1; + let _gameId: number = 0; + let img: Image; + let sprites: LedSprite[]; + /** * Creates a new LED sprite pointing to the right. * @param x sprite horizontal coordinate, eg: 2 @@ -47,7 +47,7 @@ namespace game { sprites.push(p); plot(); return p; - } + } /** * Gets the current score @@ -394,7 +394,7 @@ namespace game { } plot(); } - + /** * Turn the sprite * @param this TODO @@ -403,7 +403,7 @@ namespace game { */ //% weight=49 //% blockId=game_turn_sprite block="%sprite|turn %direction|by (°) %degrees" - public turn(direction : Direction, degrees: number) { + public turn(direction: Direction, degrees: number) { if (direction == Direction.Right) this.setDirection(this._dir + degrees); else @@ -435,8 +435,8 @@ namespace game { */ //% weight=29 //% blockId=game_sprite_set_property block="%sprite|set %property|to %value" blockGap=8 - public set(property : LedSpriteProperty, value:number) { - switch(property) { + public set(property: LedSpriteProperty, value: number) { + switch (property) { case LedSpriteProperty.X: this.setX(value); break; case LedSpriteProperty.Y: this.setY(value); break; case LedSpriteProperty.Direction: this.setDirection(value); break; @@ -452,8 +452,8 @@ namespace game { */ //% weight=30 //% blockId=game_sprite_change_xy block="%sprite|change %property|by %value" blockGap=8 - public change(property : LedSpriteProperty, value:number) { - switch(property) { + public change(property: LedSpriteProperty, value: number) { + switch (property) { case LedSpriteProperty.X: this.changeXBy(value); break; case LedSpriteProperty.Y: this.changeYBy(value); break; case LedSpriteProperty.Direction: this.changeDirectionBy(value); break; @@ -461,15 +461,15 @@ namespace game { case LedSpriteProperty.Blink: this.changeBlinkBy(value); break; } } - + /** * Gets a property of the sprite * @param property the name of the property to change */ //% weight=28 //% blockId=game_sprite_property block="%sprite|%property" - public get(property : LedSpriteProperty) { - switch(property) { + public get(property: LedSpriteProperty) { + switch (property) { case LedSpriteProperty.X: return this.x(); case LedSpriteProperty.Y: return this.y(); case LedSpriteProperty.Direction: return this.direction() @@ -681,7 +681,7 @@ namespace game { function init(): void { if (img == null) { img = images.createImage( -`0 0 0 0 0 + `0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 diff --git a/libs/microbit/helpers.ts b/libs/microbit/helpers.ts index 1e6bad4a..a5276a9a 100644 --- a/libs/microbit/helpers.ts +++ b/libs/microbit/helpers.ts @@ -4,3 +4,14 @@ namespace console { serial.writeString("\r\n"); } } + +namespace Math { + /** + * Generates a `true` or `false` value randomly, just like flipping a coin. + */ + //% blockId=logic_random block="pick random true or false" + //% help=math/random-boolean color=230 + export function randomBoolean(): boolean { + return Math.random(2) == 0; + } +} \ No newline at end of file diff --git a/libs/microbit/images.cpp b/libs/microbit/images.cpp index 707cd936..7c3e3983 100644 --- a/libs/microbit/images.cpp +++ b/libs/microbit/images.cpp @@ -3,7 +3,7 @@ /** * Creation, manipulation and display of LED images. */ -//% color=45 weight=31 +//% color=#5C2D91 weight=31 namespace images { /** * Creates an image that fits on the LED screen. @@ -35,17 +35,17 @@ namespace ImageMethods { /** * Shows an frame from the image at offset ``x offset``. - * @param xOffset TODO + * @param xOffset column index to start displaying the image */ - //% help=images/show-image weight=80 async - //% BUGblockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8 - void showImage(Image i, int xOffset = 0) { - uBit.display.print(MicroBitImage(i), -xOffset, 0, 0); + //% help=images/show-image weight=80 blockNamespace=images + //% blockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8 + void showImage(Image sprite, int xOffset) { + uBit.display.print(MicroBitImage(sprite), -xOffset, 0, 0); } /** * Draws the ``index``-th frame of the image on the screen. - * @param xOffset TODO + * @param xOffset column index to start displaying the image */ //% help=images/plot-frame weight=80 void plotFrame(Image i, int xOffset) { @@ -58,9 +58,9 @@ namespace ImageMethods { * @param frameOffset x offset moved on each animation step, eg: 5, 1, -1 * @param interval time between each animation step in milli seconds, eg: 200 */ - //% help=images/show-image weight=79 async - //% BUGblockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8 - void scrollImage(Image id, int frameOffset = 0, int interval = 200) { + //% help=images/show-image weight=79 async blockNamespace=images + //% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8 + void scrollImage(Image id, int frameOffset, int interval) { MicroBitImage i(id); if (i.getWidth() <= 5) showImage(id, 0); @@ -80,7 +80,7 @@ namespace ImageMethods { /** * Sets a specific pixel brightness at a given position */ - //% help= + //% void setPixelBrightness(Image i, int x, int y, int value) { MicroBitImage(i).setPixelValue(x, y, value); } @@ -89,7 +89,7 @@ namespace ImageMethods { /** * Gets the pixel brightness ([0..255]) at a given position */ - //% help= + //% int pixelBrightness(Image i, int x, int y) { int pix = MicroBitImage(i).getPixelValue(x, y); if (pix < 0) return 0; @@ -108,7 +108,7 @@ namespace ImageMethods { /** * Gets the height in rows (always 5) */ - //% shim= + //% int height(Image i) { return i->height; } @@ -119,7 +119,7 @@ namespace ImageMethods { * @param y TODO * @param value TODO */ - //% help=functions/set-pixel + //% help=images/set-pixel void setPixel(Image i, int x, int y, bool value) { setPixelBrightness(i, x, y, value ? 255 : 0); } @@ -129,7 +129,7 @@ namespace ImageMethods { * @param x TODO * @param y TODO */ - //% help=functions/pixel + //% help=images/pixel bool pixel(Image i, int x, int y) { return pixelBrightness(i, x, y) > 0; } @@ -139,7 +139,7 @@ namespace ImageMethods { * Shows a particular frame of the image strip. * @param frame TODO */ - //% weight=70 help=functions/show-frame + //% weight=70 help=images/show-frame void showFrame(Image i, int frame) { showImage(i, frame * 5); } diff --git a/libs/microbit/input.cpp b/libs/microbit/input.cpp index 600e3a8b..efdbc312 100644 --- a/libs/microbit/input.cpp +++ b/libs/microbit/input.cpp @@ -59,42 +59,52 @@ enum class Gesture { * Raised when shaken */ //% block=shake - Shake = GESTURE_SHAKE, + Shake = MICROBIT_ACCELEROMETER_EVT_SHAKE, /** * Raised when the logo is upward and the screen is vertical */ //% block="logo up" - LogoUp = GESTURE_UP, + LogoUp = MICROBIT_ACCELEROMETER_EVT_TILT_UP, /** * Raised when the logo is downward and the screen is vertical */ //% block="logo down" - LogoDown = GESTURE_DOWN, + LogoDown = MICROBIT_ACCELEROMETER_EVT_TILT_DOWN, /** * Raised when the screen is pointing down and the board is horizontal */ //% block="screen up" - ScreenUp = GESTURE_FACE_UP, + ScreenUp = MICROBIT_ACCELEROMETER_EVT_FACE_UP, /** * Raised when the screen is pointing up and the board is horizontal */ //% block="screen down" - ScreenDown = GESTURE_FACE_DOWN, + ScreenDown = MICROBIT_ACCELEROMETER_EVT_FACE_DOWN, /** * Raised when the screen is pointing left */ //% block="tilt left" - TiltLeft = GESTURE_LEFT, + TiltLeft = MICROBIT_ACCELEROMETER_EVT_TILT_LEFT, /** * Raised when the screen is pointing right */ //% block="tilt right" - TiltRight = GESTURE_RIGHT, + TiltRight = MICROBIT_ACCELEROMETER_EVT_TILT_RIGHT, /** * Raised when the board is falling! */ //% block="free fall" - FreeFall = GESTURE_FREEFALL + FreeFall = MICROBIT_ACCELEROMETER_EVT_FREEFALL, + /** + * Raised when a 3G shock is detected + */ + //% block="3g" + ThreeG = MICROBIT_ACCELEROMETER_EVT_3G, + /** + * Raised when a 6G shock is detected + */ + //% block="6g" + SixG = MICROBIT_ACCELEROMETER_EVT_6G }; //% color=300 weight=99 @@ -104,7 +114,7 @@ namespace input { * @param button TODO * @param body TODO */ - //% help=input/on-button-pressed weight=85 + //% help=input/on-button-pressed weight=85 blockGap=8 //% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192" void onButtonPressed(Button button, Action body) { registerWithDal((int)button, MICROBIT_BUTTON_EVT_CLICK, body); @@ -114,9 +124,13 @@ namespace input { * Attaches code to run when the screen is facing up. * @param body TODO */ - //% help=input/on-gesture weight=84 + //% help=input/on-gesture weight=84 blockGap=8 //% blockId=device_gesture_event block="on |%NAME" icon="\uf135" void onGesture(Gesture gesture, Action body) { + if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3) + uBit.accelerometer.setRange(4); + else if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_6G && uBit.accelerometer.getRange() < 6) + uBit.accelerometer.setRange(8); registerWithDal(MICROBIT_ID_GESTURE, (int)gesture, body); } diff --git a/libs/microbit/input.ts b/libs/microbit/input.ts index 35393132..d54aa37f 100644 --- a/libs/microbit/input.ts +++ b/libs/microbit/input.ts @@ -1,7 +1,7 @@ /** * Events and data from sensors */ -//% color=300 weight=99 +//% color=#B4009E weight=99 namespace input { /** * Attaches code to run when the screen is facing up. diff --git a/libs/microbit/led.ts b/libs/microbit/led.ts index 0c556f5b..901404b2 100644 --- a/libs/microbit/led.ts +++ b/libs/microbit/led.ts @@ -1,14 +1,14 @@ /** * Control of the LED screen. */ -//% color=3 weight=35 -namespace led { +//% color=#5C2D91 weight=35 + namespace led { // what's the current high value let barGraphHigh = 0; // when was the current high value recorded let barGraphHighLast = 0; - + /** * Displays a vertical bar graph based on the `value` and `high` value. * If `high` is 0, the chart gets adjusted automatically. @@ -17,35 +17,35 @@ namespace led { */ //% help=/led/plot-bar-graph weight=20 //% blockId=device_plot_bar_graph block="plot bar graph of %value |up to %high" icon="\uf080" blockExternalInputs=true - export function plotBarGraph(value: number, high: number): void { + export function plotBarGraph(value: number, high: number): void { let now = input.runningTime(); serial.writeString(value.toString() + "\r\n"); value = Math.abs(value); - + if (high != 0) barGraphHigh = high; else if (value > barGraphHigh || now - barGraphHighLast > 5000) { barGraphHigh = value; barGraphHighLast = now; } - + barGraphHigh = Math.max(barGraphHigh, 16); - + let v = (value * 15) / barGraphHigh; let k = 0; - for(let y = 4; y >= 0; --y) { + for (let y = 4; y >= 0; --y) { for (let x = 0; x < 3; ++x) { if (k > v) { - unplot(2-x,y); - unplot(2+x,y); + unplot(2 - x, y); + unplot(2 + x, y); } else { - plot(2-x, y); - plot(2+x, y); + plot(2 - x, y); + plot(2 + x, y); } ++k; } - } + } } - + /** * Toggles a particular pixel * @param x TODO diff --git a/libs/microbit/music.ts b/libs/microbit/music.ts index 1a7197e9..779fa4b2 100644 --- a/libs/microbit/music.ts +++ b/libs/microbit/music.ts @@ -77,17 +77,17 @@ enum BeatFraction { /** * Generation of music tones through pin ``P0``. */ -//% color=52 weight=33 +//% color=#D83B01 weight=98 namespace music { - var beatsPerMinute: number = 120; + let beatsPerMinute: number = 120; /** * Plays a tone through pin ``P0`` for the given duration. - * @param frequency TODO - * @param ms TODO + * @param frequency pitch of the tone to play in Hertz (Hz) + * @param ms tone duration in milliseconds (ms) */ //% help=music/play-tone weight=90 - //% blockId=device_play_note block="play|tone (Hz) %note=device_note|for (ms) %duration=device_beat" icon="\uf025" blockGap=8 + //% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" icon="\uf025" blockGap=8 export function playTone(frequency: number, ms: number): void { pins.analogSetPitchPin(AnalogPin.P0); pins.analogPitch(frequency, ms); @@ -95,7 +95,7 @@ namespace music { /** * Plays a tone through pin ``P0``. - * @param frequency TODO + * @param frequency pitch of the tone to play in Hertz (Hz) */ //% help=music/ring-tone weight=80 //% blockId=device_ring block="ring tone (Hz)|%note=device_note" icon="\uf025" blockGap=8 @@ -106,7 +106,7 @@ namespace music { /** * Rests (plays nothing) for a specified time through pin ``P0``. - * @param ms TODO + * @param ms rest duration in milliseconds (ms) */ //% help=music/rest weight=79 //% blockId=device_rest block="rest(ms)|%duration=device_beat" @@ -117,16 +117,16 @@ namespace music { /** * Gets the frequency of a note. - * @param name TODO + * @param name the note name */ //% weight=50 help=music/note-frequency //% blockId=device_note block="%note" export function noteFrequency(name: Note): number { return name; } - + function init() { - if (beatsPerMinute <= 0) beatsPerMinute = 120; + if (beatsPerMinute <= 0) beatsPerMinute = 120; } /** diff --git a/libs/microbit/pins.cpp b/libs/microbit/pins.cpp index 20023570..bf031523 100644 --- a/libs/microbit/pins.cpp +++ b/libs/microbit/pins.cpp @@ -31,6 +31,11 @@ enum class AnalogPin { P10 = MICROBIT_ID_IO_P10, }; +enum class PulseValue { + High = MICROBIT_PIN_EVT_PULSE_HI, + Low = MICROBIT_PIN_EVT_PULSE_LO +}; + MicroBitPin *getPin(int id) { switch (id) { case MICROBIT_ID_IO_P0: return &uBit.io.P0; @@ -75,7 +80,6 @@ namespace pins { return getPin(id); } - /** * Read the specified pin or connector as either 0 or 1 * @param name pin to read from @@ -124,11 +128,34 @@ namespace pins { * @param name analog pin to set period to * @param micros period in micro seconds. eg:20000 */ - //% help=pins/analog-set-period weight=23 + //% help=pins/analog-set-period weight=23 blockGap=8 //% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros" void analogSetPeriod(AnalogPin name, int micros) { PINOP(setAnalogPeriodUs(micros)); } + + /** + * Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``. + */ + //% help=pins/on-pulsed weight=22 blockGap=8 + //% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse" + void onPulsed(DigitalPin name, PulseValue pulse, Action body) { + MicroBitPin* pin = getPin((int)name); + if (!pin) return; + + pin->eventOn(MICROBIT_PIN_EVENT_ON_PULSE); + registerWithDal((int)name, (int)pulse, body); + } + + /** + * Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulsed`` handler. + */ + //% help=pins/pulse-micros + //% blockId=pins_pulse_duration block="pulse duration (µs)" + //% weight=21 + int pulseDuration() { + return pxt::lastEvent.timestamp; + } /** * Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement). diff --git a/libs/microbit/pins.ts b/libs/microbit/pins.ts index 53da784f..3412b8e2 100644 --- a/libs/microbit/pins.ts +++ b/libs/microbit/pins.ts @@ -1,7 +1,7 @@ /** * Control currents in Pins for analog/digital signals, servos, i2c, ... */ -//% color=351 weight=30 +//% color=#A80000 weight=30 namespace pins { /** * Re-maps a number from one range to another. That is, a value of ``from low`` would get mapped to ``to low``, a value of ``from high`` to ``to high``, values in-between to values in-between, etc. @@ -11,7 +11,7 @@ namespace pins { * @param toLow the lower bound of the value's target range * @param toHigh the upper bound of the value's target range, eg: 4 */ - //% help=pins/map weight=15 + //% help=pins/map weight=22 //% blockId=math_map block="map %value|from low %fromLow|from high %fromHigh|to low %toLow|to high %toHigh" export function map(value: number, fromLow: number, fromHigh: number, toLow: number, toHigh: number): number { return ((value - fromLow) * (toHigh - toLow)) / (fromHigh - fromLow) + toLow; @@ -20,6 +20,8 @@ namespace pins { /** * Read one number from 7-bit I2C address. */ + //% help=pins/i2c-read-number blockGap=8 + //% blockId=pins_i2c_readnumber block="i2c read number|at address %address|of format %format=i2c_sizeof" weight=7 export function i2cReadNumber(address: number, format: NumberFormat): number { let buf = pins.i2cReadBuffer(address, pins.sizeOf(format)) return buf.getNumber(format, 0) @@ -28,6 +30,8 @@ namespace pins { /** * Write one number to a 7-bit I2C address. */ + //% help=pins/i2c-write-number + //% blockId=i2c_writenumber block="i2c write number|at address %address|with value %value|of format %format=i2c_sizeof" weight=6 export function i2cWriteNumber(address: number, value: number, format: NumberFormat): void { let buf = createBuffer(pins.sizeOf(format)) buf.setNumber(format, 0, value) @@ -37,6 +41,7 @@ namespace pins { /** * Get the size in bytes of specified number format. */ + //% export function sizeOf(format: NumberFormat) { switch (format) { case NumberFormat.Int8LE: diff --git a/libs/microbit/pxt.json b/libs/microbit/pxt.json index 47522623..9cd49852 100644 --- a/libs/microbit/pxt.json +++ b/libs/microbit/pxt.json @@ -27,7 +27,7 @@ "serial.cpp", "serial.ts", "buffer.cpp", - "storage.cpp" + "_locales/fr/strings.json" ], "public": true, "dependencies": {}, diff --git a/libs/microbit/serial.cpp b/libs/microbit/serial.cpp index bdd15adb..e08e0b99 100644 --- a/libs/microbit/serial.cpp +++ b/libs/microbit/serial.cpp @@ -1,5 +1,24 @@ #include "ksbit.h" +enum class SerialPin { + P0 = MICROBIT_ID_IO_P0, + P1 = MICROBIT_ID_IO_P1, + P2 = MICROBIT_ID_IO_P2, + P8 = MICROBIT_ID_IO_P8, + P12 = MICROBIT_ID_IO_P12, + P13 = MICROBIT_ID_IO_P13, + P14 = MICROBIT_ID_IO_P14, + P15 = MICROBIT_ID_IO_P15, + P16 = MICROBIT_ID_IO_P16 +}; + +enum class BaudRate { + //% block=115200 + BaudRate115200 = 115200, + //% block=9600 + BaudRate9600 = 9600 +}; + //% weight=2 color=30 namespace serial { // note that at least one // followed by % is needed per declaration! @@ -7,16 +26,46 @@ namespace serial { /** * Reads a line of text from the serial port. */ - //% - StringData* readString() { - return uBit.serial.readUntil(ManagedString("\r\n")).leakData(); + //% help=serial/read-line + //% blockId=serial_read_line block="serial read line" + //% weight=20 + StringData* readLine() { + return uBit.serial.readUntil(ManagedString("\n")).leakData(); } /** * Sends a piece of text through Serial connection. */ - //% blockId=serial_writestring block="serial write %text" + //% help=serial/write-string + //% weight=87 + //% blockId=serial_writestring block="serial write string %text" void writeString(StringData *text) { uBit.serial.send(ManagedString(text)); } -} + + /** + * Registers an event to be fired when one of the delimiter is matched + * @param delimiters the characters to match received characters against. eg:"\n" + */ + // help=serial/on-data-received + // weight=19 + void onDataReceived(StringData* delimiters, Action body) { + uBit.serial.eventOn(ManagedString(delimiters)); + registerWithDal(MICROBIT_ID_SERIAL, MICROBIT_SERIAL_EVT_DELIM_MATCH, body); + } + + /** + * Dynamically configuring the serial instance to use pins other than USBTX and USBRX. + * @param tx the new transmission pins + * @param rx the new reception pin + * @param baud the new baud rate. eg: 115200 + */ + //% weight=10 + //% help=serial/redirect + //% blockId=serial_redirect block="serial redirect to|TX %tx|RX %rx|at baud rate %rate" + //% blockExternalInputs=1 + void redirect(SerialPin tx, SerialPin rx, BaudRate rate) { + uBit.serial.redirect((PinName)tx, (PinName)rx); + uBit.serial.baud((int)rate); + } +} \ No newline at end of file diff --git a/libs/microbit/serial.ts b/libs/microbit/serial.ts index 39e86ac2..1e401af7 100644 --- a/libs/microbit/serial.ts +++ b/libs/microbit/serial.ts @@ -1,22 +1,24 @@ /** * Reading and writing data over a serial connection. */ -//% weight=2 color=30 +//% weight=2 color=#002050 namespace serial { /** * Prints a line of text to the serial * @param value to send over serial */ - //% help=serial/write-line + //% weight=90 + //% help=serial/write-line blockGap=8 //% blockId=serial_writeline block="serial|write line %text" export function writeLine(text: string): void { - writeString(text); - writeString("\r\n"); + writeString(text + "\r\n"); } /** * Prints a numeric value to the serial */ + //% help=serial/write-number + //% weight=89 blockGap=8 //% blockId=serial_writenumber block="serial|write number %value" export function writeNumber(value: number): void { writeString(value.toString()); @@ -27,13 +29,20 @@ namespace serial { * @param name name of the value stream, eg: x * @param value to write */ - //% weight=80 + //% weight=88 blockGap=8 //% help=serial/write-value - //% blockId=serial_writevalue block="serial|write line %name|= %value" + //% blockId=serial_writevalue block="serial|write value %name|= %value" export function writeValue(name: string, value: number): void { - writeString(name); - writeString(": "); - writeNumber(value); - writeLine(""); + writeString(name + ":" + value + "\r\n"); + } + + /** + * Registers an event to be fired when a line has been received + */ + // help=serial/on-line-received + // blockId=serial_on_line_received block="serial on line received" + // weight=21 blockGap=8 + export function onLineReceived(body: Action): void { + // serial.onDataReceived("\n", body); } } diff --git a/libs/microbit/shims.d.ts b/libs/microbit/shims.d.ts index c5fb8383..63e42849 100644 --- a/libs/microbit/shims.d.ts +++ b/libs/microbit/shims.d.ts @@ -4,7 +4,7 @@ /** * Creation, manipulation and display of LED images. */ - //% color=45 weight=31 + //% color=#5C2D91 weight=31 declare namespace images { /** @@ -32,15 +32,15 @@ declare interface Image { /** * Shows an frame from the image at offset ``x offset``. - * @param xOffset TODO + * @param xOffset column index to start displaying the image */ - //% help=images/show-image weight=80 async - //% BUGblockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8 xOffset.defl=0 shim=ImageMethods::showImage - showImage(xOffset?: number): void; + //% help=images/show-image weight=80 blockNamespace=images + //% blockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8 shim=ImageMethods::showImage + showImage(xOffset: number): void; /** * Draws the ``index``-th frame of the image on the screen. - * @param xOffset TODO + * @param xOffset column index to start displaying the image */ //% help=images/plot-frame weight=80 shim=ImageMethods::plotFrame plotFrame(xOffset: number): void; @@ -50,9 +50,9 @@ declare interface Image { * @param frameOffset x offset moved on each animation step, eg: 5, 1, -1 * @param interval time between each animation step in milli seconds, eg: 200 */ - //% help=images/show-image weight=79 async - //% BUGblockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8 frameOffset.defl=0 interval.defl=200 shim=ImageMethods::scrollImage - scrollImage(frameOffset?: number, interval?: number): void; + //% help=images/show-image weight=79 async blockNamespace=images + //% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8 shim=ImageMethods::scrollImage + scrollImage(frameOffset: number, interval: number): void; /** * Sets all pixels off. @@ -63,13 +63,13 @@ declare interface Image { /** * Sets a specific pixel brightness at a given position */ - //% help= shim=ImageMethods::setPixelBrightness + //% shim=ImageMethods::setPixelBrightness setPixelBrightness(x: number, y: number, value: number): void; /** * Gets the pixel brightness ([0..255]) at a given position */ - //% help= shim=ImageMethods::pixelBrightness + //% shim=ImageMethods::pixelBrightness pixelBrightness(x: number, y: number): number; /** @@ -81,7 +81,7 @@ declare interface Image { /** * Gets the height in rows (always 5) */ - //% shim= shim=ImageMethods::height + //% shim=ImageMethods::height height(): number; /** @@ -90,7 +90,7 @@ declare interface Image { * @param y TODO * @param value TODO */ - //% help=functions/set-pixel shim=ImageMethods::setPixel + //% help=images/set-pixel shim=ImageMethods::setPixel setPixel(x: number, y: number, value: boolean): void; /** @@ -98,14 +98,14 @@ declare interface Image { * @param x TODO * @param y TODO */ - //% help=functions/pixel shim=ImageMethods::pixel + //% help=images/pixel shim=ImageMethods::pixel pixel(x: number, y: number): boolean; /** * Shows a particular frame of the image strip. * @param frame TODO */ - //% weight=70 help=functions/show-frame shim=ImageMethods::showFrame + //% weight=70 help=images/show-frame shim=ImageMethods::showFrame showFrame(frame: number): void; } @@ -113,7 +113,7 @@ declare interface Image { /** * Provides access to basic micro:bit functionality. */ - //% color=190 weight=100 + //% color=#0078D7 weight=100 declare namespace basic { /** @@ -200,7 +200,7 @@ declare namespace input { * @param button TODO * @param body TODO */ - //% help=input/on-button-pressed weight=85 + //% help=input/on-button-pressed weight=85 blockGap=8 //% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192" shim=input::onButtonPressed function onButtonPressed(button: Button, body: () => void): void; @@ -208,7 +208,7 @@ declare namespace input { * Attaches code to run when the screen is facing up. * @param body TODO */ - //% help=input/on-gesture weight=84 + //% help=input/on-gesture weight=84 blockGap=8 //% blockId=device_gesture_event block="on |%NAME" icon="\uf135" shim=input::onGesture function onGesture(gesture: Gesture, body: () => void): void; @@ -332,17 +332,31 @@ declare namespace control { * @param value Component specific code indicating the cause of the event. * @param mode optional definition of how the event should be processed after construction (default is CREATE_AND_FIRE). */ - //% weight=21 blockGap=12 blockId="control_raise_event" block="raise event|from source %src=control_event_source|with value %value=control_event_value" blockExternalInputs=1 + //% weight=21 blockGap=12 blockId="control_raise_event" block="raise event|from source %src=control_event_source_id|with value %value=control_event_value_id" blockExternalInputs=1 //% mode.defl=1 shim=control::raiseEvent function raiseEvent(src: number, value: number, mode?: EventCreationMode): void; /** * Raises an event in the event bus. */ - //% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source|with value %value=control_event_value" + //% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source_id|with value %value=control_event_value_id" //% blockExternalInputs=1 shim=control::onEvent function onEvent(src: number, value: number, handler: () => void): void; + /** + * Gets the value of the last event executed on the bus + */ + //% blockId=control_event_value" block="event value" + //% weight=18 shim=control::eventValue + function eventValue(): number; + + /** + * Gets the timestamp of the last event executed on the bus + */ + //% blockId=control_event_timestamp" block="event timestamp" + //% weight=19 blockGap=8 shim=control::eventTimestamp + function eventTimestamp(): number; + /** * Gets a friendly name for the device derived from the its serial number */ @@ -469,10 +483,25 @@ declare namespace pins { * @param name analog pin to set period to * @param micros period in micro seconds. eg:20000 */ - //% help=pins/analog-set-period weight=23 + //% help=pins/analog-set-period weight=23 blockGap=8 //% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros" shim=pins::analogSetPeriod function analogSetPeriod(name: AnalogPin, micros: number): void; + /** + * Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``. + */ + //% help=pins/on-pulsed weight=22 blockGap=8 + //% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse" shim=pins::onPulsed + function onPulsed(name: DigitalPin, pulse: PulseValue, body: () => void): void; + + /** + * Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulsed`` handler. + */ + //% help=pins/pulse-micros + //% blockId=pins_pulse_duration block="pulse duration (µs)" + //% weight=21 shim=pins::pulseDuration + function pulseDuration(): number; + /** * Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement). * @param name pin to write to @@ -534,14 +563,30 @@ declare namespace serial { /** * Reads a line of text from the serial port. */ - //% shim=serial::readString - function readString(): string; + //% help=serial/read-line + //% blockId=serial_read_line block="serial read line" + //% weight=20 shim=serial::readLine + function readLine(): string; /** * Sends a piece of text through Serial connection. */ - //% blockId=serial_writestring block="serial write %text" shim=serial::writeString + //% help=serial/write-string + //% weight=87 + //% blockId=serial_writestring block="serial write string %text" shim=serial::writeString function writeString(text: string): void; + + /** + * Dynamically configuring the serial instance to use pins other than USBTX and USBRX. + * @param tx the new transmission pins + * @param rx the new reception pin + * @param baud the new baud rate. eg: 115200 + */ + //% weight=10 + //% help=serial/redirect + //% blockId=serial_redirect block="serial redirect to|TX %tx|RX %rx|at baud rate %rate" + //% blockExternalInputs=1 shim=serial::redirect + function redirect(tx: SerialPin, rx: SerialPin, rate: BaudRate): void; } @@ -597,37 +642,4 @@ declare interface Buffer { write(dstOffset: number, src: Buffer): void; } - - /** - * This allows reading and writing of small blocks of data to FLASH memory. - */ - //% weight=10 color=#cc6600 -declare namespace storage { - - /** - * Writes the key and buffer pair into FLASH. This operation is rather costly as all the key/value pairs - * have to be rewritten as well. - */ - //% shim=storage::putBuffer - function putBuffer(key: string, buffer: Buffer): void; - - /** - * Gets the buffer at the given key if any. If no key is available, empty buffer is returned. - */ - //% shim=storage::getBuffer - function getBuffer(key: string): Buffer; - - /** - * Removes an entry identified by the key. - */ - //% shim=storage::remove - function remove(key: string): void; - - /** - * The number of entries in the key value store - */ - //% shim=storage::size - function size(): number; -} - // Auto-generated. Do not edit. Really. diff --git a/libs/microbit/storage.cpp b/libs/microbit/storage.cpp deleted file mode 100644 index ef270df5..00000000 --- a/libs/microbit/storage.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "ksbit.h" - -/** -* This allows reading and writing of small blocks of data to FLASH memory. -*/ -//% weight=10 color=#cc6600 -namespace storage { - /** - * Writes the key and buffer pair into FLASH. This operation is rather costly as all the key/value pairs - * have to be rewritten as well. - */ - //% - void putBuffer(StringData* key, Buffer buffer) { - uBit.storage.put(ManagedString(key), ManagedBuffer(buffer).getBytes()); - } - - /** - * Gets the buffer at the given key if any. If no key is available, empty buffer is returned. - */ - //% - Buffer getBuffer(StringData* key) { - KeyValuePair* pv = uBit.storage.get(ManagedString(key)); - if (pv == NULL) return ManagedBuffer().leakData(); - - return ManagedBuffer(pv->value, sizeof(pv->value)).leakData(); - } - - /** - * Removes an entry identified by the key. - */ - //% - void remove(StringData * key) { - uBit.storage.remove(ManagedString(key)); - } - - /** - * The number of entries in the key value store - */ - //% - int size() { - return uBit.storage.size(); - } -} \ No newline at end of file diff --git a/libs/test-snippets/README.md b/libs/test-snippets/README.md new file mode 100644 index 00000000..ce4dd16c --- /dev/null +++ b/libs/test-snippets/README.md @@ -0,0 +1 @@ +run ``pxt testdir ../../buit/docs/blocks`` from this folder \ No newline at end of file diff --git a/libs/test-snippets/main.ts b/libs/test-snippets/main.ts new file mode 100644 index 00000000..e69de29b diff --git a/libs/test-snippets/pxt.json b/libs/test-snippets/pxt.json new file mode 100644 index 00000000..ba1ffa7a --- /dev/null +++ b/libs/test-snippets/pxt.json @@ -0,0 +1,13 @@ +{ + "name": "test-snippets", + "description": "A test project for doc snippets", + "installedVersion": "file:.", + "files": [ + "main.ts" + ], + "public": true, + "dependencies": { + "microbit": "file:../microbit", + "microbit-radio": "file:../microbit-radio" + } +} diff --git a/libs/tsconfig.json b/libs/tsconfig.json index 4a1a04d5..057a3b33 100644 --- a/libs/tsconfig.json +++ b/libs/tsconfig.json @@ -6,6 +6,6 @@ "outDir": "../built", "rootDir": ".", "newLine": "LF", - "sourceMap": true + "sourceMap": false } } diff --git a/olddocs/js/lessons/bounce-image.md b/olddocs/js/lessons/bounce-image.md index bc953445..3a772f2f 100644 --- a/olddocs/js/lessons/bounce-image.md +++ b/olddocs/js/lessons/bounce-image.md @@ -2,8 +2,6 @@ scroll an image across the screen. -### @video td/videos/bounce-image-0 - ## Topic Basic- Show Animation diff --git a/olddocs/js/lessons/bounce-image/challenges.md b/olddocs/js/lessons/bounce-image/challenges.md index 5c3b6ea9..5db6b044 100644 --- a/olddocs/js/lessons/bounce-image/challenges.md +++ b/olddocs/js/lessons/bounce-image/challenges.md @@ -24,8 +24,6 @@ basic.forever(() => { ### Challenge 1 -### @video td/videos/bounce-image-1 - Now, let's add frames to reverse the animation so it looks like the bar is bouncing off the right edge of the display. ``` @@ -60,9 +58,7 @@ input.onGesture(Gesture.Shake, () => { }) // *** ``` -**Challenge 3** - -### @video td/videos/bounce-image-2-3 +### Challenge 3 When the BBC micro:bit is shaken we want to show a new animation. Here is an example, but you can create your own. Be creative! diff --git a/olddocs/js/lessons/digital-pet.md b/olddocs/js/lessons/digital-pet.md index 19213a40..a31255c4 100644 --- a/olddocs/js/lessons/digital-pet.md +++ b/olddocs/js/lessons/digital-pet.md @@ -2,8 +2,6 @@ a display of pet images for the BBC micro:bit. -### @video td/videos/digital-pet-0 - ## Topic Functions diff --git a/olddocs/js/lessons/digital-pet/challenges.md b/olddocs/js/lessons/digital-pet/challenges.md index d81044d0..8b87cacc 100644 --- a/olddocs/js/lessons/digital-pet/challenges.md +++ b/olddocs/js/lessons/digital-pet/challenges.md @@ -41,8 +41,6 @@ basic.forever(() => { ### Challenge 2 -### @video td/videos/digital-pet-2 - Now we want to show your eating pet! Let's create a function called `set eat` that will do create an image. Store that image in a variable and then show it. ``` @@ -76,8 +74,6 @@ basic.forever(() => { ### Challenge 3 -### @video td/videos/digital-pet-3 - Have your pet tell you when it is going to sleep! Do this inside of the **IF** statement that checks if button `A` is pressed before you call the function `set sleep`. ``` @@ -97,8 +93,6 @@ basic.forever(() => { ### Challenge 4 -### @video td/videos/digital-pet-4 - Now, how about we keep track of how many times our pet eats? Add a global variable called `feed` that keeps track of how many times you feed your pet. If button `B` is pressed, increment `feed` by one. Add a condition `on shake` to check your total. ``` diff --git a/olddocs/js/lessons/flipping-bird/challenges.md b/olddocs/js/lessons/flipping-bird/challenges.md index 9735281e..0108fec6 100644 --- a/olddocs/js/lessons/flipping-bird/challenges.md +++ b/olddocs/js/lessons/flipping-bird/challenges.md @@ -50,8 +50,6 @@ input.onGesture(Gesture.Shake, () => { ### Challenge 2 -### @video td/videos/flipping-bird-2 - Inside of that `if` statement you created in challenge 1, add `basic->plot image()` and display an upside down flying bird. ``` diff --git a/olddocs/js/lessons/glowing-mountain/challenges.md b/olddocs/js/lessons/glowing-mountain/challenges.md index 1d51e651..da15ec76 100644 --- a/olddocs/js/lessons/glowing-mountain/challenges.md +++ b/olddocs/js/lessons/glowing-mountain/challenges.md @@ -4,8 +4,6 @@ These challenges will help you display a glowing image that fades in and out at **Challenge 0** -### @video vimeo/134649269 - [This guided tutorial](https://test.microbit.co.uk/td/lessons/glowing-mountain/tutorial) will teach you how to create a mountain that fades out. ``` @@ -37,9 +35,7 @@ basic.pause(1000) // *** * Run the code to see if it works as expected. -**Challenge 2** - -### @video vimeo/134674595 +### Challenge 2 After the pause, let's add `led->fade in(2000)` so that we can create a glowing effect. diff --git a/olddocs/js/lessons/glowing-sword.md b/olddocs/js/lessons/glowing-sword.md index 760bdd5f..bae73c16 100644 --- a/olddocs/js/lessons/glowing-sword.md +++ b/olddocs/js/lessons/glowing-sword.md @@ -2,8 +2,6 @@ make a glowing sword. -### @video td/videos/glowing-sword-0 - ## Topic Fade Out diff --git a/olddocs/js/lessons/glowing-sword/activity.md b/olddocs/js/lessons/glowing-sword/activity.md index d17c66ab..1f5bc850 100644 --- a/olddocs/js/lessons/glowing-sword/activity.md +++ b/olddocs/js/lessons/glowing-sword/activity.md @@ -4,8 +4,6 @@ Make glowing sword. ### ~avatar avatar -### @video td/videos/glowing-sword-0 - In this activity, we will learn how to fade in and out the screen to create a glowing animation. Let's get started! ### ~ diff --git a/olddocs/js/lessons/glowing-sword/challenges.md b/olddocs/js/lessons/glowing-sword/challenges.md index 6c2472ca..7fafb951 100644 --- a/olddocs/js/lessons/glowing-sword/challenges.md +++ b/olddocs/js/lessons/glowing-sword/challenges.md @@ -37,8 +37,6 @@ basic.pause(1000) // *** ### Challenge 2 -### @video td/videos/glowing-sword-2 - After the pause, let's add `led->fade in(2000)` so that we can create a glowing effect. ``` diff --git a/olddocs/js/lessons/jailbreak.md b/olddocs/js/lessons/jailbreak.md index 1ba45f2d..58040f0c 100644 --- a/olddocs/js/lessons/jailbreak.md +++ b/olddocs/js/lessons/jailbreak.md @@ -1,8 +1,6 @@ # jailbreak lesson -break out of a counting loop by pressing button "A". - -### @video td/videos/jailbreak-0 +Break out of a counting loop by pressing button "A". ## Topic diff --git a/olddocs/js/lessons/line-of-fire.md b/olddocs/js/lessons/line-of-fire.md index 730c5012..2eaa6eaa 100644 --- a/olddocs/js/lessons/line-of-fire.md +++ b/olddocs/js/lessons/line-of-fire.md @@ -1,8 +1,6 @@ # line of fire lesson -create a game that relies on precise instincts and timing reflexes #if #. - -### @video td/videos/timing-game-0 +Create a game that relies on precise instincts and timing reflexes #if #. ## Topic diff --git a/olddocs/js/lessons/logo-pointer/challenges.md b/olddocs/js/lessons/logo-pointer/challenges.md index e81c4602..2c3040dc 100644 --- a/olddocs/js/lessons/logo-pointer/challenges.md +++ b/olddocs/js/lessons/logo-pointer/challenges.md @@ -2,9 +2,7 @@ These challenges will help you show arrows that point which way the logo is pointing! #docs -**Challenge 0** - -### @video vimeo/134638098 +## Challenge 0 This [guided tutorial](/zysycw) will help you display an arrow pointing the direction the logo is oriented! @@ -42,9 +40,7 @@ input.onLogoDown(() => { }) // *** ``` -**Challenge 2** - -### @video vimeo/134639918 +## Challenge 2 Now we need to display the arrow! diff --git a/olddocs/js/lessons/looper/challenges.md b/olddocs/js/lessons/looper/challenges.md index b915deff..8836b5d4 100644 --- a/olddocs/js/lessons/looper/challenges.md +++ b/olddocs/js/lessons/looper/challenges.md @@ -19,8 +19,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 `8` instead of `6`. ``` @@ -34,8 +32,6 @@ for (let i1 = 0; i1 < 8; i1++) { ### Challenge 2 -### @video td/videos/looper-2 - What about 9? Let's do that by changing the ending value to `10`. ``` @@ -49,8 +45,6 @@ for (let i2 = 0; i2 < 10; i2++) { ### 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 `basic->show number`. ``` @@ -64,8 +58,6 @@ Run it on the simulator! ### Challenge 4 -### @video td/videos/looper-4 - Now, let's **count down from 9**. Change the line `basic->show number(i + 3, 150)` to `basic->show number(9 - i, 150)`. ``` diff --git a/olddocs/js/lessons/looper/lesson.md b/olddocs/js/lessons/looper/lesson.md index 6e99f25b..b9cb016c 100644 --- a/olddocs/js/lessons/looper/lesson.md +++ b/olddocs/js/lessons/looper/lesson.md @@ -2,8 +2,6 @@ Learn to control blinking LEDs. -### @video vimeo/134453504 - ## Topic For loop - Blinking LED diff --git a/olddocs/js/lessons/minesweeper.md b/olddocs/js/lessons/minesweeper.md index 2e8a6150..22df7175 100644 --- a/olddocs/js/lessons/minesweeper.md +++ b/olddocs/js/lessons/minesweeper.md @@ -2,8 +2,6 @@ A game that tests your memory for placing a LED mine then finding the hidden LED mine. -### @video td/videos/minesweeper-0 - ## Topic Global Variables diff --git a/olddocs/js/lessons/on-shake/challenges.md b/olddocs/js/lessons/on-shake/challenges.md index 30043a3e..868f510f 100644 --- a/olddocs/js/lessons/on-shake/challenges.md +++ b/olddocs/js/lessons/on-shake/challenges.md @@ -4,8 +4,6 @@ These challenges will allow you to create and display a flipping image of a bird ### Challenge 0 -### @video vimeo/134449611 - Greetings! This [guided tutorial](/lessons/flipping-bird/tutorial) will begin to show you how to flip a bird. ``` diff --git a/olddocs/js/lessons/pong.md b/olddocs/js/lessons/pong.md index 69af3a0b..95aec4c9 100644 --- a/olddocs/js/lessons/pong.md +++ b/olddocs/js/lessons/pong.md @@ -2,8 +2,6 @@ code your own game of Pong on the micro:bit. #. -### @video td/videos/pong-0 - ## Topic Functions diff --git a/olddocs/js/lessons/pong/activity.md b/olddocs/js/lessons/pong/activity.md index cce4f425..2f459fc6 100644 --- a/olddocs/js/lessons/pong/activity.md +++ b/olddocs/js/lessons/pong/activity.md @@ -4,8 +4,6 @@ Building a game of pong with sprites. ### ~avatar avatar -### @video td/videos/pong-0 - Welcome! This tutorial will teach you how to build a simple pong game using sprites. ### ~ diff --git a/olddocs/js/lessons/rectangle-explosion/challenges.md b/olddocs/js/lessons/rectangle-explosion/challenges.md index 3cb61522..d5f73b1d 100644 --- a/olddocs/js/lessons/rectangle-explosion/challenges.md +++ b/olddocs/js/lessons/rectangle-explosion/challenges.md @@ -4,8 +4,6 @@ These challenges will allow you to make an exploding rectangle. #docs **Challenge 0** -### @video vimeo/134649147 - This [guided tutorial](https://test.microbit.co.uk/td/lessons/rectangle-explosion/tutorial) will help you create a snowflake animation! ``` @@ -22,8 +20,6 @@ basic.forever(() => { **Challenge 1** -### @video vimeo/134649148 - Let's begin creating our falling effect by adding another snowflake with `show animation` that displays a different snowflake pattern after the first one. ``` @@ -47,8 +43,6 @@ basic.forever(() => { **Challenge 2** -### @video vimeo/134649149 - To finalize our snowflake fall, let's add a different snowflake pattern. ``` diff --git a/olddocs/js/lessons/screen-wipe/activity.md b/olddocs/js/lessons/screen-wipe/activity.md index 3f73bbdb..713886c7 100644 --- a/olddocs/js/lessons/screen-wipe/activity.md +++ b/olddocs/js/lessons/screen-wipe/activity.md @@ -4,8 +4,6 @@ Clear the screen by pressing buttons on the BBC 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 BBC micro:bit. ### ~ diff --git a/olddocs/js/lessons/screen-wipe/challenges.md b/olddocs/js/lessons/screen-wipe/challenges.md index d2d643e0..1e7ba2c2 100644 --- a/olddocs/js/lessons/screen-wipe/challenges.md +++ b/olddocs/js/lessons/screen-wipe/challenges.md @@ -40,8 +40,6 @@ input.onButtonPressed(Button.B, () => { **Challenge 2** -### @video td/videos/screen-wipe-2 - Replay the animation when the "B" button is pressed by typing in `basic->show animation(..., 400)`. ``` diff --git a/olddocs/js/lessons/set-brightness/challenges.md b/olddocs/js/lessons/set-brightness/challenges.md index 8abaf14e..3f8597a8 100644 --- a/olddocs/js/lessons/set-brightness/challenges.md +++ b/olddocs/js/lessons/set-brightness/challenges.md @@ -4,8 +4,6 @@ These challenges will allow you to change the brightness of the micro:bit. docs **Challenge 0** -### @video vimeo/133782335 - [This tutorial](/lessons/set-brightness/tutorial) will show you how to set the brightness on the micro:bit. ``` @@ -18,8 +16,6 @@ input.onButtonPressed(Button.A, () => { **Challenge 1** -### @video vimeo/133782335 - 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 a condition for `input->on button pressed("B")`. ``` diff --git a/olddocs/js/lessons/timing-game.md b/olddocs/js/lessons/timing-game.md index aabfa45a..aa6a41a0 100644 --- a/olddocs/js/lessons/timing-game.md +++ b/olddocs/js/lessons/timing-game.md @@ -2,8 +2,6 @@ make a game to test hand-eye coordination. -### @video td/videos/timing-game-0 - Make a game to test hand-eye coordination * [tutorial](/lessons/timing-game/tutorial) diff --git a/olddocs/js/lessons/transformers.md b/olddocs/js/lessons/transformers.md index 86645eb9..7e82c8ab 100644 --- a/olddocs/js/lessons/transformers.md +++ b/olddocs/js/lessons/transformers.md @@ -2,8 +2,6 @@ use functions to return values. -### @video td/videos/transformers-0 - ## Topic Return diff --git a/olddocs/js/lessons/transformers/challenges.md b/olddocs/js/lessons/transformers/challenges.md index c1b9726f..7aa97d3d 100644 --- a/olddocs/js/lessons/transformers/challenges.md +++ b/olddocs/js/lessons/transformers/challenges.md @@ -34,8 +34,6 @@ export function square(n: number) : number { ### Challenge 2 -### @video td/videos/transformers-2 - Add a condition for when button `B` is pressed. We will use this condition in the last challenge. ``` diff --git a/olddocs/js/lessons/while-counting/challenges.md b/olddocs/js/lessons/while-counting/challenges.md index 5fce6712..92652f43 100644 --- a/olddocs/js/lessons/while-counting/challenges.md +++ b/olddocs/js/lessons/while-counting/challenges.md @@ -4,8 +4,6 @@ These challenges will teach you how to create a counter 10 to 1. #docs **Challenge 0** -### @video vimeo/134459911 - [This guided tutorial](/lessons/digi-yoyo/tutorial) will teach you how to make a counter from 0-9 using a while loop. ``` @@ -53,8 +51,6 @@ while (count > 0) { **Challenge 3** -### @video vimeo/134449661 - Now, we need `count` to decrease by one after the micro:bit has displayed the value of `count`. We can do this by adding this line: diff --git a/olddocs/js/lessons/yes-no/challenges.md b/olddocs/js/lessons/yes-no/challenges.md index 5b4a7467..9da5dd37 100644 --- a/olddocs/js/lessons/yes-no/challenges.md +++ b/olddocs/js/lessons/yes-no/challenges.md @@ -12,8 +12,6 @@ basic.showString("ASK ME A QUESTION", 150) **Challenge 1** -### @video vimeo/134142879 - Now we need to reply after someone asks Micro 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`. ``` @@ -27,8 +25,6 @@ input.onButtonPressed(Button.A, () => { **Challenge 2** -### @video vimeo/134142673 - What if Micro'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`. ``` diff --git a/package.json b/package.json index 19255ff5..78de90b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pxt-microbit", - "version": "0.2.113", + "version": "0.2.141", "description": "BBC micro:bit target for PXT", "keywords": [ "JavaScript", @@ -29,6 +29,6 @@ "typescript": "^1.8.7" }, "dependencies": { - "pxt-core": "0.2.124" + "pxt-core": "0.2.153" } } diff --git a/pxtarget.json b/pxtarget.json index 6020ad55..659adfea 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -26,8 +26,8 @@ ] }, "files": { - "main.blocks": "Hello!", - "main.ts": "\n" + "main.blocks": "\n\n\n\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nTRUE\nFALSE\nTRUE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nTRUE\nFALSE\nFALSE\nFALSE\nTRUE\nFALSE\nTRUE\nTRUE\nTRUE\nFALSE\n\n\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\n\n\n\n\n\n", + "main.ts": "\r\n" } }, "tsprj": { @@ -44,7 +44,7 @@ ] }, "files": { - "main.ts": "basic.showString('Hello!')\n" + "main.ts": "basic.showLeds(`\r\n . . . . .\r\n . # . # .\r\n . . . . .\r\n # . . . #\r\n . # # # .\r\n `);" } }, "compile": { @@ -63,7 +63,10 @@ "aspectRatio": 1.22 }, "compileService": { - "gittag": "v0.1.8", + "yottaTarget": "bbc-microbit-classic-gcc", + "yottaCorePackage": "pxt-microbit-core", + "githubCorePackage": "microsoft/pxt-microbit-core", + "gittag": "v0.1.10", "serviceId": "ws" }, "serial": { @@ -72,7 +75,7 @@ "log": true }, "appTheme": { - "accentColor": "#5C2D91", + "accentColor": "#5C005C", "logoUrl": "https://m.pxt.io/about", "logo": "./static/microbit.simplified.svg", "docsLogo": "./static/microbit.simplified.svg", @@ -91,17 +94,22 @@ "path": "/about" }, { - "name": "Lessons", - "path": "/lessons" + "name": "Getting Started", + "path": "/getting-started" }, { "name": "Reference", "path": "/reference" }, + { + "name": "Lessons", + "path": "/lessons" + }, { "name": "Device", "path": "/device" } - ] + ], + "sideDoc": "getting-started" } } \ No newline at end of file diff --git a/sim/libmbit.ts b/sim/libmbit.ts index d0d7d19c..639dac66 100644 --- a/sim/libmbit.ts +++ b/sim/libmbit.ts @@ -187,7 +187,7 @@ namespace pxsim.basic { if (interval < 0) return; let leds = createImageFromString(x.toString()); - if (x < 0 || x >= 10) ImageMethods.scrollImage(leds, interval, 1); + if (x < 0 || x >= 10) ImageMethods.scrollImage(leds, 1, interval); else showLeds(leds, interval * 5); } @@ -198,7 +198,7 @@ namespace pxsim.basic { pause(interval * 5); } else { if (s.length == 1) showLeds(createImageFromString(s), interval * 5) - else ImageMethods.scrollImage(createImageFromString(s + " "), interval, 1); + else ImageMethods.scrollImage(createImageFromString(s + " "), 1, interval); } } @@ -211,8 +211,8 @@ namespace pxsim.basic { runtime.queueDisplayUpdate() } - export function showAnimation(leds: Image, interval: number = 400): void { - ImageMethods.scrollImage(leds, interval, 5); + export function showAnimation(leds: Image, interval: number): void { + ImageMethods.scrollImage(leds, 5, interval); } export function plotLeds(leds: Image): void { @@ -429,6 +429,19 @@ namespace pxsim.serial { export function readString(): string { return board().readSerial(); } + + export function readLine(): string { + return board().readSerial(); + } + + export function onDataReceived(delimiters: string, handler: RefAction) { + let b = board(); + b.bus.listen(DAL.MICROBIT_ID_SERIAL, DAL.MICROBIT_SERIAL_EVT_DELIM_MATCH, handler); + } + + export function redirect(tx: number, rx: number, rate: number) { + // TODO? + } } @@ -457,6 +470,10 @@ namespace pxsim.radio { board().radio.datagram.send([value]); } + export function sendString(msg: string): void { + board().radio.datagram.send(msg); + } + export function writeValueToSerial(): void { let b = board(); let v = b.radio.datagram.recv().data[0]; @@ -468,11 +485,23 @@ namespace pxsim.radio { } export function receiveNumber(): number { - return board().radio.datagram.recv().data[0]; + let buffer = board().radio.datagram.recv().data; + if (buffer instanceof Array) return buffer[0]; + + return 0; + } + + export function receiveString(): string { + let buffer = board().radio.datagram.recv().data; + if (typeof buffer === "string") return buffer; + return ""; } export function receivedNumberAt(index: number): number { - return board().radio.datagram.lastReceived.data[index] || 0; + let buffer = board().radio.datagram.recv().data; + if (buffer instanceof Array) return buffer[index] || 0; + + return 0; } export function receivedSignalStrength(): number { @@ -485,6 +514,13 @@ namespace pxsim.radio { } namespace pxsim.pins { + export function onPulse(name: number, pulse: number, body: RefAction) { + } + + export function pulseDuration(): number { + return 0; + } + export function digitalReadPin(pinId: number): number { let pin = getPin(pinId); if (!pin) return; @@ -638,10 +674,11 @@ namespace pxsim.ImageMethods { return i.get(x, y); } - export function scrollImage(leds: Image, interval: number, stride: number): void { + export function scrollImage(leds: Image, stride: number, interval: number): void { if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE); + if (stride == 0) stride = 1; - let cb = getResume() + let cb = getResume(); let off = stride > 0 ? 0 : leds.width - 1; let display = board().image; diff --git a/sim/simsvg.ts b/sim/simsvg.ts index ffe1ca4b..45110fa5 100644 --- a/sim/simsvg.ts +++ b/sim/simsvg.ts @@ -234,8 +234,8 @@ namespace pxsim.micro_bit { let t = Math.max(tmin, Math.min(tmax, state.temperature)) let per = Math.floor((state.temperature - tmin) / (tmax - tmin) * 100) - svg.setGradientValue(this.thermometerGradient, 100 - per + '%'); - this.thermometerText.textContent = t + '°C'; + svg.setGradientValue(this.thermometerGradient, 100 - per + "%"); + this.thermometerText.textContent = t + "°C"; } private updateHeading() { @@ -246,6 +246,7 @@ namespace pxsim.micro_bit { if (!this.headInitialized) { let p = this.head.firstChild.nextSibling as SVGPathElement; p.setAttribute("d", "m269.9,50.134647l0,0l-39.5,0l0,0c-14.1,0.1 -24.6,10.7 -24.6,24.8c0,13.9 10.4,24.4 24.3,24.7l0,0l39.6,0c14.2,0 40.36034,-22.97069 40.36034,-24.85394c0,-1.88326 -26.06034,-24.54606 -40.16034,-24.64606m-0.2,39l0,0l-39.3,0c-7.7,-0.1 -14,-6.4 -14,-14.2c0,-7.8 6.4,-14.2 14.2,-14.2l39.1,0c7.8,0 14.2,6.4 14.2,14.2c0,7.9 -6.4,14.2 -14.2,14.2l0,0l0,0z"); + this.updateTheme(); let pt = this.element.createSVGPoint(); svg.buttonEvents( this.head, @@ -253,13 +254,12 @@ namespace pxsim.micro_bit { let cur = svg.cursorPoint(pt, this.element, ev); state.heading = Math.floor(Math.atan2(cur.y - yc, cur.x - xc) * 180 / Math.PI + 90); if (state.heading < 0) state.heading += 360; - console.log('heading: ' + state.heading) this.updateHeading(); }); this.headInitialized = true; } - let txt = state.heading.toString() + '°'; + let txt = state.heading.toString() + "°"; if (txt != this.headText.textContent) { svg.rotateElement(this.head, xc, yc, state.heading + 180); this.headText.textContent = txt; @@ -273,7 +273,7 @@ namespace pxsim.micro_bit { let now = Date.now(); if (now - this.lastFlashTime > 150) { this.lastFlashTime = now; - svg.animate(this.systemLed, 'sim-flash') + svg.animate(this.systemLed, "sim-flash") } } @@ -437,6 +437,18 @@ svg.sim.grayscale { } /* animations */ +.sim-theme-glow { + animation-name: sim-theme-glow-animation; + animation-timing-function: ease-in-out; + animation-direction: alternate; + animation-iteration-count: infinite; + animation-duration: 1.25s; +} +@keyframes sim-theme-glow-animation { + from { opacity: 1; } + to { opacity: 0.75; } +} + .sim-flash { animation-name: sim-flash-animation; animation-duration: 0.1s; @@ -501,9 +513,9 @@ svg.sim.grayscale { // head this.head = svg.child(this.g, "g", {}); svg.child(this.head, "circle", { cx: 258, cy: 75, r: 100, fill: "transparent" }) - this.logos.push(svg.path(this.head, "sim-theme", "M269.9,50.2L269.9,50.2l-39.5,0v0c-14.1,0.1-24.6,10.7-24.6,24.8c0,13.9,10.4,24.4,24.3,24.7v0h39.6c14.2,0,24.8-10.6,24.8-24.7C294.5,61,284,50.3,269.9,50.2 M269.7,89.2L269.7,89.2l-39.3,0c-7.7-0.1-14-6.4-14-14.2c0-7.8,6.4-14.2,14.2-14.2h39.1c7.8,0,14.2,6.4,14.2,14.2C283.9,82.9,277.5,89.2,269.7,89.2")); - this.logos.push(svg.path(this.head, "sim-theme", "M230.6,69.7c-2.9,0-5.3,2.4-5.3,5.3c0,2.9,2.4,5.3,5.3,5.3c2.9,0,5.3-2.4,5.3-5.3C235.9,72.1,233.5,69.7,230.6,69.7")); - this.logos.push(svg.path(this.head, "sim-theme", "M269.7,80.3c2.9,0,5.3-2.4,5.3-5.3c0-2.9-2.4-5.3-5.3-5.3c-2.9,0-5.3,2.4-5.3,5.3C264.4,77.9,266.8,80.3,269.7,80.3")); + this.logos.push(svg.path(this.head, "sim-theme sim-theme-glow", "M269.9,50.2L269.9,50.2l-39.5,0v0c-14.1,0.1-24.6,10.7-24.6,24.8c0,13.9,10.4,24.4,24.3,24.7v0h39.6c14.2,0,24.8-10.6,24.8-24.7C294.5,61,284,50.3,269.9,50.2 M269.7,89.2L269.7,89.2l-39.3,0c-7.7-0.1-14-6.4-14-14.2c0-7.8,6.4-14.2,14.2-14.2h39.1c7.8,0,14.2,6.4,14.2,14.2C283.9,82.9,277.5,89.2,269.7,89.2")); + this.logos.push(svg.path(this.head, "sim-theme sim-theme-glow", "M230.6,69.7c-2.9,0-5.3,2.4-5.3,5.3c0,2.9,2.4,5.3,5.3,5.3c2.9,0,5.3-2.4,5.3-5.3C235.9,72.1,233.5,69.7,230.6,69.7")); + this.logos.push(svg.path(this.head, "sim-theme sim-theme-glow", "M269.7,80.3c2.9,0,5.3-2.4,5.3-5.3c0-2.9-2.4-5.3-5.3-5.3c-2.9,0-5.3,2.4-5.3,5.3C264.4,77.9,266.8,80.3,269.7,80.3")); this.headText = svg.child(this.g, "text", { x: 310, y: 100, class: "sim-text" }) // https://www.microbit.co.uk/device/pins @@ -567,9 +579,10 @@ svg.sim.grayscale { svg.path(this.g, "sim-label", "M35.7,376.4c0-2.8,2.1-5.1,5.5-5.1c3.3,0,5.5,2.4,5.5,5.1v4.7c0,2.8-2.2,5.1-5.5,5.1c-3.3,0-5.5-2.4-5.5-5.1V376.4zM43.3,376.4c0-1.3-0.8-2.3-2.2-2.3c-1.3,0-2.1,1.1-2.1,2.3v4.7c0,1.2,0.8,2.3,2.1,2.3c1.3,0,2.2-1.1,2.2-2.3V376.4z"); svg.path(this.g, "sim-label", "M136.2,374.1c2.8,0,3.4-0.8,3.4-2.5h2.9v14.3h-3.4v-9.5h-3V374.1z"); svg.path(this.g, "sim-label", "M248.6,378.5c1.7-1,3-1.7,3-3.1c0-1.1-0.7-1.6-1.6-1.6c-1,0-1.8,0.6-1.8,2.1h-3.3c0-2.6,1.8-4.6,5.1-4.6c2.6,0,4.9,1.3,4.9,4.3c0,2.4-2.3,3.9-3.8,4.7c-2,1.3-2.5,1.8-2.5,2.9h6.1v2.7h-10C244.8,381.2,246.4,379.9,248.6,378.5z"); - svg.path(this.g, "sim-label", "M48.1,270.9l-0.6-1.7h-5.1l-0.6,1.7h-3.5l5.1-14.3h3.1l5.2,14.3H48.1z M45,260.7l-1.8,5.9h3.5L45,260.7z"); - svg.path(this.g, "sim-label", "M449.1,135.8h5.9c3.9,0,4.7,2.4,4.7,3.9c0,1.8-1.4,2.9-2.5,3.2c0.9,0,2.6,1.1,2.6,3.3c0,1.5-0.8,4-4.7,4h-6V135.8zM454.4,141.7c1.6,0,2-1,2-1.7c0-0.6-0.3-1.7-2-1.7h-2v3.4H454.4z M452.4,144.1v3.5h2.1c1.6,0,2-1,2-1.8c0-0.7-0.4-1.8-2-1.8H452.4z") + svg.path(this.g, "sim-button-label", "M48.1,270.9l-0.6-1.7h-5.1l-0.6,1.7h-3.5l5.1-14.3h3.1l5.2,14.3H48.1z M45,260.7l-1.8,5.9h3.5L45,260.7z"); + svg.path(this.g, "sim-button-label", "M449.1,135.8h5.9c3.9,0,4.7,2.4,4.7,3.9c0,1.8-1.4,2.9-2.5,3.2c0.9,0,2.6,1.1,2.6,3.3c0,1.5-0.8,4-4.7,4h-6V135.8zM454.4,141.7c1.6,0,2-1,2-1.7c0-0.6-0.3-1.7-2-1.7h-2v3.4H454.4z M452.4,144.1v3.5h2.1c1.6,0,2-1,2-1.8c0-0.7-0.4-1.8-2-1.8H452.4z") + svg.path(this.g, "sim-label", "M352.1,381.1c0,1.6,0.9,2.5,2.2,2.5c1.2,0,1.9-0.9,1.9-1.9c0-1.2-0.6-2-2.1-2h-1.3v-2.6h1.3c1.5,0,1.9-0.7,1.9-1.8c0-1.1-0.7-1.6-1.6-1.6c-1.4,0-1.8,0.8-1.8,2.1h-3.3c0-2.4,1.5-4.6,5.1-4.6c2.6,0,5,1.3,5,4c0,1.6-1,2.8-2.1,3.2c1.3,0.5,2.3,1.6,2.3,3.5c0,2.7-2.4,4.3-5.2,4.3c-3.5,0-5.5-2.1-5.5-5.1H352.1z") svg.path(this.g, "sim-label", "M368.5,385.9h-3.1l-5.1-14.3h3.5l3.1,10.1l3.1-10.1h3.6L368.5,385.9z") svg.path(this.g, "sim-label", "M444.4,378.3h7.4v2.5h-1.5c-0.6,3.3-3,5.5-7.1,5.5c-4.8,0-7.5-3.5-7.5-7.5c0-3.9,2.8-7.5,7.5-7.5c3.8,0,6.4,2.3,6.6,5h-3.5c-0.2-1.1-1.4-2.2-3.1-2.2c-2.7,0-4.1,2.3-4.1,4.7c0,2.5,1.4,4.7,4.4,4.7c2,0,3.2-1.2,3.4-2.7h-2.5V378.3z") diff --git a/sim/state.ts b/sim/state.ts index e1452e48..1a4d3606 100644 --- a/sim/state.ts +++ b/sim/state.ts @@ -42,21 +42,21 @@ namespace pxsim { constructor(private runtime: Runtime) { } listen(id: number, evid: number, handler: RefAction) { - let k = id + ':' + evid; + let k = id + ":" + evid; let queue = this.queues[k]; if (!queue) queue = this.queues[k] = new EventQueue(this.runtime); queue.handler = handler; } queue(id: number, evid: number, value: number = 0) { - let k = id + ':' + evid; + let k = id + ":" + evid; let queue = this.queues[k]; if (queue) queue.push(value); } } export interface PacketBuffer { - data: number[]; + data: number[] | string; rssi?: number; } @@ -77,10 +77,13 @@ namespace pxsim { } } - send(buffer: number[]) { + send(buffer: number[] | string) { + if (buffer instanceof String) buffer = buffer.slice(0, 32); + else buffer = buffer.slice(0, 8); + Runtime.postMessage({ - type: 'radiopacket', - data: buffer.slice(0, 8) + type: "radiopacket", + data: buffer }) } @@ -119,7 +122,7 @@ namespace pxsim { broadcast(msg: number) { Runtime.postMessage({ - type: 'eventbus', + type: "eventbus", id: DAL.MES_BROADCAST_GENERAL_ID, eventid: msg, power: this.power, @@ -128,21 +131,6 @@ namespace pxsim { } } - export enum BasicGesture { - GESTURE_NONE, - GESTURE_UP, - GESTURE_DOWN, - GESTURE_LEFT, - GESTURE_RIGHT, - GESTURE_FACE_UP, - GESTURE_FACE_DOWN, - GESTURE_FREEFALL, - GESTURE_3G, - GESTURE_6G, - GESTURE_8G, - GESTURE_SHAKE - }; - interface AccelerometerSample { x: number; y: number; @@ -196,8 +184,8 @@ namespace pxsim { export class Accelerometer { private sigma: number = 0; // the number of ticks that the instantaneous gesture has been stable. - private lastGesture: BasicGesture = BasicGesture.GESTURE_NONE; // the last, stable gesture recorded. - private currentGesture: BasicGesture = BasicGesture.GESTURE_NONE; // the instantaneous, unfiltered gesture detected. + private lastGesture: number = 0; // the last, stable gesture recorded. + private currentGesture: number = 0 // the instantaneous, unfiltered gesture detected. private sample: AccelerometerSample = { x: 0, y: 0, z: -1023 } private shake: ShakeHistory = { x: false, y: false, z: false, count: 0, shaken: 0, timer: 0 }; // State information needed to detect shake events. private pitch: number; @@ -250,7 +238,7 @@ namespace pxsim { * * @return A best guess of the current posture of the device, based on instantaneous data. */ - private instantaneousPosture(): BasicGesture { + private instantaneousPosture(): number { let force = this.instantaneousAccelerationSquared(); let shakeDetected = false; @@ -287,42 +275,42 @@ namespace pxsim { } if (this.shake.shaken) - return BasicGesture.GESTURE_SHAKE; + return DAL.MICROBIT_ACCELEROMETER_EVT_SHAKE; let sq = (n: number) => n * n if (force < sq(DAL.MICROBIT_ACCELEROMETER_FREEFALL_TOLERANCE)) - return BasicGesture.GESTURE_FREEFALL; + return DAL.MICROBIT_ACCELEROMETER_EVT_FREEFALL; if (force > sq(DAL.MICROBIT_ACCELEROMETER_3G_TOLERANCE)) - return BasicGesture.GESTURE_3G; + return DAL.MICROBIT_ACCELEROMETER_EVT_3G; if (force > sq(DAL.MICROBIT_ACCELEROMETER_6G_TOLERANCE)) - return BasicGesture.GESTURE_6G; + return DAL.MICROBIT_ACCELEROMETER_EVT_6G; if (force > sq(DAL.MICROBIT_ACCELEROMETER_8G_TOLERANCE)) - return BasicGesture.GESTURE_8G; + return DAL.MICROBIT_ACCELEROMETER_EVT_8G; // Determine our posture. if (this.getX() < (-1000 + DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE)) - return BasicGesture.GESTURE_LEFT; + return DAL.MICROBIT_ACCELEROMETER_EVT_TILT_LEFT; if (this.getX() > (1000 - DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE)) - return BasicGesture.GESTURE_RIGHT; + return DAL.MICROBIT_ACCELEROMETER_EVT_TILT_RIGHT; if (this.getY() < (-1000 + DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE)) - return BasicGesture.GESTURE_DOWN; + return DAL.MICROBIT_ACCELEROMETER_EVT_TILT_DOWN; if (this.getY() > (1000 - DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE)) - return BasicGesture.GESTURE_UP; + return DAL.MICROBIT_ACCELEROMETER_EVT_TILT_UP; if (this.getZ() < (-1000 + DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE)) - return BasicGesture.GESTURE_FACE_UP; + return DAL.MICROBIT_ACCELEROMETER_EVT_FACE_UP; if (this.getZ() > (1000 - DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE)) - return BasicGesture.GESTURE_FACE_DOWN; + return DAL.MICROBIT_ACCELEROMETER_EVT_FACE_DOWN; - return BasicGesture.GESTURE_NONE; + return 0; } updateGesture() { @@ -563,12 +551,12 @@ namespace pxsim { default: theme = pxsim.micro_bit.randomTheme(); } - console.log('setting up microbit simulator') + console.log("setting up microbit simulator") let view = new pxsim.micro_bit.MicrobitBoardSvg({ theme: theme, runtime: runtime }) - document.body.innerHTML = ''; // clear children + document.body.innerHTML = ""; // clear children document.body.appendChild(view.element); return Promise.resolve(); @@ -578,37 +566,42 @@ namespace pxsim { if (!runtime || runtime.dead) return; switch (msg.type || "") { - case 'eventbus': + case "eventbus": let ev = msg; this.bus.queue(ev.id, ev.eventid, ev.value); break; - case 'serial': - this.serialIn.push((msg).data || ''); + case "serial": + this.serialIn.push((msg).data || ""); break; - case 'radiopacket': + case "radiopacket": let packet = msg; - this.radio.datagram.queue({ data: packet.data || [], rssi: packet.rssi || 0 }) + this.radio.datagram.queue({ data: packet.data, rssi: packet.rssi || 0 }) break; } } readSerial() { - let v = this.serialIn.shift() || ''; + let v = this.serialIn.shift() || ""; return v; } - serialOutBuffer: string = ''; + kill() { + super.kill(); + AudioContextManager.stop(); + } + + serialOutBuffer: string = ""; writeSerial(s: string) { for (let i = 0; i < s.length; ++i) { let c = s[i]; this.serialOutBuffer += c; - if (c == '\n') { + if (c == "\n") { Runtime.postMessage({ - type: 'serial', + type: "serial", data: this.serialOutBuffer, id: runtime.id }) - this.serialOutBuffer = '' + this.serialOutBuffer = "" break; } } diff --git a/sim/tsconfig.json b/sim/tsconfig.json index 761e4ba9..007366f2 100644 --- a/sim/tsconfig.json +++ b/sim/tsconfig.json @@ -7,6 +7,6 @@ "out": "../built/sim.js", "rootDir": ".", "newLine": "LF", - "sourceMap": true + "sourceMap": false } } diff --git a/testconv.json b/testconv.json index 0ad55bff..ae8b3095 100644 --- a/testconv.json +++ b/testconv.json @@ -527,7 +527,6 @@ "tnvnko", "toqcgf", "tpdiyw", - "tpxxzl", "tqeddl", "tqhpqp", "tqwach", @@ -550,12 +549,10 @@ "vbcdot", "vbtmwf", "vcijrw", - "vcmhms", "vcoevo", "vcrvjm", "vcudrv", "vczceh", - "vezrot", "vfcwwr", "vftxlg", "vfusfw",