diff --git a/README.md b/README.md index ef81e233..0d435614 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This target allow to program a [BBC micro:bit](https://www.microbit.co.uk/) using PXT ([Microsoft Programming Experience Toolkit](https://github.com/Microsoft/pxt)). -* [Try it live](https://m.pxt.io) +* [Try it live](https://codethemicrobit.com) [![Build Status](https://travis-ci.org/Microsoft/pxt-microbit.svg?branch=master)](https://travis-ci.org/Microsoft/pxt-microbit) @@ -47,12 +47,12 @@ More instructions at https://github.com/Microsoft/pxt#running-a-target-from-loca ## Universal Windows App The Windows 10 app is a [Universal Windows Hosted Web App](https://microsoftedge.github.io/WebAppsDocs/en-US/win10/CreateHWA.htm) -that wraps ``m.pxt.io`` and provides additional features. +that wraps ``codethemicrobit.com`` and provides additional features. ### Building * Install Visual Studio 2015 Update 2 or higher. Make sure the Windows 10 templates are installed. -* open the ``win10/app.sln`` solution and launch the ``m.pxt.io`` project. +* open the ``win10/app.sln`` solution and launch the ``codethemicrobit`` project. ## Code of Conduct diff --git a/clients/chrome/README.md b/clients/chrome/README.md new file mode 100644 index 00000000..b3261250 --- /dev/null +++ b/clients/chrome/README.md @@ -0,0 +1,26 @@ +# microbit-chrome +Prototype chrome addon that exposes the micro:bit's serial output to webpages. +* watch the [demo video](https://vimeo.com/146207766) + +# Installation +See [developer.chrome.com](https://developer.chrome.com/extensions/getstarted#unpacked) +for instructions on how to install the local version into your chrome browser. + +# Requirements +* Chrome 48 or later. + +# Sample page +The `demo.html` webpage goes along with the +https://github.com/Microsoft/microbit-touchdevelop/blob/master/examples/tcs34725.cpp +program. Run `http-server` from this directory, then visit +http://localhost:8080/demo.html +(keep in mind that pages served from `file://` cannot open ports). + +# Building + +Open a command prompt and run the following commands. + +```` +npm install +typings update +```` \ No newline at end of file diff --git a/clients/chrome/background.js b/clients/chrome/background.js new file mode 100644 index 00000000..777b73ae --- /dev/null +++ b/clients/chrome/background.js @@ -0,0 +1,68 @@ +/// +var connections = []; +// A list of "ports", i.e. connected clients (such as web pages). Multiple web +// pages can connect to our service: they all receive the same data. +var ports = []; +function byPath(path) { + return connections.filter(function (x) { return x.path == path; }); +} +function byId(id) { + return connections.filter(function (x) { return x.id == id; }); +} +function onReceive(data, id) { + if (ports.length == 0) + return; + var view = new DataView(data); + var decoder = new TextDecoder("utf-8"); + var decodedString = decoder.decode(view); + ports.forEach(function (port) { return port.postMessage({ + type: "serial", + data: decodedString, + id: id + }); }); +} +function findNewDevices() { + chrome.serial.getDevices(function (serialPorts) { + serialPorts.forEach(function (serialPort) { + if (byPath(serialPort.path).length == 0 && + serialPort.displayName == "mbed Serial Port") { + chrome.serial.connect(serialPort.path, { bitrate: 115200 }, function (info) { + // In case the [connect] operation takes more than five seconds... + if (info && byPath(serialPort.path).length == 0) + connections.push({ + id: info.connectionId, + path: serialPort.path + }); + }); + } + }); + }); +} +function main() { + // Register new clients in the [ports] global variable. + chrome.runtime.onConnectExternal.addListener(function (port) { + if (/^(micro:bit|touchdevelop|yelm|pxt|codemicrobit|codethemicrobit)$/.test(port.name)) { + ports.push(port); + port.onDisconnect.addListener(function () { + ports = ports.filter(function (x) { return x != port; }); + }); + } + }); + // When receiving data for one of the connections that we're tracking, forward + // it to all connected clients. + chrome.serial.onReceive.addListener(function (info) { + if (byId(info.connectionId).length > 0) + onReceive(info.data, info.connectionId); + }); + // When it looks like we've been disconnected, drop the corresponding + // connection object from the [connections] global variable. + chrome.serial.onReceiveError.addListener(function (info) { + if (info.error == "system_error" || info.error == "disconnected" || info.error == "device_lost") + connections = connections.filter(function (x) { return x.id != info.connectionId; }); + }); + // Probe serial connections at regular intervals. In case we find an mbed port + // we haven't yet connected to, connect to it. + setInterval(findNewDevices, 5000); + findNewDevices(); +} +document.addEventListener("DOMContentLoaded", main); diff --git a/clients/chrome/background.ts b/clients/chrome/background.ts new file mode 100644 index 00000000..8925a363 --- /dev/null +++ b/clients/chrome/background.ts @@ -0,0 +1,92 @@ +// A list of: { +// id: number; +// path: string; +// } where [id] is the [connectionId] (internal to Chrome) and [path] is the +// OS' name for the device (e.g. "COM4"). +interface Connection { + id: string; + path: string; +} +let connections: Connection[] = []; + +// A list of "ports", i.e. connected clients (such as web pages). Multiple web +// pages can connect to our service: they all receive the same data. +let ports = []; + +interface Message { + type: string; + data: string; + id: string; +} + +function byPath(path: string): Connection[] { + return connections.filter((x) => x.path == path); +} + +function byId(id: string): Connection[] { + return connections.filter((x) => x.id == id); +} + +function onReceive(data, id: string) { + if (ports.length == 0) return; + + let view = new DataView(data); + let decoder = new TextDecoder("utf-8"); + let decodedString = decoder.decode(view); + ports.forEach(port => port.postMessage({ + type: "serial", + data: decodedString, + id: id, + })); +} + +function findNewDevices() { + chrome.serial.getDevices(function (serialPorts) { + serialPorts.forEach(function (serialPort) { + if (byPath(serialPort.path).length == 0 && + serialPort.displayName == "mbed Serial Port") { + chrome.serial.connect(serialPort.path, { bitrate: 115200 }, function (info) { + // In case the [connect] operation takes more than five seconds... + if (info && byPath(serialPort.path).length == 0) + connections.push({ + id: info.connectionId, + path: serialPort.path + }); + }); + } + }); + }); +} + +function main() { + // Register new clients in the [ports] global variable. + chrome.runtime.onConnectExternal.addListener(function (port) { + if (/^(micro:bit|touchdevelop|yelm|pxt|codemicrobit|codethemicrobit)$/.test(port.name)) { + ports.push(port); + port.onDisconnect.addListener(function () { + ports = ports.filter(function (x) { return x != port }); + }); + } + }); + + // When receiving data for one of the connections that we're tracking, forward + // it to all connected clients. + chrome.serial.onReceive.addListener(function (info) { + if (byId(info.connectionId).length > 0) + onReceive(info.data, info.connectionId); + }); + + // When it looks like we've been disconnected, drop the corresponding + // connection object from the [connections] global variable. + chrome.serial.onReceiveError.addListener(function (info) { + if (info.error == "system_error" || info.error == "disconnected" || info.error == "device_lost") + connections = connections.filter((x) => x.id != info.connectionId); + }); + + // Probe serial connections at regular intervals. In case we find an mbed port + // we haven't yet connected to, connect to it. + setInterval(findNewDevices, 5000); + findNewDevices(); +} + +document.addEventListener("DOMContentLoaded", main); diff --git a/clients/chrome/logo128.png b/clients/chrome/logo128.png new file mode 100644 index 00000000..eae35f4c Binary files /dev/null and b/clients/chrome/logo128.png differ diff --git a/clients/chrome/logo48.png b/clients/chrome/logo48.png new file mode 100644 index 00000000..0af483f8 Binary files /dev/null and b/clients/chrome/logo48.png differ diff --git a/clients/chrome/manifest.json b/clients/chrome/manifest.json new file mode 100644 index 00000000..a94c62a6 --- /dev/null +++ b/clients/chrome/manifest.json @@ -0,0 +1,30 @@ +{ + "app": { + "background": { + "scripts": [ "background.js" ] + } + }, + + "manifest_version": 2, + "name": "code the micro:bit", + "version": "0.6.0", + "author": "Microsoft Corporation", + "short_name": "code the micro:bit", + + "description": "Extension for https://codethemicrobit.com.", + "homepage_url": "https://codethemicrobit.com", + "offline_enabled": "true", + "icons": { + "48": "logo48.png", + "128": "logo128.png" + }, + + "permissions": [ + "serial", + "usb" + ], + + "externally_connectable": { + "matches": [ "*://localhost/*", "https://codethemicrobit.com/*", "https://*.codethemicrobit.com/*" ] + } +} diff --git a/clients/chrome/screenshot.png b/clients/chrome/screenshot.png new file mode 100644 index 00000000..c6f4b56b Binary files /dev/null and b/clients/chrome/screenshot.png differ diff --git a/clients/chrome/tsconfig.json b/clients/chrome/tsconfig.json new file mode 100644 index 00000000..ffa98b79 --- /dev/null +++ b/clients/chrome/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compiler-options": { + "target": "ES5", + "module": "amd", + "sourceMap": false + } + } \ No newline at end of file diff --git a/clients/win10/app/m.pxt.io.jsproj b/clients/win10/app/codethemicrobitapp.jsproj similarity index 100% rename from clients/win10/app/m.pxt.io.jsproj rename to clients/win10/app/codethemicrobitapp.jsproj diff --git a/clients/win10/app/codethemicrobitapp.sln b/clients/win10/app/codethemicrobitapp.sln new file mode 100644 index 00000000..ae487bac --- /dev/null +++ b/clients/win10/app/codethemicrobitapp.sln @@ -0,0 +1,48 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{262852C6-CD72-467D-83FE-5EEB1973A190}") = "codethemicrobitapp", "codethemicrobitapp.jsproj", "{39122940-AB16-4CD4-A0CE-79A3EB863ECF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|ARM = Debug|ARM + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|ARM = Release|ARM + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {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 + EndGlobalSection +EndGlobal diff --git a/clients/win10/app/package.appxmanifest b/clients/win10/app/package.appxmanifest index 74ee73b2..8eee874c 100644 --- a/clients/win10/app/package.appxmanifest +++ b/clients/win10/app/package.appxmanifest @@ -14,13 +14,13 @@ - + - + diff --git a/clients/winuploader/CodeTheMicroBit.Loader.sln b/clients/winuploader/CodeTheMicroBit.Loader.sln deleted file mode 100644 index 9c82e656..00000000 --- a/clients/winuploader/CodeTheMicroBit.Loader.sln +++ /dev/null @@ -1,22 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeTheMicrobit.Uploader", "Microbit.Uploader\CodeTheMicrobit.Uploader.csproj", "{7DC6CA45-FD75-44BC-805E-708C812CD4BF}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/clients/winuploader/CodeTheMicroBit.sln b/clients/winuploader/CodeTheMicroBit.sln new file mode 100644 index 00000000..4401ca6e --- /dev/null +++ b/clients/winuploader/CodeTheMicroBit.sln @@ -0,0 +1,66 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +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 + Debug|ARM = Debug|ARM + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|ARM = Release|ARM + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Debug|ARM.ActiveCfg = Debug|Any CPU + {7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Debug|ARM.Build.0 = Debug|Any CPU + {7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Debug|x64.ActiveCfg = Debug|Any CPU + {7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Debug|x64.Build.0 = Debug|Any CPU + {7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Debug|x86.ActiveCfg = Debug|Any CPU + {7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Debug|x86.Build.0 = Debug|Any CPU + {7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Release|Any CPU.Build.0 = Release|Any CPU + {7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Release|ARM.ActiveCfg = Release|Any CPU + {7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Release|ARM.Build.0 = Release|Any CPU + {7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Release|x64.ActiveCfg = Release|Any CPU + {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 + EndGlobalSection +EndGlobal diff --git a/clients/winuploader/Microbit.Uploader/CodeTheMicrobit.Uploader.csproj b/clients/winuploader/Microbit.Uploader/CodeTheMicrobit.csproj similarity index 98% rename from clients/winuploader/Microbit.Uploader/CodeTheMicrobit.Uploader.csproj rename to clients/winuploader/Microbit.Uploader/CodeTheMicrobit.csproj index 077710b6..0436a0f6 100644 --- a/clients/winuploader/Microbit.Uploader/CodeTheMicrobit.Uploader.csproj +++ b/clients/winuploader/Microbit.Uploader/CodeTheMicrobit.csproj @@ -8,7 +8,7 @@ WinExe Properties Microsoft.MicroBit - Microbit.Uploader + CodeTheMicrobit v2.0 512 true diff --git a/clients/winuploader/Microbit.Uploader/LicenseDialog.Designer.cs b/clients/winuploader/Microbit.Uploader/LicenseDialog.Designer.cs index bf8ed131..70ca5739 100644 --- a/clients/winuploader/Microbit.Uploader/LicenseDialog.Designer.cs +++ b/clients/winuploader/Microbit.Uploader/LicenseDialog.Designer.cs @@ -79,7 +79,7 @@ this.MinimizeBox = false; this.Name = "LicenseDialog"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "code the micro:bit uploader Terms Of Use"; + this.Text = "code the micro:bit terms of use"; this.ResumeLayout(false); } diff --git a/clients/winuploader/Microbit.Uploader/MainForm.Designer.cs b/clients/winuploader/Microbit.Uploader/MainForm.Designer.cs index cf9a6d0c..a27b4fa5 100644 --- a/clients/winuploader/Microbit.Uploader/MainForm.Designer.cs +++ b/clients/winuploader/Microbit.Uploader/MainForm.Designer.cs @@ -116,6 +116,7 @@ this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.pictureBox1.TabIndex = 5; this.pictureBox1.TabStop = false; + this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); // // linkLabel1 // @@ -148,7 +149,7 @@ this.ShowInTaskbar = false; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "code the micro:bit uploader"; + this.Text = "code the micro:bit"; this.Load += new System.EventHandler(this.MainForm_Load); ((System.ComponentModel.ISupportInitialize)(this.backgroundPictureBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); diff --git a/clients/winuploader/Microbit.Uploader/MainForm.cs b/clients/winuploader/Microbit.Uploader/MainForm.cs index 2800bda3..beba1b58 100644 --- a/clients/winuploader/Microbit.Uploader/MainForm.cs +++ b/clients/winuploader/Microbit.Uploader/MainForm.cs @@ -243,11 +243,7 @@ namespace Microsoft.MicroBit private void backgroundPictureBox_Click(object sender, EventArgs e) { - try - { - Process.Start("https://codethemicrobit.com"); - } - catch (IOException) { } + this.openEditor(); } private void SettingsLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) @@ -262,5 +258,10 @@ namespace Microsoft.MicroBit { this.openEditor(); } + + private void pictureBox1_Click(object sender, EventArgs e) + { + this.openEditor(); + } } } diff --git a/docs/device.md b/docs/device.md index 15f5d1ae..b722d430 100644 --- a/docs/device.md +++ b/docs/device.md @@ -23,13 +23,13 @@ When you have downloaded and run your code onto your micro:bit, press Button R t ### USB connection -When you plug in your micro:bit, it should appear as MICROBIT. +When you plug in your micro:bit, it should appear as ``MICROBIT``. If you accidentally hold down the reset button as you’re plugging in your micro:bit, -the micro:bit will appear as a MAINTENANCE drive instead of MICROBIT. This is known as maintenance mode.** +the micro:bit will appear as a MAINTENANCE drive instead of ``MICROBIT``. This is known as maintenance mode.** -To continue programming your micro:bit YOU MUST unplug your USB and reconnect it. Check that the drive now shows as MICROBIT. +To continue programming your micro:bit YOU MUST unplug your USB and reconnect it. Check that the drive now shows as ``MICROBIT``. -**Use with caution. If you click on the drive while it shows as MAINTENANCE, +**Use with caution. If you click on the drive while it shows as ``MAINTENANCE``, you can see which version of firmware you have running on your micro:bit. Firmware on your micro:bit should be up-to-date already. You can find the version of firmware in the 'version.txt' file on the micro:bit. Further information on the firmware can be found here: @@ -55,6 +55,10 @@ The pins can be a form of input or output. There are labels for the input/output pins P0, P1, P2, which you can attach external sensors to such as thermometers or moisture detectors. You can read more about large and small pins [here](/device/pins). +### Light level + +The screen can also be used a light level sensor (it's a really cool trick). + ### How do I connect the micro:bit to my computer? Your micro:bit can be connected to your computer via a micro USB cable. @@ -73,7 +77,7 @@ You can attach an external device such as a motor to these and power it using th ### Serial Communication -The BBC micro:bit can send an receive data via [serial communication](/device/serial). The serial data can be transfered via USB or BlE. +The BBC micro:bit can send an receive data via [serial communication](/device/serial). The serial data can be transfered via USB or BLE. ### Bluetooth Low Energy (BLE) Antenna diff --git a/docs/getting-started.md b/docs/getting-started.md index c7438317..1fe3577a 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -9,8 +9,6 @@ to make real programs that work! ## ~ -### Happy face - Use the **Basic** drawer in the editor (to the left) to drag out and arrange three blocks (two `show leds` and one `forever` block) to create this program: @@ -34,470 +32,13 @@ basic.forever(() => { }); ``` -When you run this program (click the **Play** button) you will see a smiley face, then a blank +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 **Compile** to move your program to the BBC micro:bit! +Make sure to follow the instructions. -### Happy unhappy face - -Draw an unhappy face instead of the blank screen. Click on the dots -in the second ``show leds`` block until it matches the blocks below. -Now you have an **animation** (cartoon) that shows a happy face, -then an unhappy one, then a happy one again, forever (or until -you turn off your micro:bit)! - -```blocks -basic.forever(() => { - basic.showLeds(` - . . . . . - . # . # . - . . . . . - # . . . # - . # # # . - `) - basic.showLeds(` - . . . . . - . # . # . - . . . . . - . # # # . - # . . . # - `) -}); -``` -Click **Compile** to move your program to the BBC micro:bit! - -### Your turn! - -Pile up more ``show leds`` blocks to create an animation! Create an -animation with at least 5 pictures. What does this animation show? - -```blocks -basic.forever(() => { - basic.showLeds(` - . . . . . - . # . # . - . . . . . - # . . . # - . # # # . - `) - basic.showLeds(` - . . . . . - . # . # . - . . . . . - # # # # # - . . . . . - `) - basic.showLeds(` - . . . . . - . # . # . - . . . . . - . # # # . - # . . . # - `) - basic.showLeds(` - . . . . . - . # . # . - . . . . . - # # # # # - . . . # # - `) - basic.showLeds(` - . . . . . - # . # . . - . . . . . - # . . . # - . # # # . - `) - basic.showLeds(` - . . . . . - . . # . # - . . . . . - # . . . # - . # # # . - `) -}); -``` -Click **Compile** to move your program to the BBC micro:bit! - -#### ~hint - -You can find the ``show leds`` block in the **Basic** part of the editor. - -#### ~ - -### Button A and button B - -This program will show the word **ANTEATER** on the LED -screen when you press button `A`. - -```blocks -input.onButtonPressed(Button.A, () => { - basic.showString("ANTEATER"); -}); -``` - -#### ~hint - -The ``showString`` block can show letters, numbers, and punctuation -on the micro:bit screen. - -#### ~ - -Now try to unscramble these blocks in the editor so that the micro:bit -shows **BANANA** when you press button `B`. - -```shuffle -input.onButtonPressed(Button.B, () => { - basic.showString("BANANA"); -}); -``` -#### ~hint - -You can find the letter `B` by clicking the letter `A` on the -``onButtonPressed`` block. - -#### ~ - -Click **Compile** to move your program to the BBC micro:bit! - -#### Your turn! - -Can you combine these blocks so your program shows your real name -instead of **ANTEATER** when you press `A`, but _your secret agent -name_ instead of **BANANA** when you press `B`? - -### 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. (Ouch!) - -```shuffle -input.onGesture(Gesture.Shake, () => { - basic.showLeds(` -. . . . . -. # . # . -. . . . . -. # # # . -# . . . #`); -}); -``` -Click **Compile** to move your program to the BBC micro:bit! - -### Pins - -You can also use the pins as buttons. (The pins are the holes in the -metal stripe at the bottom of the micro:bit board.) For example, hold -the ``GND`` button with one hand and touch the ``0`` pin (called -``P0``) with your other hand to tell the micro:bit you're pressing it. - -Unscramble the blocks in the editor to show a heart when you touch -pin ``P0``. - -```shuffle -input.onPinPressed(TouchPin.P0, () => { - basic.showLeds(` -. # . # . -# . # . # -# . . . # -. # . # . -. . # . .`); -}); -``` -Click **Compile** to move your program to the BBC micro:bit! - -## ~hint - -Try this experiment: find a friend and hold hands. Touch the ``GND`` -pin while your friend presses the ``P0`` pin. You should see the -heart! The electric current is going through your bodies and across -your handshake to make it happen! - -## ~ - -## The amazing coin flipper - -### ~avatar avatar - -Are you trying to choose whether to play soccer or go to the movies -instead, or which toppings to have on your pizza? Build a coin -flipping machine with the BBC micro:bit to choose for you! - -### ~ - -Here are the blocks to make your coin flipper. When you press button -`B`, the coin flipper will show either `H` for heads or `T` for tails -on the LED screen. - -```blocks -input.onButtonPressed(Button.B, () => { - if (Math.randomBoolean()) { - basic.showString("H"); - } else { - basic.showString("T"); - } -}); -``` -### ~hint - -The ``pick random true or false`` block randomly tells the ``if`` -block `true` or `false`. If the ``pick`` block picked `true`, the -``if`` block shows the letter `H`. Otherwise, it shows the letter `T`. - -That's it! - -### ~ - -### Keeping score - -#### ~avatar - -To keep track out of how many guesses you've won, -add these blocks to your coin flipper: - -#### ~ - -```blocks -input.onButtonPressed(Button.A, () => { - game.addScore(1); -}); -input.onButtonPressed(Button.AB, () => { - basic.showNumber(game.score()); -}); -``` - -These blocks mean that if you press button `A`, you will add `1` to -your score, and if you press `A` and `B` together, the micro:bit will -show your score. - -When you're done, your coin flipping program should look like this: - -```blocks -input.onButtonPressed(Button.B, () => { - if (Math.randomBoolean()) { - basic.showString("H"); - } else { - basic.showString("T"); - } -}); -input.onButtonPressed(Button.A, () => { - game.addScore(1); -}); -input.onButtonPressed(Button.AB, () => { - basic.showNumber(game.score()); -}); -``` - -Flip until your thumbs get tired! - -## Let's play Rock Paper Scissors! - -### ~avatar avatar - -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. (The game is built -like a coin flipper, but with three choices instead of two.) - -### ~ - -## 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. - -Clear up the blocks and add the blocks below. - -```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 `item`. - -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 item = 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 -`item` 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 item = Math.random(3) - if (item == 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 `item` is `1`. -Then add a ``show leds`` block with a picture of a rock. - -```blocks -input.onGesture(Gesture.Shake, () => { - let item = Math.random(3) - if (item == 0) { - basic.showLeds(` - # # # # # - # . . . # - # . . . # - # . . . # - # # # # # - `) - } else if (item == 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 item = Math.random(3) - if (item == 0) { - basic.showLeds(` - # # # # # - # . . . # - # . . . # - # . . . # - # # # # # - `) - - } else if (item == 1) { - basic.showLeds(` - . . . . . - . # # # . - . # # # . - . # # # . - . . . . . - `) - } else { - basic.showLeds(` - # # . . # - # # . # . - . . # . . - # # . # . - # # . . # - `) - } -}) - -``` - -### ~hint - -You don't need to check if `item` 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! - -Click **Compile** to move your program to the BBC micro:bit! - -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()) -}) -``` -Click **Compile** to move your program to the BBC micro:bit! - - -# Want to do more? - -There are [10 great projects](/projects) waiting for you. +### ~button /getting-started/screen +NEXT: THE SCREEN +### ~ \ No newline at end of file diff --git a/docs/getting-started/buttons.md b/docs/getting-started/buttons.md new file mode 100644 index 00000000..0f2d79dd --- /dev/null +++ b/docs/getting-started/buttons.md @@ -0,0 +1,81 @@ +# Button A and button B + +### ~avatar avatar + +Buttons are great to build games! + +### ~ + +This program will show the word **ANTEATER** on the LED +screen when you press button `A`. + +```blocks +input.onButtonPressed(Button.A, () => { + basic.showString("ANTEATER"); +}); +``` + +#### ~hint + +The ``showString`` block can show letters, numbers, and punctuation +on the micro:bit screen. + +#### ~ + +Now try to unscramble these blocks in the editor so that the micro:bit +shows **BANANA** when you press button `B`. + +```shuffle +input.onButtonPressed(Button.B, () => { + basic.showString("BANANA"); +}); +``` +#### ~hint + +You can find the letter `B` by clicking the letter `A` on the +``onButtonPressed`` block. + +#### ~ + +Click **Compile** to move your program to the BBC micro:bit! + +#### Your turn! + +Can you combine these blocks so your program shows your real name +instead of **ANTEATER** when you press `A`, but _your secret agent +name_ instead of **BANANA** when you press `B`? + +### Pins + +You can also use the pins as buttons. (The pins are the holes in the +metal stripe at the bottom of the micro:bit board.) For example, hold +the ``GND`` button with one hand and touch the ``0`` pin (called +``P0``) with your other hand to tell the micro:bit you're pressing it. + +Unscramble the blocks in the editor to show a heart when you touch +pin ``P0``. + +```shuffle +input.onPinPressed(TouchPin.P0, () => { + basic.showLeds(` +. # . # . +# . # . # +# . . . # +. # . # . +. . # . .`); +}); +``` +Click **Compile** to move your program to the BBC micro:bit! + +## ~hint + +Try this experiment: find a friend and hold hands. Touch the ``GND`` +pin while your friend presses the ``P0`` pin. You should see the +heart! The electric current is going through your bodies and across +your handshake to make it happen! + +## ~ + +### ~button /getting-started/shake +NEXT: SHAKE +### ~ \ No newline at end of file diff --git a/docs/getting-started/coin-flipper.md b/docs/getting-started/coin-flipper.md new file mode 100644 index 00000000..93d27c0f --- /dev/null +++ b/docs/getting-started/coin-flipper.md @@ -0,0 +1,78 @@ +# The amazing coin flipper + +### ~avatar avatar + +Are you trying to choose whether to play soccer or go to the movies +instead, or which toppings to have on your pizza? Build a coin +flipping machine with the BBC micro:bit to choose for you! + +### ~ + +Here are the blocks to make your coin flipper. When you press button +`B`, the coin flipper will show either `H` for heads or `T` for tails +on the LED screen. + +```blocks +input.onButtonPressed(Button.B, () => { + if (Math.randomBoolean()) { + basic.showString("H"); + } else { + basic.showString("T"); + } +}); +``` +### ~hint + +The ``pick random true or false`` block randomly tells the ``if`` +block `true` or `false`. If the ``pick`` block picked `true`, the +``if`` block shows the letter `H`. Otherwise, it shows the letter `T`. + +That's it! + +### ~ + +### Keeping score + +#### ~avatar + +To keep track out of how many guesses you've won, +add these blocks to your coin flipper: + +#### ~ + +```blocks +input.onButtonPressed(Button.A, () => { + game.addScore(1); +}); +input.onButtonPressed(Button.AB, () => { + basic.showNumber(game.score()); +}); +``` + +These blocks mean that if you press button `A`, you will add `1` to +your score, and if you press `A` and `B` together, the micro:bit will +show your score. + +When you're done, your coin flipping program should look like this: + +```blocks +input.onButtonPressed(Button.B, () => { + if (Math.randomBoolean()) { + basic.showString("H"); + } else { + basic.showString("T"); + } +}); +input.onButtonPressed(Button.A, () => { + game.addScore(1); +}); +input.onButtonPressed(Button.AB, () => { + basic.showNumber(game.score()); +}); +``` + +Flip until your thumbs get tired! + +### ~button /getting-started/rock-paper-scissors +NEXT: ROCK PAPER SCISSORS +### ~ diff --git a/docs/getting-started/rock-paper-scissors.md b/docs/getting-started/rock-paper-scissors.md new file mode 100644 index 00000000..ac9f6e79 --- /dev/null +++ b/docs/getting-started/rock-paper-scissors.md @@ -0,0 +1,205 @@ +# Rock Paper Scissors + +### ~avatar avatar + +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. (The game is built +like a coin flipper, but with three choices instead of two.) + +### ~ + +## 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. + +Clear up the blocks and add the blocks below. + +```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 `item`. + +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 item = 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 +`item` 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 item = Math.random(3) + if (item == 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 `item` is `1`. +Then add a ``show leds`` block with a picture of a rock. + +```blocks +input.onGesture(Gesture.Shake, () => { + let item = Math.random(3) + if (item == 0) { + basic.showLeds(` + # # # # # + # . . . # + # . . . # + # . . . # + # # # # # + `) + } else if (item == 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 item = Math.random(3) + if (item == 0) { + basic.showLeds(` + # # # # # + # . . . # + # . . . # + # . . . # + # # # # # + `) + + } else if (item == 1) { + basic.showLeds(` + . . . . . + . # # # . + . # # # . + . # # # . + . . . . . + `) + } else { + basic.showLeds(` + # # . . # + # # . # . + . . # . . + # # . # . + # # . . # + `) + } +}) + +``` + +### ~hint + +You don't need to check if `item` 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! + +Click **Compile** to move your program to the BBC micro:bit! + +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()) +}) +``` +Click **Compile** to move your program to the BBC micro:bit! + +### ~button /projects +NEXT: PROJECTS! +### ~ diff --git a/docs/getting-started/screen.md b/docs/getting-started/screen.md new file mode 100644 index 00000000..30cf1339 --- /dev/null +++ b/docs/getting-started/screen.md @@ -0,0 +1,98 @@ +# Screen + +### ~avatar avatar + +There are 25 bright LEDs on the micro:bit screen. Let's use them to create some cool animations! + +### ~ + +### Happy unhappy face + +Draw an unhappy face instead of the blank screen. Click on the dots +in the second ``show leds`` block until it matches the blocks below. +Now you have an **animation** (cartoon) that shows a happy face, +then an unhappy one, then a happy one again, forever (or until +you turn off your micro:bit)! + +```blocks +basic.forever(() => { + basic.showLeds(` + . . . . . + . # . # . + . . . . . + # . . . # + . # # # . + `) + basic.showLeds(` + . . . . . + . # . # . + . . . . . + . # # # . + # . . . # + `) +}); +``` +Click **Compile** to move your program to the BBC micro:bit! + +### Your turn! + +Pile up more ``show leds`` blocks to create an animation! Create an +animation with at least 5 pictures. What does this animation show? + +```blocks +basic.forever(() => { + basic.showLeds(` + . . . . . + . # . # . + . . . . . + # . . . # + . # # # . + `) + basic.showLeds(` + . . . . . + . # . # . + . . . . . + # # # # # + . . . . . + `) + basic.showLeds(` + . . . . . + . # . # . + . . . . . + . # # # . + # . . . # + `) + basic.showLeds(` + . . . . . + . # . # . + . . . . . + # # # # # + . . . # # + `) + basic.showLeds(` + . . . . . + # . # . . + . . . . . + # . . . # + . # # # . + `) + basic.showLeds(` + . . . . . + . . # . # + . . . . . + # . . . # + . # # # . + `) +}); +``` +Click **Compile** to move your program to the BBC micro:bit! + +#### ~hint + +You can find the ``show leds`` block in the **Basic** part of the editor. + +#### ~ + +### ~button /getting-started/buttons +NEXT: BUTTONS +### ~ \ No newline at end of file diff --git a/docs/getting-started/shake.md b/docs/getting-started/shake.md new file mode 100644 index 00000000..ced4b764 --- /dev/null +++ b/docs/getting-started/shake.md @@ -0,0 +1,24 @@ +# 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. (Ouch!) + +```shuffle +input.onGesture(Gesture.Shake, () => { + basic.showLeds(` +. . . . . +. # . # . +. . . . . +. # # # . +# . . . #`); +}); +``` +Click **Compile** to move your program to the BBC micro:bit! + +### ~button /getting-started/coin-flipper +NEXT: COIN FLIPPER GAME +### ~ diff --git a/docs/projects.md b/docs/projects.md index 68c023c6..b41155ed 100644 --- a/docs/projects.md +++ b/docs/projects.md @@ -1,11 +1,7 @@ -# Ten Projects - -### ~avatar avatar +# Projects Here are some cool projects that you can build with your micro:bit! -### ~ - ```codecard [{ diff --git a/docs/reference.md b/docs/reference.md index c64b5d6a..823d3be7 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -26,11 +26,11 @@ control.inBackground(() => { ## Advanced ```namespaces -bluetooth.onBluetoothConnected(() => { - -}); +devices.tellCameraTo(MesCameraEvent.TakePhoto); +bluetooth.onBluetoothConnected(() => {}); ``` ```package +microbit-devices microbit-bluetooth ``` \ No newline at end of file diff --git a/docs/reference/bluetooth.md b/docs/reference/bluetooth.md index ef65f1a1..1961bbf5 100644 --- a/docs/reference/bluetooth.md +++ b/docs/reference/bluetooth.md @@ -1,18 +1,22 @@ # Bluetooth +Support for additional Bluetooth services. + ```cards -bluetooth.onBluetoothConnected(() => { - -}); -bluetooth.onBluetoothDisconnected(() => { - -}); bluetooth.startAccelerometerService(); bluetooth.startButtonService(); bluetooth.startIOPinService(); bluetooth.startLEDService(); bluetooth.startMagnetometerService(); bluetooth.startTemperatureService(); +bluetooth.uartRead(""); +bluetooth.uartWrite(""); +bluetooth.onBluetoothConnected(() => { + +}); +bluetooth.onBluetoothDisconnected(() => { + +}); ``` ```package diff --git a/docs/reference/bluetooth/bluetooth-pairing.md b/docs/reference/bluetooth/bluetooth-pairing.md new file mode 100755 index 00000000..d9677e60 --- /dev/null +++ b/docs/reference/bluetooth/bluetooth-pairing.md @@ -0,0 +1,99 @@ +# Bluetooth Pairing + +### ~hint +![](/static/bluetooth/Bluetooth_SIG.png) + +For another device like a smartphone to use any of the Bluetooth "services" which the micro:bit has, it must first be [paired with the micro:bit](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the micro:bit and exchange data relating to many of the micro:bit's features. + +### ~ + +### What is 'pairing'? + +'Pairing' is what you have to do to have your micro:bit trust another device like a smartphone and similarly, have your smartphone trust your micro:bit. Why 'trust'? Well, pairing is all about security. You wouldn't usually want just anyone's smartphone connecting to your micro:bit and making it do things so by pairing *your* smartphone with *your* micro:bit you ensure that only your devices can talk to each other. + +Once you've paired your micro:bit with another device it also means that they are able to exchange information privately, without someone else being able to "see" the data they're exchanging over the air using Bluetooth. This is accomplished by data being [encrypted](https://en.wikipedia.org/wiki/Encryption) and pairing makes it possible for devices who trust each other to encrypt and decrypt data from each other. + +# How do you pair your micro:bit with another device? + +Making your micro:bit pair requires you to follow some simple steps which will be described shortly. What you do with the device you're pairing it to will vary slightly depending on what that device is. We'll look at how it's done with common smartphones and tablets here too. + +To get your micro:bit ready for pairing do the following: + +1. Hold down buttons A and B on the front of your micro:bit together. The front is the side with two buttons and the LED display. Keep the two buttons held down. Don't let go of them yet! +2. While still holding down buttons A and B, press and then release the reset button on the back of the micro:bit. Keep holding down buttons A and B. +3. You should see "PAIRING MODE!" start to scroll across the micro:bit display. When you see this message start to appear you can release buttons A and B. +4. Eventually you'll see a strange pattern on your micro:bit display. This is like your micro:bit's signature. Other people's micro:bits will probably display a different pattern. + +Your micro:bit is now ready to be paired with the other device. Read the section below which relates to your 'other' device and watch the video too. + +### How do you pair your micro:bit with a Windows smartphone or tablet? + +1. Go into Settings +2. Select Bluetooth +3. Switch your micro:bit into 'pairing mode' using the steps above +4. Wait until 'PAIRING MODE!' has finished scrolling across the micro:bit display. You should see your micro:bit listed on your Windows smartphone with a name something like 'BBC micro:bit [zatig]'. Note that the 5 characters in brackets at the end will vary. +5. On the Windows smartphone, tap the micro:bit named in the device list. This will initiate the pairing process. +6. The micro:bit will display a left pointing arrow and the Windows smartphone will pop up a box into which you will be invited to enter a "pin" (Personal Identity Number). +7. Press button A on the micro:bit and watch carefully as the micro:bit displays a sequence of 6 random numbers. You may find it easier to write them down than to remember them. +8. Enter the 6 digits which the micro:bit displayed into your Windows smartphone in the pop-up box provided and then select "done". +9. If you entered the right number the micro:bit will display a tick / check mark. If you made a mistake it will display a cross or X and you should repeat the process to try again. + +#### Video +https://www.youtube.com/watch?v=AoW3mit7jIg + + +### How do you pair your micro:bit with an Android smartphone or tablet? + +1. Go into Settings +2. Select Bluetooth +3. Switch your micro:bit into 'pairing mode' using the steps above +4. Wait until 'PAIRING MODE!' has finished scrolling across the micro:bit display. You should see your micro:bit listed on your Android smartphone under the heading "Available devices" with a name something like 'BBC micro:bit [zatig]'. Note that the 5 characters in brackets at the end will vary. +5. On the Android smartphone, tap the micro:bit named in the Available devices list. This will initiate the pairing process. +6. The micro:bit will display a left pointing arrow and the Android smartphone will pop up a box into which you will be invited to enter a "pin" (Personal Identity Number). +7. Press button A on the micro:bit and watch carefully as the micro:bit displays a sequence of 6 random numbers. You may find it easier to write them down than to remember them. +8. Enter the 6 digits which the micro:bit displayed into your Android smartphone in the pop-up box provided and then select "done". +9. If you entered the right number the micro:bit will display a tick / check mark. If you made a mistake it will display a cross or X and you should repeat the process to try again. + +#### Video +https://www.youtube.com/watch?v=7hLBfdAGkZI + +### How do you pair your micro:bit with an Apple iOS smartphone or tablet? + +The steps to pair with an Apple iOS device are different to those followed for an Android or Windows device. To trigger pairing you need an application which will try to interact with your micro:bit and it's that interaction that triggers the iOS pairing process. There are many you could use but for the purposes of this documentation we'll suggest you install the "nRF Master Control Panel" (nRF MCP) application from Nordic Semiconductor. You'll find it in the Apple app store. It's a really useful Bluetooth application which will help you learn about Bluetooth as well as it having the ability to trigger the pairing process. After installing nRF MCP you should follow these steps to pair with your micro:bit: + +1. Switch your micro:bit into 'pairing mode' using the steps above +2. Wait until 'PAIRING MODE!' has finished scrolling across the micro:bit display. +3. Launch the nRF MCP application. Your micro:bit should be listed and have a "Connect" button next to it. +4. Select "Connect" to connect your Apple device to the micro:bit. This will trigger the pairing process. +5. The micro:bit will display a left pointing arrow and the Apple device will pop up a box into which you will be invited to enter a "pin" (Personal Identity Number). +6. Press button A on the micro:bit and watch carefully as the micro:bit displays a sequence of 6 random numbers. You may find it easier to write them down than to remember them. +7. Enter the 6 digits which the micro:bit displayed into your Apple device in the pop-up box provided and then select "Pair". +8. If you entered the right number the micro:bit will display a tick / check mark. If you made a mistake it will display a cross or X and you should repeat the process to try again. + +#### Video +https://www.youtube.com/watch?v=wslwyAMwMhs + + +### How often do I need to pair my micro:bit with my phone? + +You do *not* need to pair your micro:bit and smartphone or tablet every time you use them together. Pairing establishes 'trust' which will be retained until it is somehow lost. When another device wants to talk to your micro:bit it must connect to it but connecting and pairing are not the same thing. + +There are circumstances which will result in pairing data being lost however and when this happens you will need to pair again. + +Currently, flashing new code via a USB cable causes the micro:bit's Bluetooth pairing data to be lost. Consequently, if you do flash new code to your micro:bit using a USB cable you will need to pair again. + +In contrast if you upload new code to your micro:bit over Bluetooth, using for example the Samsung micro:bit application for Android devices, you will not need to pair again. + +If you do find yourself needing to pair again you will first need to remove the pairing from your other device (i.e. smartphone or tablet): + +* On Android go into Settings/Bluetooth, select the 'cog' next to your micro:bit and then select FORGET +* On iOS go into Settings/Bluetooth, select your micro:bit and then select Forget This Device +* On a Windows device go into Settings/Bluetooth. Press and hold the micro:bit entry on the Windows device. A pop-up will appear with the option "delete". Select "delete" to unpair your micro:bit. + +### See also + +[Bluetooth SIG](https://www.bluetooth.com), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) + +```package +microbit-bluetooth +``` \ No newline at end of file diff --git a/docs/reference/bluetooth/on-bluetooth-connected.md b/docs/reference/bluetooth/on-bluetooth-connected.md index 990ca12a..8594d947 100755 --- a/docs/reference/bluetooth/on-bluetooth-connected.md +++ b/docs/reference/bluetooth/on-bluetooth-connected.md @@ -3,7 +3,7 @@ ### ~hint ![](/static/bluetooth/Bluetooth_SIG.png) -For another device like a smartphone to use any of the Bluetooth "services" which the micro:bit has, it must first connect to the micro:bit. +For another device like a smartphone to use any of the Bluetooth "services" which the micro:bit has, it must first be [paired with the micro:bit](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the micro:bit and exchange data relating to many of the micro:bit's features. ### ~ diff --git a/docs/reference/bluetooth/on-bluetooth-disconnected.md b/docs/reference/bluetooth/on-bluetooth-disconnected.md index 34674e83..942f7efa 100755 --- a/docs/reference/bluetooth/on-bluetooth-disconnected.md +++ b/docs/reference/bluetooth/on-bluetooth-disconnected.md @@ -1,33 +1,37 @@ # On Bluetooth Disconnected +### ~hint ![](/static/bluetooth/Bluetooth_SIG.png) -For another device like a smartphone to use any of the Bluetooth "services" which the micro:bit has, it must first connect to the micro:bit. This block starts an [event handler](/reference/event-handler) which in this case will run when a device which is connected to your micro:bit over Bluetooth disconnects. +For another device like a smartphone to use any of the Bluetooth "services" which the micro:bit has, it must first be [paired with the micro:bit](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the micro:bit and exchange data relating to many of the micro:bit's features. + +### ~ + +This block starts an [event handler](/reference/event-handler) which in this case will run when a device which is connected to your micro:bit over Bluetooth disconnects. You could use this event handler to display a letter "D" on the micro:bit LED grid so you know that the Bluetooth connection has been closed. -~~~~sig +```sig bluetooth.onBluetoothDisconnected(() => { }); -~~~~ +``` ### Example: Displaying "D" when a Bluetooth connection to the micro:bit is closed -~~~~blocks +```blocks bluetooth.onBluetoothDisconnected(() => { basic.showString("D"); }); -~~~~ +``` ### Video - on Bluetooth disconnected -[![micro:bit Bluetooth demo video](/static/bluetooth/microbit_on_disconnected.png)]( - http://www.youtube.com/watch?v=HyBcsD9Eh6I "Click to launch YouTube video" - ) +http://www.youtube.com/watch?v=HyBcsD9Eh6I ### See also -[Bluetooth SIG](https://www.bluetooth.com) - -[Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) +[Bluetooth SIG](https://www.bluetooth.com), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) +```package +microbit-bluetooth +``` diff --git a/docs/reference/bluetooth/start-accelerometer-service.md b/docs/reference/bluetooth/start-accelerometer-service.md index 2c8ddec6..abb9e4b5 100755 --- a/docs/reference/bluetooth/start-accelerometer-service.md +++ b/docs/reference/bluetooth/start-accelerometer-service.md @@ -1,30 +1,33 @@ # Bluetooth Accelerometer Service +### ~hint ![](/static/bluetooth/Bluetooth_SIG.png) +For another device like a smartphone to use any of the Bluetooth "services" which the micro:bit has, it must first be [paired with the micro:bit](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the micro:bit and exchange data relating to many of the micro:bit's features. + +### ~ + The Bluetooth accelerometer service allows another device such as a smartphone to wirelessly receive data from the micro:bit's accelerometer. An accelerometer detects motion. More precisely, it measures acceleration in one or more of three directions which we call X, Y and Z. Using the Bluetooth accelerometer service you could, for example, create a smartphone application which makes a loud noise whenever your micro:bit (or the important thing you've attached it to) is moved. Or you could use your micro:bit to control the movement of a cartoon character in a game on your smartphone just by tilting the micro:bit in the direction you want the character to move in. No additional code is needed on the micro:bit to use the Bluetooth accelerometer service from another device. -~~~~sig +```sig bluetooth.startAccelerometerService(); -~~~~ +``` ### Example: Starting the Bluetooth accelerometer service The following code shows the Bluetooth accelerometer service being started: -~~~~blocks +```blocks bluetooth.startAccelerometerService(); -~~~~ +``` ### Video - Accelerometer service demo - Starts at 0:18 -[![micro:bit Bluetooth demo video](/static/bluetooth/microbit_accelerometer.png)]( - http://www.youtube.com/watch?v=aep_GVowKfs "Click to launch YouTube video" - ) +http://www.youtube.com/watch?v=aep_GVowKfs#t=18s ### Advanced @@ -32,7 +35,8 @@ For more advanced information on the micro:bit Bluetooth accelerometer service i ### See also -[Bluetooth SIG](https://www.bluetooth.com) - -[Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) +[Bluetooth SIG](https://www.bluetooth.com), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) +```package +microbit-bluetooth +``` diff --git a/docs/reference/bluetooth/start-button-service.md b/docs/reference/bluetooth/start-button-service.md index 05e96c21..1e8e1313 100755 --- a/docs/reference/bluetooth/start-button-service.md +++ b/docs/reference/bluetooth/start-button-service.md @@ -1,7 +1,12 @@ # Bluetooth Button Service +### ~hint ![](/static/bluetooth/Bluetooth_SIG.png) +For another device like a smartphone to use any of the Bluetooth "services" which the micro:bit has, it must first be [paired with the micro:bit](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the micro:bit and exchange data relating to many of the micro:bit's features. + +### ~ + The Bluetooth button service makes it possible for another device such as a smartphone to be notified wirelessly whenever a button on the front of a micro:bit is pressed. Each of the two micro:bit buttons can be in one of three possible states: * Not pressed @@ -12,23 +17,21 @@ The button service allows you to make other things which are connected to your m No additional code is needed on the micro:bit to use the Bluetooth button service from another device. -~~~~sig +```sig bluetooth.startButtonService(); -~~~~ +``` ### Example: Starting the Bluetooth button service The following code shows the Bluetooth button service being started: -~~~~blocks +```blocks bluetooth.startButtonService(); -~~~~ +``` ### Video - Button service demo - Starts at 0:59 -[![micro:bit Bluetooth demo video](/static/bluetooth/microbit_button.png)]( - http://www.youtube.com/watch?v=aep_GVowKfs "Click to launch YouTube video" - ) +http://www.youtube.com/watch?v=aep_GVowKfs ### Advanced @@ -36,7 +39,8 @@ For more advanced information on the micro:bit Bluetooth button service includin ### See also -[Bluetooth SIG](https://www.bluetooth.com) - -[Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) +[Bluetooth SIG](https://www.bluetooth.com),[Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) +```package +microbit-bluetooth +``` diff --git a/docs/reference/bluetooth/start-io-pin-service.md b/docs/reference/bluetooth/start-io-pin-service.md index 5d947a91..48ffa914 100755 --- a/docs/reference/bluetooth/start-io-pin-service.md +++ b/docs/reference/bluetooth/start-io-pin-service.md @@ -1,28 +1,31 @@ # Bluetooth IO Pin Service +### ~hint ![](/static/bluetooth/Bluetooth_SIG.png) +For another device like a smartphone to use any of the Bluetooth "services" which the micro:bit has, it must first be [paired with the micro:bit](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the micro:bit and exchange data relating to many of the micro:bit's features. + +### ~ + The Bluetooth IO pin service makes it possible for another device such as a smartphone to communicate with other electronic 'things' connected to a micro:bit's edge connector. You could for example, use your smartphone to switch on or off a light which is connected to the micro:bit or your smartphone could receive data collected from a sensor connected to the micro:bit. In fact you could do both of these things at the same time since the Bluetooth IO pin service lets you interact with multiple 'pins' on the edge conector in different ways all at the same time. No additional code is needed on the micro:bit to use the Bluetooth IO pin service from another device. -~~~~sig +```sig bluetooth.startIOPinService(); -~~~~ +``` ### Example: Starting the Bluetooth IO pin service The following code shows the Bluetooth IO pin service being started: -~~~~blocks +```blocks bluetooth.startIOPinService(); -~~~~ +``` ### Video - IO pin service demo starts at 3:49 -[![micro:bit Bluetooth demo video](/static/bluetooth/microbit_pin_io.png)]( - http://www.youtube.com/watch?v=aep_GVowKfs "Click to launch YouTube video" - ) +http://www.youtube.com/watch?v=aep_GVowKfs ### Advanced @@ -30,7 +33,8 @@ For more advanced information on the micro:bit Bluetooth IO pin service includin ### See also -[Bluetooth SIG](https://www.bluetooth.com) - -[Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) +[Bluetooth SIG](https://www.bluetooth.com), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) +```package +microbit-bluetooth +``` diff --git a/docs/reference/bluetooth/start-led-service.md b/docs/reference/bluetooth/start-led-service.md index 3f0a7c19..3dc1c5ea 100755 --- a/docs/reference/bluetooth/start-led-service.md +++ b/docs/reference/bluetooth/start-led-service.md @@ -1,30 +1,33 @@ # Bluetooth LED Service +### ~hint ![](/static/bluetooth/Bluetooth_SIG.png) +For another device like a smartphone to use any of the Bluetooth "services" which the micro:bit has, it must first be [paired with the micro:bit](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the micro:bit and exchange data relating to many of the micro:bit's features. + +### ~ + The Bluetooth LED service allows another device such as a smartphone to send short text strings or patterns over a Bluetooth connection to a micro:bit for display on its LED matrix. Text will scroll across the micro:bit and the speed at which it scrolls can also be controlled using the Bluetooth LED service. Devices using the LED service may also read the current state of the micro:bit's LED matrix. So you could, for example, draw a smiley face in a smartphone app and at the press of a button, have it magically appear on your micro:bit on the other side of the room. Or you could program your smartphone to send a message to your micro:bit whenever your phone receives an email, SMS or social media message so you could wear your micro:bit like a smart watch and leave your phone in your bag. No additional code is needed on the micro:bit to use the Bluetooth LED service from another device. -~~~~sig +```sig bluetooth.startLEDService(); -~~~~ +``` ### Example: Starting the Bluetooth LED service The following code shows the Bluetooth LED service being started: -~~~~blocks +```blocks bluetooth.startLEDService(); -~~~~ +``` ### Video - LED service demo starts at 2:00 -[![micro:bit Bluetooth demo video](/static/bluetooth/microbit_led.png)]( - http://www.youtube.com/watch?v=aep_GVowKfs "Click to launch YouTube video" - ) +http://www.youtube.com/watch?v=aep_GVowKfs ### Advanced @@ -32,7 +35,8 @@ For more advanced information on the micro:bit Bluetooth LED service including i ### See also -[Bluetooth SIG](https://www.bluetooth.com) - -[Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) +[Bluetooth SIG](https://www.bluetooth.com), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) +```package +microbit-bluetooth +``` diff --git a/docs/reference/bluetooth/start-magnetometer-service.md b/docs/reference/bluetooth/start-magnetometer-service.md index 3208135f..4dcab9d7 100755 --- a/docs/reference/bluetooth/start-magnetometer-service.md +++ b/docs/reference/bluetooth/start-magnetometer-service.md @@ -1,30 +1,33 @@ # Bluetooth Magnetometer Service +### ~hint ![](/static/bluetooth/Bluetooth_SIG.png) +For another device like a smartphone to use any of the Bluetooth "services" which the micro:bit has, it must first be [paired with the micro:bit](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the micro:bit and exchange data relating to many of the micro:bit's features. + +### ~ + The Bluetooth magnetometer service allows another device such as a smartphone to wirelessly receive data from the micro:bit's magnetometer. The magnetometer measures the strength and direction of magnetic fields including the earth's and so it can be used as a digital compass and indicate the way the micro:bit is pointing relative to magnetic north. Using the Bluetooth magnetometer service you could, for example, create a smartphone application which displays your direction of travel, updating it in real time. No additional code is needed on the micro:bit to use the Bluetooth magnetometer service from another device. -~~~~sig +```sig bluetooth.startMagnetometerService(); -~~~~ +``` ### Example: Starting the Bluetooth magnetometer service The following code shows the Bluetooth magnetometer service being started: -~~~~blocks +```blocks bluetooth.startMagnetometerService(); -~~~~ +``` ### Video - Magnetometer service demo -[![micro:bit Bluetooth demo video](/static/bluetooth/microbit_magnetometer.png)]( - http://www.youtube.com/watch?v=C_0VL4Gp4_U "Click to launch YouTube video" - ) +http://www.youtube.com/watch?v=C_0VL4Gp4_U ### Advanced @@ -32,7 +35,9 @@ For more advanced information on the micro:bit Bluetooth magnetometer service in ### See also -[Bluetooth SIG](https://www.bluetooth.com) +[Bluetooth SIG](https://www.bluetooth.com), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) -[Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) +```package +microbit-bluetooth +``` diff --git a/docs/reference/bluetooth/start-temperature-service.md b/docs/reference/bluetooth/start-temperature-service.md index 298c9a63..0679fbb0 100755 --- a/docs/reference/bluetooth/start-temperature-service.md +++ b/docs/reference/bluetooth/start-temperature-service.md @@ -1,30 +1,33 @@ # Bluetooth Temperature Service +### ~hint ![](/static/bluetooth/Bluetooth_SIG.png) +For another device like a smartphone to use any of the Bluetooth "services" which the micro:bit has, it must first be [paired with the micro:bit](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the micro:bit and exchange data relating to many of the micro:bit's features. + +### ~ + A micro:bit is able to provide a rough measure of the current environmental temperature. It's an approximation only as in fact the temperature value is inferred from the temperature of its main processor. The Bluetooth temperature service allows another device such as a smartphone to wirelessly find out the micro:bit's current temperature reading or to receive a constant stream of temperature data values. Temperature values are expressed in degrees celsius. Using the Bluetooth temperature service you could turn your smartphone or tablet into a graphical thermometer using your micro:bit as the sensor. No additional code is needed on the micro:bit to use the Bluetooth temperature service from another device. -~~~~sig +```sig bluetooth.startTemperatureService(); -~~~~ +``` ### Example: Starting the Bluetooth temperature service The following code shows the Bluetooth temperature service being started: -~~~~blocks +```blocks bluetooth.startTemperatureService(); -~~~~ +``` ### Video - Temperature service demo - Starts at 3:05 -[![micro:bit Bluetooth demo video](/static/bluetooth/microbit_temperature.png)]( - http://www.youtube.com/watch?v=aep_GVowKfs "Click to launch YouTube video" - ) +http://www.youtube.com/watch?v=aep_GVowKfs ### Advanced @@ -32,7 +35,10 @@ For more advanced information on the micro:bit Bluetooth temperature service inc ### See also -[Bluetooth SIG](https://www.bluetooth.com) +[Bluetooth SIG](https://www.bluetooth.com), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) -[Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) + +```package +microbit-bluetooth +``` diff --git a/docs/reference/bluetooth/start-uart-service.md b/docs/reference/bluetooth/start-uart-service.md new file mode 100755 index 00000000..a74875a9 --- /dev/null +++ b/docs/reference/bluetooth/start-uart-service.md @@ -0,0 +1,44 @@ +# Bluetooth UART Service + +### ~hint +![](/static/bluetooth/Bluetooth_SIG.png) + +For another device like a smartphone to use any of the Bluetooth "services" which the micro:bit has, it must first be [paired with the micro:bit](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the micro:bit and exchange data relating to many of the micro:bit's features. + +### ~ + +The Bluetooth UART service allows another device such as a smartphone to exchange any data it wants to with the micro:bit, in small chunks which are intended to be joined together. [UART[(https://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter) stands for Universal Asynchronous Receiver Transmitter and is one way in which serial data communications can be performed, usually between two devices connected by a physical, wired connection. The Bluetooth UART service emulates the behaviour of a physical UART system and allows the exchange of a maximum of 20 bytes of data at a time in either direction. + +When this service is used, the micro:bit sets up a 60 byte buffer and data it receives will be accumulated in the buffer until it is full. When using the UART service from your micro:bit code, you can indicate a special character which will be used to mean that the entire message in at most three chunks has now been sent by the other, connected device, at which point the micro:bit will release the entire contents of its buffer to any code trying to read it. In other words this special character, known as a 'delimiter' is used by the device connected to the micro:bit to mean "I've sent my whole message, you can now use it". + +You could use the UART service for many things. It doesn't care what you put in messages which makes it very flexible. You could create a guessing game, with questions and answers passing between micro:bit and a smartphone or you could connect a camera to the micro:bit and transmit image data obtained from the edge connector, in chunks over Bluetooth to a smartphone. There are a great many possibilities. + +To use the Bluetooth UART service from another device you'll need additional micro:bit code which reads and uses data from the UART buffer and / or writes data to the buffer for transmission over Bluetooth to another device. + +```sig +bluetooth.startUartService(); +``` + +### Example: Starting the Bluetooth UART service + +The following code shows the Bluetooth UART service being started: + +```blocks +bluetooth.startUartService(); +``` + +### Video - UART service guessing game + +https://www.youtube.com/watch?v=PgGeWddMAZ0 + +### Advanced + +For more advanced information on the micro:bit Bluetooth UART service including information on using a smartphone, see the [Lancaster University micro:bit runtime technical documentation](http://lancaster-university.github.io/microbit-docs/ble/uart-service/) + +### See also + +[Bluetooth SIG](https://www.bluetooth.com), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) + +```package +microbit-bluetooth +``` diff --git a/docs/reference/bluetooth/uart-read.md b/docs/reference/bluetooth/uart-read.md new file mode 100755 index 00000000..374507c7 --- /dev/null +++ b/docs/reference/bluetooth/uart-read.md @@ -0,0 +1,52 @@ +# UART Read + +### ~hint +![](/static/bluetooth/Bluetooth_SIG.png) + +For another device like a smartphone to use any of the Bluetooth "services" which the micro:bit has, it must first be [paired with the micro:bit](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the micro:bit and exchange data relating to many of the micro:bit's features. + +### ~ + +The [Bluetooth UART service](start-uart-service.md) allows another device such as a smartphone to exchange any data it wants to with the micro:bit, in small chunks. + +With the Bluetooth UART service running, this block allows a micro:bit to read data which has been received from a Bluetooth connected device, terminating reading and returning the value obtained as soon as a specified delimiter character is encountered. This means that connected devices can send data to the micro:bit and indicate that the complete message has been sent by appending the message with the delimiter character. + +```sig +bluetooth.uartRead(""); +``` + +### Example: Starting the Bluetooth UART service and then reading data received from another device which is terminated by ":" character and then displaying it + +```blocks +let uart_data = ""; +let connected = 0; +basic.showString("UART"); +bluetooth.onBluetoothConnected(() => { + basic.showString("C"); + connected = 1; + while (connected == 1) { + uart_data = bluetooth.uartRead(":"); + basic.showString(uart_data); + } +}); +bluetooth.onBluetoothDisconnected(() => { + basic.showString("D"); +}); + +``` + +### Video - UART service guessing game + +https://www.youtube.com/watch?v=PgGeWddMAZ0 + +### Advanced + +For more advanced information on the micro:bit Bluetooth UART service including information on using a smartphone, see the [Lancaster University micro:bit runtime technical documentation](http://lancaster-university.github.io/microbit-docs/ble/uart-service/) + +### See also + +[Bluetooth SIG](https://www.bluetooth.com), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) + +```package +microbit-bluetooth +``` diff --git a/docs/reference/bluetooth/uart-write.md b/docs/reference/bluetooth/uart-write.md new file mode 100755 index 00000000..58c3d676 --- /dev/null +++ b/docs/reference/bluetooth/uart-write.md @@ -0,0 +1,51 @@ +# UART Write + +### ~hint +![](/static/bluetooth/Bluetooth_SIG.png) + +For another device like a smartphone to use any of the Bluetooth "services" which the micro:bit has, it must first be [paired with the micro:bit](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the micro:bit and exchange data relating to many of the micro:bit's features. + +### ~ + +The [Bluetooth UART service](start-uart-service.md) allows another device such as a smartphone to exchange any data it wants to with the micro:bit, in small chunks. + +With the Bluetooth UART service running, this block allows a micro:bit to send data to a Bluetooth connected device. + +```sig +bluetooth.uartWrite(""); +``` + +### Example: Starting the Bluetooth UART service and then sending "HELLO" whenever button A is pressed and another device has connected over Bluetooth + +```blocks +let connected = 0; +bluetooth.onBluetoothConnected(() => { + basic.showString("C"); + connected = 1; +}); +bluetooth.onBluetoothDisconnected(() => { + basic.showString("D"); + connected = 0; +}); +input.onButtonPressed(Button.A, () => { + if (connected == 1) { + bluetooth.uartWrite("HELLO"); + } +}); +``` + +### Video - UART service guessing game + +https://www.youtube.com/watch?v=PgGeWddMAZ0 + +### Advanced + +For more advanced information on the micro:bit Bluetooth UART service including information on using a smartphone, see the [Lancaster University micro:bit runtime technical documentation](http://lancaster-university.github.io/microbit-docs/ble/uart-service/) + +### See also + +[Bluetooth SIG](https://www.bluetooth.com), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) + +```package +microbit-bluetooth +``` diff --git a/docs/reference/control/in-background.md b/docs/reference/control/in-background.md index 24aa8a9b..0e0de180 100644 --- a/docs/reference/control/in-background.md +++ b/docs/reference/control/in-background.md @@ -1,15 +1,25 @@ -# In Background +# Run In Background -Run code in the background as a separate process or thread; for more information on this advanced construct, see [the micro:bit - a reactive system](/device/reactive). +Run part of a program while the rest of it is doing something else. ```sig control.inBackground(() => { }) ``` +### ~hint + +For more information, read +[The micro:bit - a reactive system](/device/reactive). +It is pretty advanced! + +### ~ + ### Example -The example below shows how a background process can be used to display the current value of the global variable `num`, while code (like the `on button pressed` handler) can change the value of the variable. +This program shows how running in the background can say what is +stored in a variable like `num`, while another part (``on button pressed``) +changes what is stored there. ```blocks let num = 0 @@ -24,7 +34,8 @@ input.onButtonPressed(Button.A, () => { }) ``` -The code below using the `forever` loop is equivalent to the code above +This program does the same thing, but in a more usual way, +with a ``forever`` loop. ```blocks let num = 0 @@ -36,20 +47,8 @@ input.onButtonPressed(Button.A, () => { }) ``` -### Contention for the LED display - -If you have multiple processes that each show something on the LED screen, you may get unexpected results. Try, for example: - -```blocks -basic.forever(() => { - basic.showNumber(6789, 150) -}) -input.onButtonPressed(Button.A, () => { - basic.showNumber(2, 150) -}) -``` - ### See also -[while](/blocks/loops/while), [forever](/reference/basic/forever), [on button pressed](/reference/input/on-button-pressed) +[while](/blocks/loops/while), [forever](/reference/basic/forever), +[on button pressed](/reference/input/on-button-pressed) diff --git a/docs/reference/control/reset.md b/docs/reference/control/reset.md index 16c985ee..59ba8cbe 100644 --- a/docs/reference/control/reset.md +++ b/docs/reference/control/reset.md @@ -1,8 +1,37 @@ # Reset -Reset the BBC micro:bit (as if you pushed the reset button on the back of the device), which causes the program to start again. +Reset the BBC micro:bit and start the program again. + +This function is like pressing the reset button on the back of the micro:bit. ```sig control.reset() ``` +### Example + +This program will count as high as you like when you press button `A`. +When you get tired of counting, press button `B` to reset the +micro:bit and start the program over. + +```blocks +let item = 0; +basic.showNumber(item); +input.onButtonPressed(Button.A, () => { + item = item + 1; + basic.showNumber(item); +}); +input.onButtonPressed(Button.B, () => { + control.reset(); +}); +``` + +#### ~hint + +This program works better on a real micro:bit than in the simulator. + +#### ~ + +### See Also + +[clear screen](/reference/basic/clear-screen), [game over](/reference/game/game-over) diff --git a/docs/reference/devices.md b/docs/reference/devices.md new file mode 100644 index 00000000..c8b88d88 --- /dev/null +++ b/docs/reference/devices.md @@ -0,0 +1,19 @@ +# Devices + +Control a phone with the BBC micro:bit via Bluetooth. + +```cards +devices.tellCameraTo(MesCameraEvent.TakePhoto); +devices.tellRemoteControlTo(MesRemoteControlEvent.play); +devices.raiseAlertTo(MesAlertEvent.DisplayToast); +devices.onNotified(MesDeviceInfo.IncomingCall, () => { + +}); +devices.onGamepadButton(MesDpadButtonInfo.ADown, () => { + +}); +devices.signalStrength(); +devices.onSignalStrengthChanged(() => { + +}); +``` diff --git a/docs/reference/input/acceleration.md b/docs/reference/input/acceleration.md index f4b4e122..f59ffa62 100644 --- a/docs/reference/input/acceleration.md +++ b/docs/reference/input/acceleration.md @@ -38,5 +38,7 @@ basic.forever(() => { ### See also -[compass-heading](/reference/input/compass-heading), [lightlevel](/reference/input/light-level) +[set accelerometer range](/reference/input/set-accelerometer-range), +[compass heading](/reference/input/compass-heading), +[light level](/reference/input/light-level) diff --git a/docs/reference/input/set-accelerometer-range.md b/docs/reference/input/set-accelerometer-range.md new file mode 100644 index 00000000..68589749 --- /dev/null +++ b/docs/reference/input/set-accelerometer-range.md @@ -0,0 +1,37 @@ +# Set Accelerometer Range + +Set up the part of the micro:bit that measures +[acceleration](/reference/input/acceleration) (how much the microbit +is speeding up or slowing down), in case you need to measure high +or low acceleration. + +### Parameters + +* the biggest number of gravities of acceleration you will be + measuring (either 1G, 2G, 4G, or 8G). Any bigger numbers will be + ignored by your micro:bit, both when you are picking a number of + gravities, and when you are measuring acceleration. + +### Example + +This program says the highest acceleration that your micro:bit +will measure is 4G. Then it measures acceleration from side to side +until you stop the program. + +```blocks +input.setAccelerometerRange(AcceleratorRange.FourG); +basic.forever(() => { + basic.showNumber(input.acceleration(Dimension.X)); +}); +``` + +#### ~hint + +This program does not work in the simulator, only in a micro:bit. + +#### ~ + +### See Also + +[compass heading](/reference/input/compass-heading), +[light level](/reference/input/light-level) diff --git a/docs/reference/offline.md b/docs/reference/offline.md index e40e9b46..028f3dc8 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://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 "/". +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://codethemicrobit.com/](https://codethemicrobit.com/), 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/analog-read-pin.md b/docs/reference/pins/analog-read-pin.md index d1ee83bd..fceccfe0 100644 --- a/docs/reference/pins/analog-read-pin.md +++ b/docs/reference/pins/analog-read-pin.md @@ -1,6 +1,7 @@ # Analog Read Pin -Read the specified [pin](/device/pins) (P0, P1, P2) as analog. +Read an **analog** signal (`0` through `1023`) from the +[pin](/device/pins) you say. ```sig pins.analogReadPin(AnalogPin.P0) @@ -8,22 +9,27 @@ pins.analogReadPin(AnalogPin.P0) ### Parameters -* name - the pin name (`P0`, `P1`, or `P2`) +* a [string](/reference/types/string) that stores the name of the pin + you say (`P0` through `P4`, or `P10`) ### Returns -* [Number](/reference/types/number) - a number between 0 and 1023 (included) +* a [number](/reference/types/number) from `0` through `1023` -The following code reads `P1` and charts it on the screen: +This program reads pin `P1` and shows the number +on the LED screen. ```blocks basic.forever(() => { let value = pins.analogReadPin(AnalogPin.P1) - led.plotBarGraph(value, 1023) + basic.showNumber(value) }); ``` ### See also -[micro:bit pins](/device/pins), [on pin pressed](/reference/input/on-pin-pressed), [analog write pin](/reference/pins/analog-write-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin) - +[micro:bit pins](/device/pins), +[on pin pressed](/reference/input/on-pin-pressed), +[analog write pin](/reference/pins/analog-write-pin), +[digital read pin](/reference/pins/digital-read-pin), +[digital write pin](/reference/pins/digital-write-pin) diff --git a/docs/reference/pins/digital-read-pin.md b/docs/reference/pins/digital-read-pin.md index 22ff2443..baa98dbe 100644 --- a/docs/reference/pins/digital-read-pin.md +++ b/docs/reference/pins/digital-read-pin.md @@ -1,24 +1,32 @@ # Digital Read Pin -The digital read pin function. - -Digitally read the specified [pin](/device/pins) (``P0``, ``P1``, ``P2``, ...) as digital. **Some pins are also used by the display, read the [pin documentation ](/device/pins) carefully.** +Read a **digital** (`0` or `1`) signal from a [pin](/device/pins) on +the micro:bit board. ```sig pins.digitalReadPin(DigitalPin.P3) ``` +### ~avatar + +Some pins are also used by the [LED screen](/device/screen). +Please read the [page about pins](/device/pins) carefully. + +### ~ + ### Parameters -* name - the pin name ``P0``, ``P1``, ``P2``, ... +* a [string](/reference/types/string) that stores the name of the pin (``P0``, ``P1``, or ``P2``, up through ``P20``) ### Returns -* [Number](/reference/types/number) - 0 or 1 +* a [number](/reference/types/number) that can be `0` or `1` ### Example: football score keeper -The following example reads `P0` to determine when a goal is scored. When `P0 = 1`, the code uses `digital write pin` to play a buzzer sound: +This program reads pin `P0` to find when a goal is scored. When `P0` +is `1`, the program makes the score bigger and plays a buzzer sound +through `P2` with ``digital write pin``. ```blocks let score = 0 @@ -34,7 +42,29 @@ basic.forever(() => { }) ``` +This program is a remote control for the score keeper program. If you +connect `P1` on the remote control micro:bit to `P0` on the score +keeper micro:bit, you can press button `B` on the remote to buzz and +make the score bigger on the other micro:bit. + +```blocks +input.onButtonPressed(Button.B, () => { + pins.digitalWritePin(DigitalPin.P1, 1); + basic.pause(500); + pins.digitalWritePin(DigitalPin.P1, 0); +}); +``` +#### ~hint + +Remember to connect `GND` on both micro:bits together! + +#### ~ + ### See also -[micro:bit pins](/device/pins), [digital write pin](/reference/pins/digital-write-pin), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [on pin pressed](/reference/input/on-pin-pressed), [pin is pressed](/reference/input/pin-is-pressed) - +[micro:bit pins](/device/pins), +[digital write pin](/reference/pins/digital-write-pin), +[analog read pin](/reference/pins/analog-read-pin), +[analog write pin](/reference/pins/analog-write-pin), +[on pin pressed](/reference/input/on-pin-pressed), +[pin is pressed](/reference/input/pin-is-pressed) diff --git a/docs/reference/pins/digital-write-pin.md b/docs/reference/pins/digital-write-pin.md index 90d862de..72771996 100644 --- a/docs/reference/pins/digital-write-pin.md +++ b/docs/reference/pins/digital-write-pin.md @@ -1,19 +1,29 @@ # Digital Write Pin -Write the value ``0`` or ``1`` to the specified (digital) [pin](/device/pins). **Some pins are also used by the display, read the [pin documentation ](/device/pins) carefully.** +Write a **digital** (`0` or `1`) signal to a [pin](/device/pins) on +the micro:bit board. ```sig pins.digitalWritePin(DigitalPin.P1, 1) ``` +### ~avatar + +Some pins are also used by the [LED screen](/device/screen). +Please read the [page about pins](/device/pins) carefully. + +### ~ + ### Parameters -* name - the pin name (``P0``, ``P1``, ``P2``, ...) -* value - [Number](/reference/types/number); 0 or 1 +* a [string](/reference/types/string) that stores the name of the pin (``P0``, ``P1``, or ``P2``, up through ``P20``) +* a [number](/reference/types/number) that can be either `0` or `1` ### Example: football score keeper -The following example reads `P0` to determine when a goal is scored. When `P0 = 1`, the code uses `digital write pin` to play a buzzer sound: +This program reads pin `P0` to find when a goal is scored. When `P0` +is `1`, the program makes the score bigger and plays a buzzer sound +through `P2` with ``digital write pin``. ```blocks let score = 0 @@ -29,7 +39,25 @@ basic.forever(() => { }) ``` +This program is a remote control for the score keeper program. If you +connect `P1` on the remote control micro:bit to `P0` on the score +keeper micro:bit, you can press button `B` on the remote. This program +will use ``digital write pin`` to make the other micro:bit buzz and +make the score bigger. + +```blocks +input.onButtonPressed(Button.B, () => { + pins.digitalWritePin(DigitalPin.P1, 1); + basic.pause(500); + pins.digitalWritePin(DigitalPin.P1, 0); +}); +``` + ### See also -[micro:bit pins](/device/pins), [digital read pin](/reference/pins/digital-read-pin), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [on pin pressed](/reference/input/on-pin-pressed) +[micro:bit pins](/device/pins), +[digital read pin](/reference/pins/digital-read-pin), +[analog read pin](/reference/pins/analog-read-pin), +[analog write pin](/reference/pins/analog-write-pin), +[on pin pressed](/reference/input/on-pin-pressed) diff --git a/docs/streaming.md b/docs/streaming.md new file mode 100644 index 00000000..f2ce8334 --- /dev/null +++ b/docs/streaming.md @@ -0,0 +1,32 @@ +# Streaming + +This page describes how to stream data from the micro:bit to the editor or even to the cloud. + +## Before starting... + +Make sure you follow the instructions on [how to setup a serial connection](/device/serial) with the micro:bit. + +## A typical scenario + +A common scenario is to chart some sensor data, such as the acceleration, and analyse it in the editor. +For example, run this code on your micro:bit. + +```blocks +basic.forever(() => { + led.plotBarGraph(input.acceleration(Dimension.X), 0); +}); +``` + +If your serial connection is working, you will start to see a chart representing that acceleration ``x`` value read from the micro:bit. +Each time ``led.plotBarGraph`` is called, the value is also written to the serial output. The log view automatically detects +that there is a data stream and displays a graph. + +## Local download + +The log view will automatically start to collect and organize the data it detects. Simply click on the log view to open the various options +to export the data. The simplest option is to download the data as a **CSV file**. This file can easily be opened in programs like Office Excel. + +## Cloud upload via Azure + +In the data export dialog, there is another option to upload the data to the Azure cloud. This allows to upload small amounts of data +without any kind setup. The data can be accessed via web services or directly from Office Excel. \ No newline at end of file diff --git a/docs/windows10.md b/docs/windows10.md index dcb8d66b..3f79bbc3 100644 --- a/docs/windows10.md +++ b/docs/windows10.md @@ -2,17 +2,11 @@ ## Features -The Windows 10 App provides all the existing features of [m.pxt.io](https://m.pxt.io) plus the following ones: +The Windows 10 App provides all the existing features of [codethemicrobit](https://codethemicrobit.com) 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. -## Installing the pre-release app +## Installing the app -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://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). +Coming to the store soon! \ No newline at end of file diff --git a/libs/microbit-bluetooth/bluetooth.cpp b/libs/microbit-bluetooth/bluetooth.cpp index ab995204..81585e9d 100644 --- a/libs/microbit-bluetooth/bluetooth.cpp +++ b/libs/microbit-bluetooth/bluetooth.cpp @@ -1,9 +1,32 @@ #include "pxt.h" #include "MESEvents.h" +#include "MicroBitUARTService.h" using namespace pxt; + +enum Delimiters { + //% block="new line" + NewLine = 1, + //% block="," + Comma = 2, + //% block="$" + Dollar = 3, + //% block=":" + Colon = 4, + //% block="." + Fullstop = 5, + //% block="#" + Hash = 6, +}; + + +/** + * Support for additional Bluetooth services. + */ //% color=#0082FB weight=20 namespace bluetooth { + MicroBitUARTService *uart = NULL; + /** * Starts the Bluetooth IO pin service. */ @@ -57,13 +80,55 @@ namespace bluetooth { void startButtonService() { new MicroBitButtonService(*uBit.ble); } + + /** + * Starts the Bluetooth UART service + */ + // help=bluetooth/start-uart-service + // blockId=bluetooth_start_uart_service block="bluetooth uart service" blockGap=8 + void startUartService() { + if (uart) return; + // 61 octet buffer size is 3 x (MTU - 3) + 1 + // MTU on nRF51822 is 23 octets. 3 are used by Attribute Protocol header data leaving 20 octets for payload + // So we allow a RX buffer that can contain 3 x max length messages plus one octet for a terminator character + uart = new MicroBitUARTService(*uBit.ble, 61, 60); + } - /** + /** + * Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device. + */ + //% help=bluetooth/uart-write + //% blockId=bluetooth_uart_write block="bluetooth uart write %data" blockGap=8 + void uartWrite(StringData *data) { + startUartService(); + uart->send(ManagedString(data)); + } + + /** + * Reads from the Bluetooth UART service buffer, returning its contents when the specified delimiter character is encountered. + */ + //% help=bluetooth/uart-read + //% blockId=bluetooth_uart_read block="bluetooth uart read %del=bluetooth_uart_delimiter_conv" blockGap=8 + StringData* uartRead(StringData *del) { + startUartService(); + return uart->readUntil(ManagedString(del)).leakData(); + } + + /** + * Returns the delimiter corresponding string + */ + //% blockId="bluetooth_uart_delimiter_conv" block="%del" + //% weight=1 + StringData* delimiters(Delimiters del) { + ManagedString c("\n\n,$:.#"[max(0, min(6, (int)del))]); + return c.leakData(); + } + /** * Register code to run when the micro:bit is connected to over Bluetooth * @param body Code to run when a Bluetooth connection is established */ - //% help=bluetooth/on-bluetooth-connected - //% blockId=bluetooth_on_connected block="on bluetooth connected" + //% help=bluetooth/on-bluetooth-connected weight=20 + //% blockId=bluetooth_on_connected block="on bluetooth connected" blockGap=8 void onBluetoothConnected(Action body) { registerWithDal(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, body); } @@ -72,11 +137,11 @@ namespace bluetooth { * Register code to run when a bluetooth connection to the micro:bit is lost * @param body Code to run when a Bluetooth connection is lost */ - //% help=bluetooth/on-bluetooth-disconnected + //% help=bluetooth/on-bluetooth-disconnected weight=19 //% blockId=bluetooth_on_disconnected block="on bluetooth disconnected" void onBluetoothDisconnected(Action body) { registerWithDal(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, body); } -} +} \ No newline at end of file diff --git a/libs/microbit-bluetooth/enums.d.ts b/libs/microbit-bluetooth/enums.d.ts index c1770c7b..b1a4cfa4 100644 --- a/libs/microbit-bluetooth/enums.d.ts +++ b/libs/microbit-bluetooth/enums.d.ts @@ -1,4 +1,20 @@ // Auto-generated. Do not edit. + + + declare enum Delimiters { + //% block="new line" + NewLine = 1, + //% block="," + Comma = 2, + //% block="$" + Dollar = 3, + //% block=":" + Colon = 4, + //% block="." + Fullstop = 5, + //% block="#" + Hash = 6, + } declare namespace bluetooth { } diff --git a/libs/microbit-bluetooth/pxt.json b/libs/microbit-bluetooth/pxt.json index 584ea366..bfa289f0 100644 --- a/libs/microbit-bluetooth/pxt.json +++ b/libs/microbit-bluetooth/pxt.json @@ -21,7 +21,7 @@ "open": 0, "whitelist": 1, "advertising_timeout": 0, - "tx_power": 0, + "tx_power": 6, "dfu_service": 1, "event_service": 1, "device_info_service": 1 diff --git a/libs/microbit-bluetooth/shims.d.ts b/libs/microbit-bluetooth/shims.d.ts index 9d7d49b5..0606d684 100644 --- a/libs/microbit-bluetooth/shims.d.ts +++ b/libs/microbit-bluetooth/shims.d.ts @@ -1,7 +1,9 @@ // Auto-generated. Do not edit. - + /** + * Support for additional Bluetooth services. + */ //% color=#0082FB weight=20 declare namespace bluetooth { @@ -47,19 +49,40 @@ declare namespace bluetooth { //% blockId=bluetooth_start_button_service block="bluetooth button service" blockGap=8 shim=bluetooth::startButtonService function startButtonService(): void; + /** + * Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device. + */ + //% help=bluetooth/uart-write + //% blockId=bluetooth_uart_write block="bluetooth uart write %data" blockGap=8 shim=bluetooth::uartWrite + function uartWrite(data: string): void; + + /** + * Reads from the Bluetooth UART service buffer, returning its contents when the specified delimiter character is encountered. + */ + //% help=bluetooth/uart-read + //% blockId=bluetooth_uart_read block="bluetooth uart read %del=bluetooth_uart_delimiter_conv" blockGap=8 shim=bluetooth::uartRead + function uartRead(del: string): string; + + /** + * Returns the delimiter corresponding string + */ + //% blockId="bluetooth_uart_delimiter_conv" block="%del" + //% weight=1 shim=bluetooth::delimiters + function delimiters(del: Delimiters): string; + /** * Register code to run when the micro:bit is connected to over Bluetooth * @param body Code to run when a Bluetooth connection is established */ - //% help=bluetooth/on-bluetooth-connected - //% blockId=bluetooth_on_connected block="on bluetooth connected" shim=bluetooth::onBluetoothConnected + //% help=bluetooth/on-bluetooth-connected weight=20 + //% blockId=bluetooth_on_connected block="on bluetooth connected" blockGap=8 shim=bluetooth::onBluetoothConnected function onBluetoothConnected(body: () => void): void; /** * Register code to run when a bluetooth connection to the micro:bit is lost * @param body Code to run when a Bluetooth connection is lost */ - //% help=bluetooth/on-bluetooth-disconnected + //% help=bluetooth/on-bluetooth-disconnected weight=19 //% blockId=bluetooth_on_disconnected block="on bluetooth disconnected" shim=bluetooth::onBluetoothDisconnected function onBluetoothDisconnected(body: () => void): void; } diff --git a/libs/microbit-devices/devices.cpp b/libs/microbit-devices/devices.cpp index 3c1b51cf..9e672020 100644 --- a/libs/microbit-devices/devices.cpp +++ b/libs/microbit-devices/devices.cpp @@ -120,7 +120,9 @@ enum class MesDpadButtonInfo { _4Up = MES_DPAD_BUTTON_4_UP, }; - +/** + * Control a phone with the BBC micro:bit via Bluetooth. + */ //% color=156 weight=80 namespace devices { static void genEvent(int id, int event) { diff --git a/libs/microbit-devices/shims.d.ts b/libs/microbit-devices/shims.d.ts index 64fdb60c..9b152593 100644 --- a/libs/microbit-devices/shims.d.ts +++ b/libs/microbit-devices/shims.d.ts @@ -1,7 +1,9 @@ // Auto-generated. Do not edit. - + /** + * Control a phone with the BBC micro:bit via Bluetooth. + */ //% color=156 weight=80 declare namespace devices { diff --git a/package.json b/package.json index 42a22644..08d69d99 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pxt-microbit", - "version": "0.2.174", + "version": "0.2.180", "description": "BBC micro:bit target for PXT", "keywords": [ "JavaScript", @@ -29,6 +29,6 @@ "typescript": "^1.8.7" }, "dependencies": { - "pxt-core": "0.2.185" + "pxt-core": "0.2.190" } } diff --git a/pxtarget.json b/pxtarget.json index 1cd50988..d156eec5 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -1,7 +1,7 @@ { "id": "microbit", - "name": "m.pxt.io", - "title": "m.pxt.io", + "name": "code the micro:bit", + "title": "code the micro:bit", "corepkg": "microbit", "bundleddirs": [ "libs/microbit", @@ -81,14 +81,14 @@ }, "appTheme": { "accentColor": "#5C005C", - "logoUrl": "https://m.pxt.io/about", + "logoUrl": "https://codethemicrobit.com/about", "logo": "./static/microbit.simplified.svg", "docsLogo": "./static/microbit.simplified.svg", "portraitLogo": "./static/microbit.simplified.svg", "footerLogo": "./static/microbit.simplified.svg", "organizationLogo": "./static/Microsoft-logo_rgb_c-gray.png", - "homeUrl": "https://m.pxt.io/", - "embedUrl": "https://m.pxt.io/", + "homeUrl": "https://codethemicrobit.com/", + "embedUrl": "https://codethemicrobit.com/", "privacyUrl": "https://go.microsoft.com/fwlink/?LinkId=521839", "termsOfUseUrl": "https://go.microsoft.com/fwlink/?LinkID=206977", "boardName": "BBC micro:bit", @@ -112,6 +112,10 @@ { "name": "JavaScript", "path": "/javascript" + }, + { + "name": "Streaming Data", + "path": "/streaming" } ], "sideDoc": "getting-started" diff --git a/testconv.json b/testconv.json index ae8b3095..c80cba75 100644 --- a/testconv.json +++ b/testconv.json @@ -142,7 +142,6 @@ "fbpnng", "fbyrog", "fcfoox", - "fcgdzt", "fcicvk", "fcjlto", "fcvwvj",