Compare commits
169 Commits
Author | SHA1 | Date | |
---|---|---|---|
5dbbc2266f | |||
2a22001e02 | |||
214ff25995 | |||
f4768d99ff | |||
8792f9fe36 | |||
3d45bef910 | |||
3de6b33163 | |||
3f1c03ea51 | |||
a4063d636d | |||
92b5b76171 | |||
51d285b0b0 | |||
4d8afdd3ae | |||
13b21ad275 | |||
d90a43a6d8 | |||
6fd14e718d | |||
c79f043529 | |||
3a676c7151 | |||
0023710209 | |||
0756091e8c | |||
8144df0023 | |||
b2137e2622 | |||
39b30c8ae1 | |||
1c5d6316cc | |||
6d4d681898 | |||
7053fd1490 | |||
e7a49acac0 | |||
d76cfb6e2e | |||
538f08052d | |||
b6fed71c58 | |||
6c86f98b66 | |||
26797545c6 | |||
3ce8aa1f47 | |||
8b46698f50 | |||
47401e947c | |||
718cc9d530 | |||
b83d777144 | |||
cfb9acea34 | |||
53189830a1 | |||
67da22c135 | |||
7c7014a25f | |||
851f395ec9 | |||
a343cbd065 | |||
a2c042f715 | |||
a4a97f31cb | |||
5bd6a384ae | |||
943393dfa3 | |||
7089aa9c54 | |||
bd9e456bc5 | |||
ea82d066c9 | |||
bb8338a0f0 | |||
b24b65abcd | |||
2cc0523f9a | |||
a78f7f9601 | |||
b1cf3246ae | |||
24eb6f64db | |||
0c99eaf7bf | |||
8eb3376cf5 | |||
b863d5663d | |||
aeb4cb6a17 | |||
fd88e0b7f0 | |||
ea0d2d4d02 | |||
adff537013 | |||
19fc284884 | |||
5d9f85828d | |||
9f31637000 | |||
8e811b913e | |||
269254796d | |||
46995cbd54 | |||
380488528f | |||
aca863f436 | |||
a1ec25fd79 | |||
3e9d6d5895 | |||
719370f6b0 | |||
2780497d4f | |||
3eeaf2eddc | |||
eb3e91420c | |||
38cd913020 | |||
9159c297a5 | |||
851687dba8 | |||
28b8006ec5 | |||
271128c075 | |||
a04ca0d715 | |||
8b89fe721d | |||
1baf04b1fd | |||
6c7f0f911c | |||
f2008f9263 | |||
62127f7269 | |||
740cedd978 | |||
4278ff2b37 | |||
e7bea34d95 | |||
825409b697 | |||
8f72ac0094 | |||
8a6bb610e3 | |||
94dc141062 | |||
286dd1e50b | |||
6451d9add9 | |||
fd1dcde86b | |||
99947a9e21 | |||
a69239abed | |||
fd06fae050 | |||
7fbb056edf | |||
06758863fb | |||
ad8af16a5a | |||
70dd6bcac5 | |||
b103423a53 | |||
a82a44e587 | |||
e6f612283f | |||
fcd60876ab | |||
5daa9a0bb6 | |||
4fb3926073 | |||
73932f4619 | |||
c99138b02e | |||
64d584681a | |||
9788dd49cc | |||
9d15c4e270 | |||
fe7b06d763 | |||
0e0275e496 | |||
ffd4d96539 | |||
a6b4c9645a | |||
a9141d027f | |||
807e581c3d | |||
41a4dfeb68 | |||
4430391e87 | |||
81667f4df5 | |||
835048132c | |||
00217305c2 | |||
85e8a70f76 | |||
bbdf27de5a | |||
3e63d4083e | |||
d1b8e3c752 | |||
1164feb754 | |||
9ebd9d4f04 | |||
9fd2a3a3e6 | |||
7f40889103 | |||
ee37b4a959 | |||
99d05ec91b | |||
412e5bd034 | |||
141420d337 | |||
084f83ba1b | |||
8601eff170 | |||
5da4d74a2a | |||
4215574a7c | |||
da9d986a3e | |||
7481b9c24c | |||
de5def8dde | |||
dd011b977a | |||
20d0dd91ad | |||
825c6d57e7 | |||
b3edb81d3c | |||
78089da134 | |||
3aef765d35 | |||
f4727f12c9 | |||
a36cb65aa5 | |||
3b16e59ee1 | |||
f2c43c74ac | |||
1c4c93dc60 | |||
d73847bfba | |||
4e46682489 | |||
ab7aa00747 | |||
2bebb6056d | |||
22046c417c | |||
dc8afa6d45 | |||
22e2ab5ad9 | |||
f365726a8e | |||
e329b3bd2e | |||
d7b709e97b | |||
9714ec46e9 | |||
20ef54f565 | |||
e942fb5733 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -7,11 +7,15 @@ typings
|
||||
tmp
|
||||
temp
|
||||
projects/**
|
||||
clients/win10/app/AppPackages
|
||||
clients/win10/app/BundlePackages
|
||||
clients/win10/app/BundleArtifacts
|
||||
clients/win10/app/bin
|
||||
clients/win10/app/bld
|
||||
clients/win10/*.opendb
|
||||
clients/**/bin/**
|
||||
clients/**/obj/**
|
||||
clients/electron/projects
|
||||
|
||||
*.user
|
||||
*.sw?
|
||||
|
15
.vscode/settings.json
vendored
15
.vscode/settings.json
vendored
@ -1,5 +1,20 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"file.autoSave": "afterDelay",
|
||||
"files.watcherExclude": {
|
||||
"**/.git/objects/**": true,
|
||||
"**/built/**": true,
|
||||
"**/node_modules/**": true,
|
||||
"**/yotta_modules/**": true,
|
||||
"**/yotta_targets": true,
|
||||
"**/pxt_modules/**": true
|
||||
},
|
||||
"search.exclude": {
|
||||
"**/node_modules": true,
|
||||
"**/yotta_modules/**": true,
|
||||
"**/yotta_targets": true,
|
||||
"**/pxt_modules/**": true
|
||||
},
|
||||
"tslint.enable": true,
|
||||
"tslint.rulesDirectory": "node_modules/tslint-microsoft-contrib"
|
||||
}
|
67
clients/electron/main.js
Normal file
67
clients/electron/main.js
Normal file
@ -0,0 +1,67 @@
|
||||
const electron = require('electron')
|
||||
// Module to control application life.
|
||||
const app = electron.app
|
||||
// Module to create native browser window.
|
||||
const BrowserWindow = electron.BrowserWindow
|
||||
// pxt toolchain
|
||||
const pxt = require('pxt-core')
|
||||
|
||||
// Keep a global reference of the window object, if you don't, the window will
|
||||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
let mainWindow
|
||||
|
||||
function createWindow() {
|
||||
console.log('starting app...')
|
||||
// Create the browser window.
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800, height: 600,
|
||||
webPreferences: {
|
||||
nodeIntegration: false,
|
||||
}
|
||||
})
|
||||
|
||||
ts.pxt.Util.debug = true;
|
||||
pxt.mainCli("C:/gh/pxt-microbit/clients/electron/node_modules/pxt-microbit", ["serve", "-just"]);
|
||||
|
||||
// no menu
|
||||
mainWindow.setMenu(null);
|
||||
|
||||
// and load the index.html of the app.
|
||||
mainWindow.loadURL(`http://localhost:3232/#local_token=08ba9b8f-6ccb-4202-296d-28fac7a553d9`)
|
||||
|
||||
// Open the DevTools.
|
||||
mainWindow.webContents.openDevTools()
|
||||
|
||||
// Emitted when the window is closed.
|
||||
mainWindow.on('closed', function () {
|
||||
// Dereference the window object, usually you would store windows
|
||||
// in an array if your app supports multi windows, this is the time
|
||||
// when you should delete the corresponding element.
|
||||
mainWindow = null
|
||||
})
|
||||
}
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.on('ready', createWindow)
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', function () {
|
||||
// On OS X it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
||||
app.on('activate', function () {
|
||||
// On OS X it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (mainWindow === null) {
|
||||
createWindow()
|
||||
}
|
||||
})
|
||||
|
||||
// In this file you can include the rest of your app's specific main process
|
||||
// code. You can also put them in separate files and require them here.
|
19
clients/electron/package.json
Normal file
19
clients/electron/package.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "codethemicrobit",
|
||||
"version": "0.1.0",
|
||||
"description": "A Blocks / JavaScript editor for the micro:bit",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"start": "electron ."
|
||||
},
|
||||
"author": "Microsoft",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"electron-prebuilt": "^1.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"typescript": "1.8.7",
|
||||
"pxt-core": "*",
|
||||
"pxt-microbit": "*"
|
||||
}
|
||||
}
|
@ -20,22 +20,18 @@
|
||||
<ProjectConfiguration Include="Release|AnyCPU">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>AnyCPU</Platform>
|
||||
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|ARM">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>ARM</Platform>
|
||||
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x86">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x86</Platform>
|
||||
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
|
BIN
clients/win10/store/desktopblocks1366x768.png
Normal file
BIN
clients/win10/store/desktopblocks1366x768.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 172 KiB |
BIN
clients/win10/store/desktopjavascript1366x768.png
Normal file
BIN
clients/win10/store/desktopjavascript1366x768.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 121 KiB |
BIN
clients/win10/store/mobileblocks480x800.png
Normal file
BIN
clients/win10/store/mobileblocks480x800.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 54 KiB |
@ -5,8 +5,6 @@ VisualStudioVersion = 14.0.25123.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeTheMicrobit", "Microbit.Uploader\CodeTheMicrobit.csproj", "{7DC6CA45-FD75-44BC-805E-708C812CD4BF}"
|
||||
EndProject
|
||||
Project("{262852C6-CD72-467D-83FE-5EEB1973A190}") = "codethemicrobitapp", "..\win10\app\codethemicrobitapp.jsproj", "{39122940-AB16-4CD4-A0CE-79A3EB863ECF}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -35,30 +33,6 @@ Global
|
||||
{7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Release|x64.Build.0 = Release|Any CPU
|
||||
{7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Release|x86.Build.0 = Release|Any CPU
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|ARM.ActiveCfg = Debug|ARM
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|ARM.Build.0 = Debug|ARM
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|ARM.Deploy.0 = Debug|ARM
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|x64.Build.0 = Debug|x64
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|x64.Deploy.0 = Debug|x64
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|x86.Build.0 = Debug|x86
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|x86.Deploy.0 = Debug|x86
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|Any CPU.Deploy.0 = Release|Any CPU
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|ARM.ActiveCfg = Release|ARM
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|ARM.Build.0 = Release|ARM
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|ARM.Deploy.0 = Release|ARM
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|x64.ActiveCfg = Release|x64
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|x64.Build.0 = Release|x64
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|x64.Deploy.0 = Release|x64
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|x86.ActiveCfg = Release|x86
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|x86.Build.0 = Release|x86
|
||||
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|x86.Deploy.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -14,7 +14,7 @@ namespace Microsoft.MicroBit
|
||||
public LicenseDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.textBox.Rtf = Resources.MSR_LA___2576;
|
||||
this.textBox.Text = Resources.MSR_LA___2576;
|
||||
}
|
||||
|
||||
private void acceptButton_Click(object sender, EventArgs e)
|
||||
|
@ -32,7 +32,7 @@ namespace Microsoft.MicroBit
|
||||
private void openEditor()
|
||||
{
|
||||
// lanch editor
|
||||
try { Process.Start("https://codethemicrobit.com"); } catch (Exception) { }
|
||||
try { Process.Start("https://codethemicrobit.com#uploader"); } catch (Exception) { }
|
||||
}
|
||||
|
||||
private void initializeFileWatch()
|
||||
|
@ -34,7 +34,7 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("0.9.0.0")]
|
||||
[assembly: AssemblyFileVersion("0.9.0.0")]
|
||||
[assembly: AssemblyVersion("0.10.0.0")]
|
||||
[assembly: AssemblyFileVersion("0.10.0.0")]
|
||||
[assembly: CLSCompliant(true)]
|
||||
[assembly: NeutralResourcesLanguage("en-US")]
|
@ -81,8 +81,7 @@ namespace Microsoft.MicroBit.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to {\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff0\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f1\fbidi \fswiss\fcharset0\fprq2{\*\panose 020b0604020202020204}Arial;}
|
||||
///{\f2\fbidi \fmodern\fcharset0\fprq1{\*\panose 02070309020205020404}Courier New;}{\f3\fbidi \froman\fcharset2\fprq2{\*\panose 05050102010706020507}Symbol;}{\f10\fbidi \fnil\fcharset2\fp [rest of string was truncated]";.
|
||||
/// Looks up a localized string similar to TBD.
|
||||
/// </summary>
|
||||
internal static string MSR_LA___2576 {
|
||||
get {
|
||||
|
@ -118,13 +118,13 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="MSR_LA___2576" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\MSR-LA - 2576.rtf;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<data name="microbit_red" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\microbit.red.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="MSFT_logo_png" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\MSFT_logo_png.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="microbit_red" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\microbit.red.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
<data name="MSR_LA___2576" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\MSR-LA - 2576.rtf;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
||||
</data>
|
||||
</root>
|
@ -9,16 +9,16 @@ let execAsync: (cmd: string, options?: { cwd?: string }) => Promise<Buffer> = Pr
|
||||
let readDirAsync = Promise.promisify(fs.readdir)
|
||||
|
||||
|
||||
export function deployCoreAsync(res: ts.pxt.CompileResult) {
|
||||
export function deployCoreAsync(res: pxtc.CompileResult) {
|
||||
return getBitDrivesAsync()
|
||||
.then(drives => {
|
||||
if (drives.length == 0) {
|
||||
console.log("cannot find any drives to deploy to")
|
||||
} else {
|
||||
console.log(`copy ${ts.pxt.BINARY_HEX} to ` + drives.join(", "))
|
||||
console.log(`copy ${pxtc.BINARY_HEX} to ` + drives.join(", "))
|
||||
}
|
||||
return Promise.map(drives, d =>
|
||||
writeFileAsync(d + ts.pxt.BINARY_HEX, res.outfiles[ts.pxt.BINARY_HEX])
|
||||
writeFileAsync(d + pxtc.BINARY_HEX, res.outfiles[pxtc.BINARY_HEX])
|
||||
.then(() => {
|
||||
console.log("wrote hex file to " + d)
|
||||
}))
|
||||
|
@ -23,6 +23,8 @@ input.onButtonPressed(Button.B, () => {
|
||||
```
|
||||
# About
|
||||
|
||||
### @description A Blocks / Javascript code editor for the micro:bit, a pocket-size computer with 5x5 display, sensors and Bluetooth.
|
||||
|
||||
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).
|
||||
|
||||
|
@ -1,8 +1,14 @@
|
||||
# Blocks language
|
||||
|
||||
### @description Langugage constructs for the Block editor.
|
||||
|
||||
```namespaces
|
||||
for (let i = 0;i<5;++i) {}
|
||||
if (true){}
|
||||
let x = 0;
|
||||
Math.random(5);
|
||||
```
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
[logic](/blocks/logic), [loops](/blocks/loops), [math](/blocks/math), [variables](/blocks/variables)
|
@ -46,7 +46,7 @@ basic.showNumber(counter);
|
||||
|
||||
To change the contents of a variable use the assignment operator. The following code sets `counter` to 1 and then increments `counter` by 10:
|
||||
|
||||
```blocks
|
||||
```blocks
|
||||
let counter = 1;
|
||||
counter = counter + 10;
|
||||
basic.showNumber(counter);
|
||||
|
54
docs/code.md
Normal file
54
docs/code.md
Normal file
@ -0,0 +1,54 @@
|
||||
# Visual Studio Code
|
||||
|
||||
Visual Studio Code is a Free Open Source code editor that you can use to edit your programs.
|
||||
|
||||
Working from Visual Studio code allows you to benefit from all the features
|
||||
of a professional IDE while working with PXT: working with files,
|
||||
git integration (or source control of your choice), hundreds of extensions.
|
||||
|
||||

|
||||
|
||||
## Setup
|
||||
|
||||
Follow these instructions to setup your machine and edit your programs in Visual Studio Code.
|
||||
|
||||
* install [Visual Studio Code](https://code.visualstudio.com/)
|
||||
* install [Node.JS](https://nodejs.org/en/)
|
||||
* install the PXT Tools (on Mac or Linux, you might have to add ``sudo`` to the command).
|
||||
```
|
||||
pxt install -g pxt
|
||||
```
|
||||
* create a folder for your projects
|
||||
```
|
||||
mkdir microbit
|
||||
```
|
||||
* install the microbit target
|
||||
```
|
||||
pxt target microbit
|
||||
```
|
||||
|
||||
That's it! You are ready to create new projects in code or open existing projects.
|
||||
|
||||
## Creating a new project
|
||||
|
||||
Open a shell to your ``microbit`` folder.
|
||||
|
||||
```
|
||||
# create a new subfolder for your project
|
||||
mkdir myproject
|
||||
cd myproject
|
||||
# start the project set
|
||||
pxt init
|
||||
# open code
|
||||
code .
|
||||
```
|
||||
|
||||
## Opening an existing project
|
||||
|
||||
You can extract a project from the embedded URL or .hex file. Open a shell to your projects folder
|
||||
|
||||
```
|
||||
# extract the project from the URL
|
||||
pxt extract EMBEDURL
|
||||
```
|
||||
where ``EMBEDURL`` is the published project URL.
|
@ -9,7 +9,15 @@ Below is a list of error numbers and what they mean:
|
||||
* **10** (`MICROBIT_I2C_LOCKUP`): the micro:bit's I2C bus is not working
|
||||
* **20** (`MICROBIT_OOM`): there is no free memory on the micro:bit
|
||||
|
||||

|
||||
```sim
|
||||
basic.showLeds(`
|
||||
# . . . #
|
||||
# # . # #
|
||||
. . . . .
|
||||
. # # # .
|
||||
# . . . #
|
||||
`)
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
|
@ -48,41 +48,45 @@ The micro:bit’s *scheduler* provides the capability to concurrently execute di
|
||||
|
||||
The first job of the scheduler is to allow multiple *subprograms* to be queued up for later execution . For our purposes, a subprogram is just a statement or sequence of statements in the context of a larger program. Consider the Touch Develop program below for counting button presses.
|
||||
|
||||
```
|
||||
export function countButtonPresses() {
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
count = count + 1
|
||||
})
|
||||
basic.forever(() => {
|
||||
basic.showNumber(count, 150)
|
||||
})
|
||||
count = 0
|
||||
}
|
||||
```
|
||||
|
||||
The program above contains three statements that execute in order from top to bottom. The first statement
|
||||
|
||||
```
|
||||
```blocks
|
||||
let count = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
count = count + 1
|
||||
count++;
|
||||
})
|
||||
```
|
||||
|
||||
informs the scheduler that on each and every event of the A button being pressed, a subprogram (called the event handler) should be queued for execution. The event handler is demarcated by the do/end keywords; it increments the global variable `count` by one. The second statement
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.showNumber(count, 150)
|
||||
})
|
||||
```
|
||||
|
||||
queues a `forever` loop for later execution by the scheduler; the body of this loop (between the do/end keywords) displays the current value of global variable `count` on the LED screen. The third statement
|
||||
The program above contains three statements that execute in order from top to bottom.
|
||||
The first statement initializes the global variable `count` to zero.
|
||||
|
||||
```
|
||||
count = 0
|
||||
```blocks
|
||||
let count = 0
|
||||
```
|
||||
|
||||
initializes the global variable `count` to zero. The function ends after the execution of these three statements, but this is not the end of program execution! That’s because the function queued the `forever` loop for execution by the scheduler.
|
||||
The second statement informs the scheduler that on each and every event of the A button being pressed, a subprogram (called the event handler) should be queued for execution. The event handler is demarcated by the do/end keywords; it increments the global variable `count` by one.
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
// ...
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
count++;
|
||||
})
|
||||
```
|
||||
|
||||
The third statement queues a `forever` loop for later execution by the scheduler; the body of this loop (between the do/end keywords) displays the current value of global variable `count` on the LED screen. The third statement
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
// ...
|
||||
basic.forever(() => {
|
||||
basic.showNumber(count, 150)
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
The function ends after the execution of these three statements, but this is not the end of program execution! That’s because the function queued the `forever` loop for execution by the scheduler.
|
||||
|
||||
The second job of the scheduler is to periodically interrupt execution to read (poll) the various inputs to the micro:bit (the buttons, pins, etc.) and fire off events (such as “button A pressed”). Recall that the firing of an event causes the event handler subprogram associated with that event to be queued for later execution. The scheduler uses a timer built into the micro:bit hardware to interrupt execution every 6 milliseconds and poll the inputs, which is more than fast enough to catch the quickest press of a button.
|
||||
|
||||
@ -96,9 +100,18 @@ If you hadn’t guessed already, a footballer represents subprogram and dribblin
|
||||
|
||||
We will call this “passing control of execution” rather than “passing the ball”. However, in the world of the micro:bit, the concurrently executing subprograms are not aware of each other, so they don’t actually pass control directly to one another. Rather they pass control of execution back to the scheduler and the scheduler determines the subprogram to pass control to next. The programmer inserts a call to the `pause` function to indicate a point in the subprogram where control of execution passes to the scheduler. Also, when a subprogram ends execution, control passes to the scheduler.
|
||||
|
||||
Let’s take a look at the implementation of the `forever` statement to see an example of cooperative scheduling:
|
||||
Let’s take a look at the implementation of the `basic.forever` function to see an example of cooperative scheduling:
|
||||
|
||||

|
||||
```typescript
|
||||
function forever(body: () => void) {
|
||||
control.inBackground(() => {
|
||||
while(true) {
|
||||
body()
|
||||
basic.pause(20)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
The `forever` loop actually is a function that takes a subprogram (an *Action* in Touch Develop) as a parameter. The function uses the `control -> in background` function of the micro:bit runtime to queue a `while true` loop for execution by the scheduler. The while loop has two statements. The first statement runs the subprogram represented by the `body` parameter. The second statement passes control to the scheduler (requesting to “sleep” for 20 milliseconds).
|
||||
|
||||
@ -128,15 +141,15 @@ Through this example, we have seen that the micro:bit scheduler enables you to c
|
||||
|
||||
As a result, you can easily add a new capability to the micro:bit by just adding a new subprogram. For example, if you want to add a reset feature to the counter program, all you need to do is add a new event handler for a press of button B that sets the global variable "count" to zero, as shown below:
|
||||
|
||||
```
|
||||
```typescript
|
||||
export function countButtonPressesWithReset() {
|
||||
let count = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
count = count + 1
|
||||
})
|
||||
basic.forever(() => {
|
||||
basic.showNumber(count, 150)
|
||||
})
|
||||
count = 0
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
count = 0
|
||||
})
|
||||
|
@ -40,7 +40,7 @@ Next, compile your script:
|
||||
|
||||
2. Open your script (find the script in **My Scripts** and click `Edit`).
|
||||
|
||||
3. Click `compile`. Your script is converted into a hex file that you can transfer and run on your micro:bit.
|
||||
3. Click **Download**. Your script is converted into a hex file that you can transfer and run on your micro:bit.
|
||||
|
||||
4. When prompted, choose to save the compiled file on your computer (or anywhere other than the micro:bit). Depending on which browser you are using, the download will adopt the download behaviour of that particular browser.
|
||||
|
||||
@ -66,13 +66,13 @@ A dialogue box will appear, asking whether you would like to open or save your h
|
||||
|
||||
**IE10**
|
||||
|
||||
Click on compile. You will see a message “Do you want to save this .hex file.” Select **Save**.
|
||||
Click on **Download**. You will see a message “Do you want to save this .hex file.” Select **Save**.
|
||||
|
||||
### Mac
|
||||
|
||||
** Safari**
|
||||
|
||||
When you select **compile** in Safari on Mac, your file will be downloaded to your downloads folder. Go to your downloads folder and open the file. In Safari the file will appear as unknown.txt rather than a named .hex file. Drag and drop it onto your MICROBIT drive.
|
||||
When you select **Download** in Safari on Mac, your file will be downloaded to your downloads folder. Go to your downloads folder and open the file. In Safari the file will appear as unknown.txt rather than a named .hex file. Drag and drop it onto your MICROBIT drive.
|
||||
|
||||

|
||||
|
||||
@ -86,7 +86,7 @@ A dialogue box will appear, asking whether you would like to open or save your h
|
||||
|
||||
**Chrome**
|
||||
|
||||
When you select **compile** in Chrome, the file will be downloaded to the bottom of the browser in .hex format. Click on the small arrow and select **Show in Finder**. This will show the file in your download folder. Drag and drop the file onto your MICROBIT drive.
|
||||
When you select **Download** in Chrome, the file will be downloaded to the bottom of the browser in .hex format. Click on the small arrow and select **Show in Finder**. This will show the file in your download folder. Drag and drop the file onto your MICROBIT drive.
|
||||
|
||||

|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
# Documentation
|
||||
|
||||
### @description Links to the documentation, reference and projects.
|
||||
|
||||
### Things to do
|
||||
|
||||
* **[Getting Started](/getting-started)**
|
||||
@ -19,6 +21,7 @@
|
||||
### More questions?
|
||||
|
||||
* [Frequently Asked Question](/faq)
|
||||
* [Help Translate](/translate)
|
||||
* [Release notes](/release-notes)
|
||||
|
||||
### Developers
|
||||
|
21
docs/faq.md
21
docs/faq.md
@ -1,9 +1,30 @@
|
||||
# Frequently Asked Questions
|
||||
|
||||
### @description Frequently asked questions and answers from our users.
|
||||
|
||||
### Where can I get a BBC micro:bit?
|
||||
|
||||
More information at [http://uk.farnell.com/bbc-microbit](http://uk.farnell.com/bbc-microbit).
|
||||
|
||||
### How do I send feedback?
|
||||
|
||||
Find the small bubble icon on the bottom of the editor and
|
||||
post your feedback from there!
|
||||
|
||||
### How do I save my code?
|
||||
|
||||
The web editor automatically saves your code in the browser cache. Simply reopen the browser and navigate to the web editor
|
||||
to reopen your latest project. You can also open previous project stored locally through **More -> Open Project**.
|
||||
|
||||
The project source is also stored in each compiled ``.hex`` file. Drag and drop the ``.hex`` file into the web editor to load the project.
|
||||
|
||||
To share your project with others, you can use the **Embed** feature. It stores your project in the cloud and creates a URL that you can share with others.
|
||||
|
||||
If you are using [Visual Studio Code](/code), all your programs are stored as files on your computer and you can use your favorite source control system as needed.
|
||||
|
||||
## Is the web site available in other languages?
|
||||
|
||||
You can [help us translate](/translate) the web site, documentation and blocks via our crowd-source translations!
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
|
BIN
docs/favicon.ico
Normal file
BIN
docs/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
@ -1,5 +1,7 @@
|
||||
# Getting started
|
||||
|
||||
### @description An activity for beginners to get started with the micro:bit
|
||||
|
||||
## ~avatar
|
||||
|
||||
Here are some challenges for you. Arrange the blocks in the editor
|
||||
@ -33,7 +35,7 @@ When this program runs, you will see a smiley face, then a blank
|
||||
screen, then a smiley again -- it never stops! (That's because of the
|
||||
``forever`` block.)
|
||||
|
||||
Click **Compile** to move your program to the BBC micro:bit!
|
||||
Click **Download** to move your program to the BBC micro:bit!
|
||||
Make sure to follow the instructions.
|
||||
|
||||
### ~button /getting-started/screen
|
||||
|
@ -37,7 +37,7 @@ You can find the letter `B` by clicking the letter `A` on the
|
||||
|
||||
#### ~
|
||||
|
||||
Click **Compile** to move your program to the BBC micro:bit!
|
||||
Click **Download** to move your program to the BBC micro:bit!
|
||||
|
||||
#### Your turn!
|
||||
|
||||
@ -65,7 +65,7 @@ input.onPinPressed(TouchPin.P0, () => {
|
||||
. . # . .`);
|
||||
});
|
||||
```
|
||||
Click **Compile** to move your program to the BBC micro:bit!
|
||||
Click **Download** to move your program to the BBC micro:bit!
|
||||
|
||||
## ~hint
|
||||
|
||||
|
@ -152,7 +152,7 @@ That's why you can use an ``else`` instead of an ``else if``.
|
||||
|
||||
Your game is ready!
|
||||
|
||||
Click **Compile** to move your program to the BBC micro:bit!
|
||||
Click **Download** to move your program to the BBC micro:bit!
|
||||
|
||||
Have fun!
|
||||
|
||||
@ -198,7 +198,7 @@ input.onButtonPressed(Button.B, () => {
|
||||
basic.showNumber(game.score())
|
||||
})
|
||||
```
|
||||
Click **Compile** to move your program to the BBC micro:bit!
|
||||
Click **Download** to move your program to the BBC micro:bit!
|
||||
|
||||
### ~button /projects
|
||||
NEXT: PROJECTS!
|
||||
|
@ -32,7 +32,7 @@ basic.forever(() => {
|
||||
`)
|
||||
});
|
||||
```
|
||||
Click **Compile** to move your program to the BBC micro:bit!
|
||||
Click **Download** to move your program to the BBC micro:bit!
|
||||
|
||||
### Your turn!
|
||||
|
||||
@ -85,7 +85,7 @@ basic.forever(() => {
|
||||
`)
|
||||
});
|
||||
```
|
||||
Click **Compile** to move your program to the BBC micro:bit!
|
||||
Click **Download** to move your program to the BBC micro:bit!
|
||||
|
||||
#### ~hint
|
||||
|
||||
|
@ -17,7 +17,7 @@ input.onGesture(Gesture.Shake, () => {
|
||||
# . . . #`);
|
||||
});
|
||||
```
|
||||
Click **Compile** to move your program to the BBC micro:bit!
|
||||
Click **Download** to move your program to the BBC micro:bit!
|
||||
|
||||
### ~button /getting-started/coin-flipper
|
||||
NEXT: COIN FLIPPER GAME
|
||||
|
@ -1,4 +1,4 @@
|
||||
# JavaScript and TypeScript
|
||||
# JavaScript
|
||||
|
||||
Visit the cards below to starting programming JavaScript and TypeScript with the micro:bit:
|
||||
|
||||
@ -34,3 +34,8 @@ Visit the cards below to starting programming JavaScript and TypeScript with the
|
||||
]
|
||||
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
[calling](/js/call), [sequencing](/js/sequence), [variables](/js/variables), [operators](/js/operators), [statements](/js/statements), [functions](/js/functions),
|
||||
[types](/js/types), [classes](/js/classes), [FAQ](/js/faq)
|
@ -49,7 +49,7 @@ basic.clearScreen()
|
||||
|
||||
It's a syntax error to have a left parenthesis without the "closing" right parenthesis:
|
||||
|
||||
```typescript
|
||||
```
|
||||
basic.clearScreen(
|
||||
```
|
||||
|
||||
|
@ -43,7 +43,7 @@ Of course, one of the most fundamental patterns in class-based programming is be
|
||||
|
||||
Let's take a look at an example:
|
||||
|
||||
```ts
|
||||
```ts-ignore
|
||||
class Animal {
|
||||
name: string;
|
||||
constructor(theName: string) { this.name = theName; }
|
||||
@ -105,7 +105,7 @@ In TypeScript, each member is `public` by default.
|
||||
You may still mark a member `public` explicitly.
|
||||
We could have written the `Animal` class from the previous section in the following way:
|
||||
|
||||
```ts
|
||||
```ts-ignore
|
||||
class Animal {
|
||||
public name: string;
|
||||
public constructor(theName: string) { this.name = theName; }
|
||||
@ -119,7 +119,7 @@ class Animal {
|
||||
|
||||
When a member is marked `private`, it cannot be accessed from outside of its containing class. For example:
|
||||
|
||||
```ts
|
||||
```ts-ignore
|
||||
class Animal {
|
||||
private name: string;
|
||||
constructor(theName: string) { this.name = theName; }
|
||||
@ -138,7 +138,7 @@ The same applies to `protected` members.
|
||||
|
||||
Let's look at an example to better see how this plays out in practice:
|
||||
|
||||
```ts
|
||||
```ts-ignore
|
||||
class Animal {
|
||||
private name: string;
|
||||
constructor(theName: string) { this.name = theName; }
|
||||
@ -174,7 +174,7 @@ Even though `Employee` also has a `private` member called `name`, it's not the o
|
||||
The `protected` modifier acts much like the `private` modifier with the exception that members
|
||||
declared `protected` can also be accessed by instances of deriving classes. For example,
|
||||
|
||||
```ts
|
||||
```ts-ignore
|
||||
class Person {
|
||||
protected name: string;
|
||||
constructor(name: string) { this.name = name; }
|
||||
@ -204,7 +204,7 @@ we can still use it from within an instance method of `Employee` because `Employ
|
||||
A constructor may also be marked `protected`.
|
||||
This means that the class cannot be instantiated outside of its containing class, but can be extended. For example,
|
||||
|
||||
```ts
|
||||
```ts-ignore
|
||||
class Person {
|
||||
protected name: string;
|
||||
protected constructor(theName: string) { this.name = theName; }
|
||||
@ -233,7 +233,7 @@ let john = new Person("John"); // Error: The 'Person' constructor is protected
|
||||
You can make properties readonly by using the `readonly` keyword.
|
||||
Readonly properties must be initialized at their declaration or in the constructor.
|
||||
|
||||
```ts
|
||||
```ts-ignore
|
||||
class Octopus {
|
||||
readonly name: string;
|
||||
readonly numberOfLegs: number = 8;
|
||||
@ -252,7 +252,7 @@ This turns out to be a very common practice.
|
||||
*Parameter properties* let you create and initialize a member in one place.
|
||||
Here's a further revision of the previous `Octopus` class using a parameter property:
|
||||
|
||||
```ts
|
||||
```ts-ignore
|
||||
class Octopus {
|
||||
readonly numberOfLegs: number = 8;
|
||||
constructor(readonly name: string) {
|
||||
|
@ -45,7 +45,7 @@ TypeScript can figure the return type out by looking at the return statements, s
|
||||
|
||||
In TypeScript, the number of arguments given to a function has to match the number of parameters the function expects.
|
||||
|
||||
```ts
|
||||
```ts-ignore
|
||||
function buildName(firstName: string, lastName: string) {
|
||||
return firstName + " " + lastName;
|
||||
}
|
||||
@ -60,7 +60,7 @@ When they do, their value is `undefined`.
|
||||
We can get this functionality in TypeScript by adding a `?` to the end of parameters we want to be optional.
|
||||
For example, let's say we want the last name parameter from above to be optional:
|
||||
|
||||
```ts
|
||||
```ts-ignore
|
||||
function buildName(firstName: string, lastName?: string) {
|
||||
if (lastName)
|
||||
return firstName + " " + lastName;
|
||||
@ -80,7 +80,7 @@ In TypeScript, we can also set a value that a parameter will be assigned if the
|
||||
These are called default-initialized parameters.
|
||||
Let's take the previous example and default the last name to `"Smith"`.
|
||||
|
||||
```ts
|
||||
```ts-ignore
|
||||
function buildName(firstName: string, lastName = "Smith") {
|
||||
return firstName + " " + lastName;
|
||||
}
|
||||
@ -115,7 +115,7 @@ Unlike plain optional parameters, default-initialized parameters don't *need* to
|
||||
If a default-initialized parameter comes before a required parameter, users need to explicitly pass `undefined` to get the default initialized value.
|
||||
For example, we could write our last example with only a default initializer on `firstName`:
|
||||
|
||||
```ts
|
||||
```ts-ignore
|
||||
function buildName(firstName = "Will", lastName: string) {
|
||||
return firstName + " " + lastName;
|
||||
}
|
||||
@ -134,7 +134,7 @@ In JavaScript, you can work with the arguments directly using the `arguments` va
|
||||
|
||||
In TypeScript, you can gather these arguments together into a variable:
|
||||
|
||||
```ts
|
||||
```ts-ignore
|
||||
function buildName(firstName: string, ...restOfName: string[]) {
|
||||
return firstName + " " + restOfName.join(" ");
|
||||
}
|
||||
@ -148,7 +148,7 @@ The compiler will build an array of the arguments passed in with the name given
|
||||
|
||||
The ellipsis is also used in the type of the function with rest parameters:
|
||||
|
||||
```ts
|
||||
```ts-ignore
|
||||
function buildName(firstName: string, ...restOfName: string[]) {
|
||||
return firstName + " " + restOfName.join(" ");
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ Another property of block-scoped variables is that they can't be read or written
|
||||
While these variables are "present" throughout their scope, all points up until their declaration are part of their *temporal dead zone*.
|
||||
This is just a sophisticated way of saying you can't access them before the `let` statement, and luckily TypeScript will let you know that.
|
||||
|
||||
```typescript
|
||||
```typescript-ignore
|
||||
a++; // illegal to use 'a' before it's declared;
|
||||
let a;
|
||||
```
|
||||
|
@ -1,5 +1,7 @@
|
||||
# Lessons
|
||||
|
||||
### @description Lessons to teach computer science and coding.
|
||||
|
||||
### @short Lessons
|
||||
|
||||
### ~column
|
||||
|
@ -42,7 +42,7 @@ We want the message "Press A!" to scroll across the BBC micro:bit, so right-clic
|
||||
|
||||

|
||||
|
||||
So, to recap: the `forever` block makes sure our code runs forever. The BBC micro:bit checks if the user is pressing the left button, if the user is not then the “Press the button!” message will scroll across the LEDs. If the user is pressing the button then the “hello, world!” message will scroll across the screen. Check this in the simulator or attach the BBC micro:bit to the computer then click **compile** to send the code onto the BBC micro:bit.
|
||||
So, to recap: the `forever` block makes sure our code runs forever. The BBC micro:bit checks if the user is pressing the left button, if the user is not then the “Press the button!” message will scroll across the LEDs. If the user is pressing the button then the “hello, world!” message will scroll across the screen. Check this in the simulator or attach the BBC micro:bit to the computer then click **Download** to send the code onto the BBC micro:bit.
|
||||
|
||||
## What is a condition?
|
||||
|
||||
|
@ -62,7 +62,7 @@ export function newAction() {
|
||||
|
||||
Now let's implement `PRESS PIN 0` in the main. Create a condition of `input->on pin pressed("P0")` that will add one to the score and calls the method `new action`.
|
||||
|
||||
```
|
||||
```blocks
|
||||
// **. . .**
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.showNumber(game.score(), 150) // ***
|
||||
|
@ -86,3 +86,7 @@ Have fun reviewing your simulation and analyze the acceleration by chart the Exc
|
||||
* The first person and second person take turns tilting the micro:bit in the "x" direction while the other player charts the data on the micro:bit!
|
||||
* Review and analyze the actual micro:bit device acceleration data on Excel
|
||||
* Display acceleration with y or z using plot bar graph by changing acceleration from "x" to "y" or "z"
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
@ -34,8 +34,7 @@ Let's code the third part of Happy Birthday!
|
||||
|
||||
To do this, you need to add blocks after the last line of the `play` blocks. We want to continue to adding musical chords with the `play` block. Then insert the appropriate chord blocks `G`, `E`, `C`, `B`, `A` to complete the third part of the song. Modify your code so that your code looks like this.
|
||||
|
||||
``` blocks
|
||||
|
||||
```blocks
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
|
||||
@ -57,8 +56,7 @@ music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
|
||||
basic.pause(100);
|
||||
|
||||
```
|
||||
```
|
||||
|
||||
* click *run * to see if the code works as expected.
|
||||
|
||||
|
@ -73,6 +73,7 @@ coll.push("cow")
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let coll: string[] = []
|
||||
let index = Math.random(coll.length)
|
||||
let word = coll[index]
|
||||
```
|
||||
|
@ -39,7 +39,7 @@ coll.push("cat")
|
||||
|
||||
## 4. Write the five (5) lines of code that will add the following five words to `data->coll`: puppy, clock, night, cat, cow.
|
||||
|
||||
```
|
||||
```ts
|
||||
let coll = (<string[]>[])
|
||||
```
|
||||
|
||||
|
@ -42,3 +42,7 @@ radio.onDataReceived(() => { })
|
||||
* learn how to conditionally run code depending on whether a condition is true or not
|
||||
* learn how to run code when an input button is pressed
|
||||
* learn how to pause your code for the specified number of milliseconds
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
@ -162,3 +162,7 @@ radio.onDataReceived(() => {
|
||||
Connect the first micro:bit to your computer using your USB cable and run the pogo script on it.
|
||||
Connect the second micro:bit to your computer using your USB cable and run the pogo script on it.
|
||||
The first person and second person take turns jumping in the “y” direction while the other player uses the micro:bit to track the results on the micro:bit!
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
@ -33,3 +33,7 @@ radio.receiveNumber();
|
||||
* learn how to return the sum of the two numbers
|
||||
* learn how to get acceleration value in milli-gravitys
|
||||
* learn how to read the connector value as analog as a value comprised between 0 and 1023
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
@ -92,7 +92,7 @@ Connect a micro:bit to your computer using your USB cable
|
||||
|
||||

|
||||
|
||||
Click or tap the compile button for the seismograph program to run the program on the micro:bit.
|
||||
Click or tap the **Download** button for the seismograph program to run the program on the micro:bit.
|
||||
|
||||

|
||||
|
||||
|
@ -116,7 +116,7 @@ Connect the 2nd micro:bit to your computer using your USB cable. We should have
|
||||
|
||||
## 8.
|
||||
|
||||
Click or tap the compile button for the seismograph program to run the program on the 1st micro:bit and 2nd micro:bit.
|
||||
Click or tap the **Download** button for the seismograph program to run the program on the 1st micro:bit and 2nd micro:bit.
|
||||
|
||||
## 9.
|
||||
|
||||
@ -195,4 +195,6 @@ Let's select Style 10 as an example.
|
||||
* The first person and second person take shaking or moving the micor:bit in any direction while the other player charts the data on the micro:bit!
|
||||
* Review and analyze the actual micro:bit device acceleration data on Excel
|
||||
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
@ -2,8 +2,18 @@
|
||||
|
||||
The editor is open source on GitHub under the MIT license. Contributions are welcome, please check our GitHub repos.
|
||||
|
||||
### Repos
|
||||
## Source Code
|
||||
|
||||
* [microsoft/pxt-microbit](https://github.com/Microsoft/pxt-microbit), PXT target for BBC micro:bit, also includes the documentation.
|
||||
* [microbit/pxt](https://github.com/Microsoft/pxt), programming experience toolkit (PXT)
|
||||
* [microsoft/pxt-microbit-core](https://github.com/Microsoft/pxt-microbit-core), Yotta module used to build the BBC micro:bit runtime
|
||||
|
||||
## C++ Runtime
|
||||
|
||||
The [C++ micro:bit runtime](http://lancaster-university.github.io/microbit-docs/), created at [Lancaster University](http://www.lancaster.ac.uk/), provides access to the hardware functions of the micro:bit,
|
||||
as well as a set of helper functions (such as displaying a number/image/string on the LED screen).
|
||||
|
||||
## Packages
|
||||
|
||||
* [microsoft/pxt-neopixel](https://github.com/microsoft/pxt-neopixel), package for neopixel strips
|
||||
* [microsoft/pxt-max6675](https://github.com/microsoft/pxt-max6675), package for Temperature Probe (MAX6675)
|
@ -1,14 +1,19 @@
|
||||
# Extensions
|
||||
# Packages
|
||||
|
||||
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.
|
||||
|
||||
* [pxt-max6675](https://github.com/Microsoft/pxt-max6675) -- TypeScript
|
||||
* [pxt-neopixel](https://github.com/Microsoft/pxt-neopixel) -- TypeScript + ARM Thumb assembly package
|
||||
* [pxt-sonar](https://github.com/microsoft/pxt-sonar) -- TypeScript
|
||||
* [pxt-i2c-fram](https://github.com/microsoft/pxt-i2c-fram) -- TypeScript
|
||||
|
||||
* [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
|
||||
## Finding packages
|
||||
|
||||
From the editor, the user clicks on **More** then **Add Package** and searches for the package.
|
||||
|
||||
@ -16,11 +21,11 @@ To see the list of packages, click on **More** then **Show Files** to see the pr
|
||||
|
||||
To remove a package, click on the garbage button in the file list next to the package.
|
||||
|
||||
## Publishing libraries
|
||||
## Publishing packages
|
||||
|
||||
Packages can be published from the pxt command line. We are still sorting out the details.
|
||||
Packages can be published from the pxt command line. Check out [the docs](https://www.pxt.io/packages).
|
||||
|
||||
## Localizing libraries
|
||||
## Localizing packages
|
||||
|
||||
It is possible to package localization strings for the **jsDoc** description associated to the API in the package.
|
||||
|
||||
|
@ -47,5 +47,6 @@ Here are some cool projects that you can build with your micro:bit!
|
||||
}]
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
|
||||
[Flashing Heart](/projects/flashing-heart), [Smiley Buttons](/projects/smiley-buttons), [Love Meter](/projects/love-meter), [Rock Paper Scissors](/projects/rock-paper-scissors), [Compass](/projects/compass), [Hack your headphones](/projects/hack-your-headphones), [Banana keyboard](/projects/banana-keyboard), [Telegraph](/projects/telegraph), [Radio](/projects/radio), [Watch](/projects/the-watch)
|
@ -69,7 +69,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
});
|
||||
```
|
||||
|
||||
* click *compile* and run your code on the micro:bit.
|
||||
* click **Download** and run your code on the micro:bit.
|
||||
|
||||
### ~button /projects/banana-keyboard
|
||||
NEXT: Banana Keyboard
|
||||
|
65
docs/projects/messenger.md
Normal file
65
docs/projects/messenger.md
Normal file
@ -0,0 +1,65 @@
|
||||
# messenger
|
||||
|
||||

|
||||
|
||||
Use the radio to create an app that sends "YO" messages.
|
||||
|
||||
## Step 1
|
||||
|
||||
Use [on button pressed](/reference/input/on-button-pressed) to send the number "0" over radio.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
radio.sendNumber(0);
|
||||
});
|
||||
```
|
||||
|
||||
## Step 2
|
||||
|
||||
Use [radio on data received](/reference/radio/on-data-received) display "YO" when the number ``0`` is received
|
||||
by radio.
|
||||
|
||||
```blocks
|
||||
let message = 0;
|
||||
radio.onDataReceived(() => {
|
||||
message = radio.receiveNumber();
|
||||
if (message == 0) {
|
||||
basic.showString("YO")
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Download the program and **upload the same .hex file to 2 devices!**
|
||||
|
||||
## Step 3
|
||||
|
||||
Use [on button pressed](/reference/input/on-button-pressed) to send the number "1" over radio.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
radio.sendNumber(1);
|
||||
});
|
||||
```
|
||||
|
||||
## Step 4
|
||||
|
||||
Add blocks in [radio on data received](/reference/radio/on-data-received) to display "BYE" when the number ``1`` is received
|
||||
by radio.
|
||||
|
||||
```blocks
|
||||
let message = 0;
|
||||
radio.onDataReceived(() => {
|
||||
message = radio.receiveNumber();
|
||||
if (message == 0) {
|
||||
basic.showString("YO")
|
||||
}
|
||||
if (message == 1) {
|
||||
basic.showString("BYE")
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
@ -89,4 +89,8 @@ Have fun reviewing your simulation and analyze the acceleration by chart the Exc
|
||||
|
||||
### ~button /projects/the-watch
|
||||
NEXT: The Watch
|
||||
### ~
|
||||
### ~
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
@ -1,12 +1,12 @@
|
||||
# telegraph activity
|
||||
|
||||
Build a telgraph.
|
||||
Build a telegraph.
|
||||
|
||||
# micro:bit telegraph
|
||||
|
||||
Have you ever tried to communicate through a telegraph? Let's try coding a "Telegraph" on two BBC micro:bits !
|
||||
|
||||
Complete the following [guided tutorial](/projects/telegraph), your hack should look like this:
|
||||
Complete the following [tutorial](/projects/telegraph), your hack should look like this:
|
||||
|
||||

|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
# Reference
|
||||
|
||||
### @description List of API categories available in the editors
|
||||
|
||||
```namespaces
|
||||
basic.showNumber(0);
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
@ -30,6 +32,11 @@ bluetooth.onBluetoothConnected(() => {});
|
||||
```
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
microbit-devices
|
||||
microbit-bluetooth
|
||||
```
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
[basic](/reference/basic), [input](/reference/input), [music](/reference/music), [led](/reference/led), [Math (blocks)](/blocks/math), [String](/reference/types/string), [game](/reference/game), [images](/reference/images), [pins](/reference/pins), [serial](/reference/serial), [control](/reference/control), [radio](/reference/radio), [devices](/reference/devices), [bluetooth](/reference/bluetooth)
|
||||
|
@ -3,3 +3,7 @@
|
||||
```cards
|
||||
String.fromCharCode(0);
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
[fromCharCode](/reference//math/string-from-char-code)
|
||||
|
@ -32,3 +32,7 @@ basic.showAnimation(`
|
||||
. . . . .
|
||||
`);
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
[showNumber](/reference/basic/show-number), [showLeds](/reference/basic/show-leds), [showString](/reference/basic/show-string), [clearScreen](/reference/basic/clear-screen), [forever](/reference/basic/forever), [pause](/reference/basic/pause), [plotLeds](/reference/basic/plot-leds), [showAnimation](/reference/basic/show-animation)
|
||||
|
@ -23,7 +23,7 @@ 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.
|
||||
|
||||
```
|
||||
```blocks
|
||||
basic.showAnimation(`
|
||||
. . # . . . # # # . . # # # .
|
||||
. # # . . . . . # . . . . # .
|
||||
@ -47,7 +47,7 @@ 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.
|
||||
|
||||
```
|
||||
```blocks
|
||||
basic.showAnimation(`
|
||||
. . . . . # . . . . . . . . . . . . . # . . . . . # . . . .
|
||||
. . # . . . . . . . . . # . . . . . . . . . # . . . . . . .
|
||||
|
@ -22,3 +22,7 @@ bluetooth.onBluetoothDisconnected(() => {
|
||||
```package
|
||||
microbit-bluetooth
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
[startAccelerometerService](/reference/bluetooth/start-accelerometer-service), [startButtonService](/reference/bluetooth/start-button-service), [startIOPinService](/reference/bluetooth/start-io-pin-service), [startLEDService](/reference/bluetooth/start-led-service), [startMagnetometerService](/reference/bluetooth/start-magnetometer-service), [startTemperatureService](/reference/bluetooth/start-temperature-service), [uartRead](/reference/bluetooth/uart-read), [uartWrite](/reference/bluetooth/uart-write), [onBluetoothConnected](/reference/bluetooth/on-bluetooth-connected), [onBluetoothDisconnected](/reference/bluetooth/on-bluetooth-disconnected)
|
||||
|
@ -7,4 +7,9 @@ control.inBackground(() => {
|
||||
|
||||
});
|
||||
control.reset();
|
||||
control.waitMicros(4);
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
[inBackground](/reference/control/in-background), [reset](/reference/control/reset), [wait-micros](/reference/control/wait-micros)
|
||||
|
32
docs/reference/control/wait-micros.md
Normal file
32
docs/reference/control/wait-micros.md
Normal file
@ -0,0 +1,32 @@
|
||||
# WaitMicros
|
||||
|
||||
Blocks the current fiber for the given amount of micro-seconds.
|
||||
|
||||
```sig
|
||||
control.waitMicros(4)
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
This program sends a 10 micro-second HIGH pulse through pin ``P0``.
|
||||
|
||||
```blocks
|
||||
// ensure pin is low to send a clean pulse
|
||||
pins.digitalWritePin(DigitalPin.P0, 0)
|
||||
control.waitMicros(2)
|
||||
// set pin to 1 and wait 10 micros
|
||||
pins.digitalWritePin(DigitalPin.P0, 1)
|
||||
control.waitMicros(10)
|
||||
// finish pulse
|
||||
pins.digitalWritePin(DigitalPin.P0, 0)
|
||||
```
|
||||
|
||||
#### ~hint
|
||||
|
||||
This function is not supported in the simulator.
|
||||
|
||||
#### ~
|
||||
|
||||
### See Also
|
||||
|
||||
[pause](/reference/basic/pause)
|
@ -17,3 +17,11 @@ devices.onSignalStrengthChanged(() => {
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
```package
|
||||
microbit-devices
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
[tellCameraTo](/reference/devices/tell-camera-to), [tellRemoteControlTo](/reference/devices/tell-remote-control-to), [raiseAlertTo](/reference/devices/raise-alert-to), [onNotified](/reference/devices/on-notified), [onGamepadButton](/reference/devices/on-gamepad-button), [signalStrength](/reference/devices/signal-strength), [onSignalStrengthChanged](/reference/devices/on-signal-strength-changed)
|
||||
|
38
docs/reference/devices/on-notified.md
Normal file
38
docs/reference/devices/on-notified.md
Normal file
@ -0,0 +1,38 @@
|
||||
# On Signal Strength Changed
|
||||
|
||||
Register code to run when the signal strength of the paired device changes.
|
||||
|
||||
### ~hint
|
||||
|
||||
The functions in the ``devices`` namespace allow the BBC micro:bit to communicate with a separate (remote) device,
|
||||
such as a smartphone, over Bluetooth (Smart).
|
||||
The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device.
|
||||
|
||||
### ~
|
||||
|
||||
|
||||
```sig
|
||||
devices.onNotified(MesDeviceInfo.IncomingCall, () => {})
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``body``: code to run when the signal strength changes.
|
||||
|
||||
### Examples
|
||||
|
||||
Display the signal strength on screen:
|
||||
|
||||
```blocks
|
||||
devices.onNotified(MesDeviceInfo.IncomingCall, () => {
|
||||
basic.showString("RING RING")
|
||||
})
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
[tell remote control to](/reference/devices/tell-remote-control-to), [raise alert to](/reference/devices/raise-alert-to), [signal strength](/reference/devices/signal-strength)
|
||||
|
||||
```package
|
||||
microbit-devices
|
||||
```
|
@ -23,7 +23,7 @@ devices.onSignalStrengthChanged(() => {})
|
||||
|
||||
Display the signal strength on screen:
|
||||
|
||||
```
|
||||
```blocks
|
||||
devices.onSignalStrengthChanged(() => {
|
||||
basic.showNumber(devices.signalStrength(), 150)
|
||||
})
|
||||
|
@ -1,47 +0,0 @@
|
||||
# tell microphone to
|
||||
|
||||
The tell microphone to function.
|
||||
|
||||
Access the audio recording capabilities of the device using the ``tell microphone to`` function.
|
||||
|
||||
The functions in the antenna namespace allow the BBC micro:bit to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart). The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device.
|
||||
|
||||
### Block Editor
|
||||
|
||||

|
||||
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
export function tellMicrophoneTo(event: string)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* event - an event identifier
|
||||
|
||||
### Event values
|
||||
|
||||
* play
|
||||
* stop
|
||||
* pause
|
||||
* forward
|
||||
* rewind
|
||||
* volume up
|
||||
* volume down
|
||||
* previous track
|
||||
* next track
|
||||
|
||||
### Examples
|
||||
|
||||
To tell the connected device to start recording audio
|
||||
|
||||
```
|
||||
devices.tellMicrophoneTo("start capture")
|
||||
```
|
||||
|
||||
To tell the connected device to stop recording audio
|
||||
|
||||
```
|
||||
devices.tellMicrophoneTo("stop capture")
|
||||
```
|
@ -9,3 +9,7 @@ game.startCountdown(10000);
|
||||
game.gameOver();
|
||||
game.setScore(0);
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
[addScore](/reference/game/change-score-by), [score](/reference/game/score), [startCountdown](/reference/game/start-countdown), [gameOver](/reference/game/game-over), [setScore](/reference/game/set-score)
|
||||
|
@ -6,7 +6,7 @@ Turn off all the pixels in an [Image](/reference/images/image).
|
||||
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
```sig
|
||||
export function clear(img: micro_bit.Image)
|
||||
```
|
||||
|
||||
@ -18,7 +18,7 @@ export function clear(img: micro_bit.Image)
|
||||
|
||||
The following example turns off the pixels of `img` when the A input button is pressed:
|
||||
|
||||
```
|
||||
```blocks
|
||||
let img = images.createImage(`
|
||||
. . . . .
|
||||
. # # # .
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
Reports the x position of a sprite on the LED screen
|
||||
|
||||
```
|
||||
```sig
|
||||
export function x(_this: micro_bitSprites.LedSprite) : number
|
||||
```
|
||||
|
||||
Reports the y position of a sprite on the LED screen
|
||||
|
||||
```
|
||||
```sig
|
||||
export function y(_this: micro_bitSprites.LedSprite) : number
|
||||
```
|
||||
|
@ -4,24 +4,24 @@ Reports the x or y position, the current direction of a sprite, or the brightne
|
||||
|
||||
Reports the x position of a sprite on the LED screen
|
||||
|
||||
```
|
||||
```sig
|
||||
export function x(_this: micro_bitSprites.LedSprite) : number
|
||||
```
|
||||
|
||||
Reports the y position of a sprite on the LED screen
|
||||
|
||||
```
|
||||
```sig
|
||||
export function y(_this: micro_bitSprites.LedSprite) : number
|
||||
```
|
||||
|
||||
Reports the brightness of a sprite on the LED screen
|
||||
|
||||
```
|
||||
```sig
|
||||
export function brightness(_this: micro_bitSprites.LedSprite) : number
|
||||
```
|
||||
|
||||
Reports the current direction of a sprite on the LED screen
|
||||
|
||||
```
|
||||
```sig
|
||||
export function direction(_this: micro_bitSprites.LedSprite) : number
|
||||
```
|
||||
|
30
docs/reference/game/set-score.md
Normal file
30
docs/reference/game/set-score.md
Normal file
@ -0,0 +1,30 @@
|
||||
# Set Score
|
||||
|
||||
Sets the current score.
|
||||
|
||||
```sig
|
||||
game.setScore(1)
|
||||
```
|
||||
### Parameters
|
||||
|
||||
* a [number](/reference/types/number) that represents the new score.
|
||||
|
||||
### Examples
|
||||
|
||||
This program is a simple game.
|
||||
Press button ``A`` as much as possible to increase the score.
|
||||
Press ``B`` to display the score and reset the score.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.showNumber(game.score())
|
||||
game.setScore(0)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
[score](/reference/game/score), [start countdown](/reference/game/start-countdown)
|
@ -18,3 +18,7 @@ images.createBigImage(`
|
||||
. . . . .
|
||||
`);
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
[createImage](/reference/images/create-image), [createBigImage](/reference/images/create-big-image)
|
||||
|
@ -6,7 +6,7 @@ Get the state of a pixel in an [Image](/reference/images/image).
|
||||
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
```sig
|
||||
export function pixel(_this: micro_bit.Image, x: number, y: number) : boolean
|
||||
```
|
||||
|
||||
@ -29,7 +29,7 @@ This example gets the state of pixel `0, 0` in the `img` variable:
|
||||
|
||||
### ~hide
|
||||
|
||||
```
|
||||
```blocks
|
||||
let img = images.createImage(`
|
||||
. . # . . . . . . .
|
||||
. # . # . . . # . .
|
||||
@ -41,7 +41,7 @@ let img = images.createImage(`
|
||||
|
||||
### ~
|
||||
|
||||
```
|
||||
```typescript-ignore
|
||||
let state = img.pixel(0, 0)
|
||||
```
|
||||
|
||||
|
@ -6,7 +6,7 @@ Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](
|
||||
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
```sig
|
||||
export function plotFrame(_this: micro_bit.Image, index: number)
|
||||
```
|
||||
|
||||
@ -20,7 +20,7 @@ The `plot frame` function takes the index of the frame (if there are two frames,
|
||||
|
||||
### Example
|
||||
|
||||
```
|
||||
```blocks
|
||||
let img = images.createImage(`
|
||||
# . . . # # . . . #
|
||||
. # . # . . # # # .
|
||||
|
@ -6,7 +6,7 @@ Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](
|
||||
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
```sig
|
||||
export function plotImage(_this: micro_bit.Image, xOffset: number)
|
||||
```
|
||||
|
||||
@ -20,7 +20,7 @@ The `show image` function has a built in delay of 400ms after display of the ima
|
||||
|
||||
### Example
|
||||
|
||||
```
|
||||
```blocks
|
||||
let img = images.createImage(`
|
||||
# . . . # # . . . #
|
||||
. # . # . . # # # .
|
||||
|
@ -6,7 +6,7 @@ Set the on/off state of pixel in an [Image](/reference/images/image).
|
||||
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
```sig
|
||||
export function setPixel(_this: micro_bit.Image, x: number, y: number, value: boolean)
|
||||
```
|
||||
|
||||
@ -24,7 +24,7 @@ To figure out the ``x``, ``y`` coordinates, see [LED screen](/device/screen).
|
||||
|
||||
The following example creates an image and stores it in the `img` variable. The `set pixel` function sets the centre pixel off, before `img` is shown using `show image`.
|
||||
|
||||
```
|
||||
```blocks
|
||||
let img = images.createImage(`
|
||||
. . # . .
|
||||
. # . # .
|
||||
|
@ -6,7 +6,7 @@ Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](
|
||||
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
```sig
|
||||
export function showFrame(img: micro_bit.Image, frame: number)
|
||||
```
|
||||
|
||||
@ -20,7 +20,7 @@ The `show frame` function is the same as [plot frame](/reference/images/plot-fra
|
||||
|
||||
### Example
|
||||
|
||||
```
|
||||
```blocks
|
||||
let img = images.createImage(`
|
||||
# . . . # # . . . #
|
||||
. # . # . . # # # .
|
||||
|
@ -20,7 +20,7 @@ The following example gets the width of `img` and stores it in the `w` variable:
|
||||
|
||||
### ~hide
|
||||
|
||||
```
|
||||
```blocks
|
||||
let img = images.createImage(`
|
||||
. . # . . . . . . .
|
||||
. # . # . . . # . .
|
||||
@ -32,7 +32,7 @@ let img = images.createImage(`
|
||||
|
||||
### ~
|
||||
|
||||
```
|
||||
```typescript-ignore
|
||||
let w = img.width()
|
||||
```
|
||||
|
||||
@ -40,7 +40,7 @@ let w = img.width()
|
||||
|
||||
The following example uses the `width` function with a [for](/blocks/loops/for) loop to show each image frame on the screen:
|
||||
|
||||
```
|
||||
```typescript
|
||||
let img2 = images.createImage(`
|
||||
. . # . . . # # # # . # # # .
|
||||
. # # . . . . . . # . . . # .
|
||||
|
@ -39,3 +39,7 @@ input.onShake(() => {
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
[onButtonPressed](/reference/input/on-button-pressed), [onGesture](/reference/input/on-gesture), [onPinPressed](/reference/input/on-pin-pressed), [buttonIsPressed](/reference/input/button-is-pressed), [compassHeading](/reference/input/compass-heading), [pinIsPressed](/reference/input/pin-is-pressed), [temperature](/reference/input/temperature), [acceleration](/reference/input/acceleration), [lightLevel](/reference/input/light-level), [rotation](/reference/input/rotation), [magneticForce](/reference/input/magnetic-force), [runningTime](/reference/input/running-time), [setAccelerometerRange](/reference/input/set-accelerometer-range), [calibrate](/reference/input/calibrate), [onLogoDown](/reference/input/on-logo-down), [onLogoUp](/reference/input/on-logo-up), [onScreenDown](/reference/input/on-screen-down), [onScreenUp](/reference/input/on-screen-up), [onShake](/reference/input/on-shake)
|
||||
|
48
docs/reference/input/on-pin-released.md
Normal file
48
docs/reference/input/on-pin-released.md
Normal file
@ -0,0 +1,48 @@
|
||||
# On Pin Released
|
||||
|
||||
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 you release pin `0`, `1`, or `2`
|
||||
together with `GND`. When you are using this function in a web
|
||||
browser, click and release the pins on the screen instead of the ones on the BBC
|
||||
micro:bit.
|
||||
|
||||
If you hold the `GND` pin with one hand and touch pin `0`, `1`, or `2`
|
||||
with the other, a very small (safe) amount of electricity will flow
|
||||
through your body and back into the micro:bit. This is called
|
||||
**completing a circuit**. It's like you're a big wire!
|
||||
|
||||
```sig
|
||||
input.onPinReleased(TouchPin.P0, () => {
|
||||
})
|
||||
```
|
||||
|
||||
## ~hint
|
||||
|
||||
This function works best when the BBC micro:bit is using batteries for power,
|
||||
instead of the USB cable.
|
||||
|
||||
## ~
|
||||
|
||||
## Parameters
|
||||
|
||||
* ``name`` means the pin that is being released, either `P0`, `P1`, or `P2`
|
||||
|
||||
### Example: pin pressed counter
|
||||
|
||||
This program counts how many times you release the `P0` pin.
|
||||
Every time you release the pin, the program shows the number of times on the screen.
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
basic.showNumber(count, 100)
|
||||
input.onPinReleased(TouchPin.P0, () => {
|
||||
count = count + 1
|
||||
basic.showNumber(count, 100)
|
||||
})
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[BBC micro:bit pins](/device/pins), [pin is pressed](/reference/input/pin-is-pressed), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin)
|
||||
|
@ -18,3 +18,7 @@ led.toggle(0, 0);
|
||||
led.toggleAll();
|
||||
led.setDisplayMode(DisplayMode.BackAndWhite);
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
[plot](/reference/led/plot), [unplot](/reference/led/unplot), [point](/reference/led/point), [brightness](/reference/led/brightness), [setBrightness](/reference/led/set-brightness), [stopAnimation](/reference/led/stop-animation), [plotBarGraph](/reference/led/plot-bar-graph), [fadeIn](/reference/led/fade-in), [fadeOut](/reference/led/fade-out), [plotAll](/reference/led/plot-all), [screenshot](/reference/led/screenshot), [toggle](/reference/led/toggle), [toggleAll](/reference/led/toggle-all), [setDisplayMode](/reference/led/set-display-mode)
|
||||
|
@ -12,3 +12,7 @@ music.tempo();
|
||||
music.changeTempoBy(20);
|
||||
music.setTempo(120);
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
[playTone](/reference/music/play-tone), [ringTone](/reference/music/ring-tone), [rest](/reference/music/rest), [noteFrequency](/reference/music/note-frequency), [beat](/reference/music/beat), [tempo](/reference/music/tempo), [changeTempoBy](/reference/music/change-tempo), [setTempo](/reference/music/set-tempo)
|
||||
|
@ -13,11 +13,17 @@ pins.onPulsed(DigitalPin.P0, PulseValue.High, () => {
|
||||
|
||||
});
|
||||
pins.pulseDuration();
|
||||
pins.pulseIn(DigitalPin.P0, PulseValue.High);
|
||||
pins.servoWritePin(AnalogPin.P0, 180);
|
||||
pins.servoSetPulse(AnalogPin.P0, 1500);
|
||||
pins.i2cReadNumber(0, NumberFormat.Int8LE);
|
||||
pins.i2cWriteNumber(0, 0, NumberFormat.Int8LE);
|
||||
pins.spiWrite(0);
|
||||
pins.setPull(DigitalPin.P0, PinPullMode.PullDown);
|
||||
pins.analogPitch(0, 0);
|
||||
pins.analogSetPitchPin(AnalogPin.P0);
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
[digitalReadPin](/reference/pins/digital-read-pin), [digitalWritePin](/reference/pins/digital-write-pin), [analogReadPin](/reference/pins/analog-read-pin), [analogWritePin](/reference/pins/analog-write-pin), [analogSetPeriod](/reference/pins/analog-set-period), [map](/reference/pins/map), [onPulsed](/reference/pins/on-pulsed), [pulseDuration](/reference/pins/pulse-duration), [pulseIn](/reference/pins/pulse-in), [servoWritePin](/reference/pins/servo-write-pin), [servoSetPulse](/reference/pins/servo-set-pulse), [i2cReadNumber](/reference/pins/i2c-read-number), [i2cWriteNumber](/reference/pins/i2c-write-number), [setPull](/reference/pins/set-pull), [analogPitch](/reference/pins/analog-pitch), [analogSetPitchPin](/reference/pins/analog-set-pitch), [spiWrite](/reference/pins/spi-write)
|
||||
|
@ -13,7 +13,7 @@ pins.analogPitch(440, 300)
|
||||
|
||||
### Example
|
||||
|
||||
```
|
||||
```blocks
|
||||
pins.analogSetPitchPin("P0")
|
||||
let frequency1 = 440
|
||||
let duration = 1000
|
||||
|
@ -12,7 +12,7 @@ pins.analogSetPitchPin(AnalogPin.P0)
|
||||
|
||||
### Example
|
||||
|
||||
```
|
||||
```blocks
|
||||
pins.analogSetPitchPin(AnalogPin.P0)
|
||||
let frequency = 440
|
||||
let duration = 1000
|
||||
|
@ -27,6 +27,12 @@ format from the 7-bit I2C address `32`.
|
||||
pins.i2cReadNumber(32, NumberFormat.UInt16BE);
|
||||
```
|
||||
|
||||
#### ~hint
|
||||
|
||||
This function is not supported in the simulator.
|
||||
|
||||
#### ~
|
||||
|
||||
### See also
|
||||
|
||||
[I2C](https://en.wikipedia.org/wiki/I%C2%B2C)
|
||||
|
@ -27,6 +27,13 @@ address `32` in big-endian 32-bit integer format.
|
||||
```blocks
|
||||
pins.i2cWriteNumber(32, 2055, NumberFormat.Int32BE);
|
||||
```
|
||||
|
||||
#### ~hint
|
||||
|
||||
This function is not supported in the simulator.
|
||||
|
||||
#### ~
|
||||
|
||||
### See also
|
||||
|
||||
[I2C](https://en.wikipedia.org/wiki/I%C2%B2C)
|
||||
|
54
docs/reference/pins/pulse-in.md
Normal file
54
docs/reference/pins/pulse-in.md
Normal file
@ -0,0 +1,54 @@
|
||||
# Pulse In
|
||||
|
||||
Returns the duration of a pulse (high or low) from a [pin](/device/pins) on
|
||||
the micro:bit board in microseconds.
|
||||
|
||||
```sig
|
||||
pins.pulseIn(DigitalPin.P0, PulseValue.High)
|
||||
```
|
||||
|
||||
### ~avatar
|
||||
|
||||
Some pins are also used by the [LED screen](/device/screen).
|
||||
Please read the [page about pins](/device/pins) carefully.
|
||||
|
||||
### ~
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``name`` is a [string](/reference/types/string) that stores the name of the pin (``P0``, ``P1``, or ``P2``, up through ``P20``)
|
||||
* ``value`` is the value of the pulse, ``high`` or ``low``
|
||||
* ``maxDuration``, maximum duration in micro-seconds. If no pulse is received
|
||||
|
||||
### Returns
|
||||
|
||||
* a [number](/reference/types/number) that represents the pulse duration in micro-seconds
|
||||
|
||||
### Example: Measuring distance with a sonar
|
||||
|
||||
The following script sends a pulse on ``P0`` and reads the pulse returned by a HC-SR04 sonar to determine the distance of the object in front of the sensor.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
// send pulse
|
||||
pins.digitalWritePin(DigitalPin.P0, 0)
|
||||
control.waitMicros(2)
|
||||
pins.digitalWritePin(DigitalPin.P0, 1)
|
||||
control.waitMicros(10)
|
||||
pins.digitalWritePin(DigitalPin.P0, 0)
|
||||
|
||||
// read pulse
|
||||
led.plotBarGraph(pins.pulseIn(DigitalPin.P1, PulseValue.High) / 58, 0)
|
||||
basic.pause(100)
|
||||
})
|
||||
```
|
||||
|
||||
#### ~hint
|
||||
|
||||
This function is not supported in the simulator.
|
||||
|
||||
#### ~
|
||||
|
||||
### See also
|
||||
|
||||
[digital write pin](/reference/pins/digital-write-pin),
|
@ -29,7 +29,7 @@ pins.servoWritePin(AnalogPin.P0, 90)
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let millig = input.acceleration(Dimensions.X)
|
||||
let millig = input.acceleration(Dimension.X)
|
||||
// map accelerometer readings to angle
|
||||
let angle = pins.map(millig, -1023, 1023, 0, 180)
|
||||
pins.servoWritePin(AnalogPin.P0, angle)
|
||||
|
19
docs/reference/pins/spi-write.md
Normal file
19
docs/reference/pins/spi-write.md
Normal file
@ -0,0 +1,19 @@
|
||||
# SPI Write
|
||||
|
||||
Write to the SPI Slave and return the response.
|
||||
|
||||
```sig
|
||||
pins.spiWrite(0);
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``value``: value Data to be sent to the SPI slave
|
||||
|
||||
### Returns
|
||||
|
||||
* a [number](/reference/types/number) Response from the SPI slave
|
||||
|
||||
### See also
|
||||
|
||||
[SPI](https://developer.mbed.org/handbook/SPI)
|
@ -15,6 +15,14 @@ radio.receiveString();
|
||||
radio.receivedSignalStrength();
|
||||
radio.setGroup(0);
|
||||
radio.setTransmitPower(7);
|
||||
radio.writeValueToSerial();
|
||||
radio.setTransmitSerialNumber(false);
|
||||
radio.writeValueToSerial();
|
||||
```
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
[sendNumber](/reference/radio/send-number), [sendValue](/reference/radio/send-value), [sendString](/reference/radio/send-string), [onDataReceived](/reference/radio/on-data-received), [receiveNumber](/reference/radio/receive-number), [receivedNumberAt](/reference/radio/received-number-at), [receiveString](/reference/radio/receive-string), [receivedSignalStrength](/reference/radio/received-signal-strength), [setGroup](/reference/radio/set-group), [setTransmitPower](/reference/radio/set-transmit-power), [setTransmitSerialNumber](/reference/radio/set-transmit-serial-number), [writeValueToSerial](/reference/radio/write-value-to-serial)
|
||||
|
@ -33,3 +33,6 @@ radio.onDataReceived(() => {
|
||||
[receive number](/reference/radio/receive-number),
|
||||
[send number](/reference/radio/send-number), [set group](/reference/radio/set-group)
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
@ -64,3 +64,6 @@ basic.forever(() => {
|
||||
|
||||
[send number](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
@ -89,3 +89,7 @@ radio.onDataReceived(() => {
|
||||
### See also
|
||||
|
||||
[send string](/reference/radio/send-string), [on data received](/reference/radio/on-data-received)
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
@ -38,3 +38,7 @@ basic.forever(() => {
|
||||
### See also
|
||||
|
||||
[receive number](/reference/radio/receive-number), [send number](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
@ -43,3 +43,7 @@ basic.forever(() => {
|
||||
### See also
|
||||
|
||||
[receive number](/reference/radio/receive-number), [on data received](/reference/radio/on-data-received)
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
@ -40,3 +40,7 @@ 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)
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
@ -44,3 +44,6 @@ radio.onDataReceived(() => {
|
||||
|
||||
[receive number](/reference/radio/receive-number), [on data received](/reference/radio/on-data-received)
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
@ -34,3 +34,6 @@ radio.setGroup(128)
|
||||
|
||||
[receive number](/reference/radio/receive-number), [send number](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
@ -38,3 +38,7 @@ 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)
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
31
docs/reference/radio/set-transmit-serial-number.md
Normal file
31
docs/reference/radio/set-transmit-serial-number.md
Normal file
@ -0,0 +1,31 @@
|
||||
# Set Transmit Serial Number
|
||||
|
||||
Make the ``radio`` packet embed the board serial number with each packet of data.
|
||||
|
||||
```sig
|
||||
radio.setTransmitSerialNumber(true);
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``transmit`` is a [boolean](/reference/types/boolean) that represents whether the serial number needs to be transmitted.
|
||||
|
||||
### Simulator
|
||||
|
||||
This function only works on the micro:bit, not in browsers.
|
||||
|
||||
### Example
|
||||
|
||||
This program makes the ``radio`` send the serial number in each packet.
|
||||
|
||||
```blocks
|
||||
radio.setTransmitSerialNumber(true);
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[receive number](/reference/radio/receive-number), [send number](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)
|
||||
|
||||
```package
|
||||
microbit-radio
|
||||
```
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user