Compare commits
81 Commits
Author | SHA1 | Date | |
---|---|---|---|
055704b3ef | |||
60107aa7ce | |||
787ab021a7 | |||
f56a70f502 | |||
4ec6749ee6 | |||
8413b61397 | |||
ecbb970983 | |||
36e6570296 | |||
92c63b615a | |||
f71267c988 | |||
38fc0f8099 | |||
8c7238eab3 | |||
2baca30184 | |||
ac56979142 | |||
ff72858c42 | |||
deac587164 | |||
7a0a2fbd0a | |||
79c32097b5 | |||
26c20d9fc3 | |||
fe826a508a | |||
62d2140d24 | |||
499d619faf | |||
c178e58260 | |||
d242501fe6 | |||
37a438735d | |||
b862cfc4ec | |||
31002ae1a8 | |||
e8a3a2f676 | |||
e6baf8c35e | |||
b72ff9fe4f | |||
58f79ea617 | |||
ed6d343992 | |||
92b46d5c7b | |||
9cf7f08ae2 | |||
3b05b8f2f6 | |||
774d614d79 | |||
545f715eeb | |||
45b480c6dd | |||
7cc93507d9 | |||
80d3f67e6c | |||
dfbea2719b | |||
ce5da6bf80 | |||
d8d2129685 | |||
5dd37a1494 | |||
6cfe39dac3 | |||
660b22b398 | |||
b9a24a4542 | |||
af5bf6e04e | |||
ecc71a3295 | |||
0834402b18 | |||
8edd8ac73a | |||
1207a91a7f | |||
727490668c | |||
f068b3d204 | |||
205a486e58 | |||
f3bfd41a75 | |||
8d5c5daaaf | |||
83cfe8f534 | |||
9378e5e90c | |||
8617f0f3b4 | |||
0ecf3dc2b4 | |||
76005841fa | |||
7bf00ff139 | |||
82e34d852c | |||
7cd8ee1e23 | |||
a91a87b628 | |||
9d71f46e78 | |||
ccf405e64c | |||
c0a75d1845 | |||
e65a521bd4 | |||
1f203269ff | |||
18feea45bb | |||
597f0c895b | |||
5f21789d90 | |||
64826db4aa | |||
b150ee873f | |||
34effcefc6 | |||
68be2384d9 | |||
2629192bdb | |||
67b5afd73a | |||
5d8193301c |
10
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)
|
||||
|
||||
[](https://travis-ci.org/Microsoft/pxt-microbit)
|
||||
|
||||
@ -47,9 +47,13 @@ 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
|
||||
|
||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
||||
|
26
clients/chrome/README.md
Normal file
@ -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
|
||||
````
|
68
clients/chrome/background.js
Normal file
@ -0,0 +1,68 @@
|
||||
///<reference path='typings/browser.d.ts'/>
|
||||
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);
|
92
clients/chrome/background.ts
Normal file
@ -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(<Message>{
|
||||
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);
|
BIN
clients/chrome/logo128.png
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
clients/chrome/logo48.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
30
clients/chrome/manifest.json
Normal file
@ -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/*" ]
|
||||
}
|
||||
}
|
BIN
clients/chrome/screenshot.png
Normal file
After Width: | Height: | Size: 138 KiB |
7
clients/chrome/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"compiler-options": {
|
||||
"target": "ES5",
|
||||
"module": "amd",
|
||||
"sourceMap": false
|
||||
}
|
||||
}
|
48
clients/win10/app/codethemicrobitapp.sln
Normal file
@ -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
|
@ -14,13 +14,13 @@
|
||||
<Resource Language="x-generate" />
|
||||
</Resources>
|
||||
<Applications>
|
||||
<Application Id="App" StartPage="https://m.pxt.io/">
|
||||
<Application Id="App" StartPage="https://codethemicrobit.com">
|
||||
<uap:ApplicationContentUriRules>
|
||||
<uap:Rule Match="https://m.pxt.io/" Type="include" WindowsRuntimeAccess="all" />
|
||||
<uap:Rule Match="https://codemicrobit.com/" Type="include" WindowsRuntimeAccess="all" />
|
||||
<uap:Rule Match="https://codethemicrobit.com/" Type="include" WindowsRuntimeAccess="all" />
|
||||
</uap:ApplicationContentUriRules>
|
||||
<uap:VisualElements DisplayName="codethemicrobit" Description="Code editors for the BBC micro:bit" BackgroundColor="white" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png">
|
||||
<uap:VisualElements DisplayName="code the micro:bit" Description="A code editor for the BBC micro:bit with Blocks or Javascript." BackgroundColor="white" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png">
|
||||
<uap:DefaultTile Wide310x150Logo="images\Wide310x150Logo.png" ShortName="code the micro:bit">
|
||||
</uap:DefaultTile>
|
||||
<uap:SplashScreen Image="images\splashscreen.png" />
|
||||
|
@ -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
|
66
clients/winuploader/CodeTheMicroBit.sln
Normal file
@ -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
|
@ -8,7 +8,7 @@
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Microsoft.MicroBit</RootNamespace>
|
||||
<AssemblyName>Microbit.Uploader</AssemblyName>
|
||||
<AssemblyName>CodeTheMicrobit</AssemblyName>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import * as child_process from "child_process";
|
||||
|
||||
let writeFileAsync: any = Promise.promisify(fs.writeFile)
|
||||
let execAsync: (cmd: string, options?: { cwd?: string }) => Promise<Buffer> = Promise.promisify(child_process.exec)
|
||||
let readDirAsync = Promise.promisify(fs.readdir)
|
||||
|
||||
|
||||
export function deployCoreAsync(res: ts.pxt.CompileResult) {
|
||||
return getBitDrivesAsync()
|
||||
@ -37,6 +39,10 @@ function getBitDrivesAsync(): Promise<string[]> {
|
||||
})
|
||||
return res
|
||||
})
|
||||
}
|
||||
else if (process.platform == "darwin") {
|
||||
return readDirAsync("/Volumes")
|
||||
.then(lst => lst.filter(s => /MICROBIT/.test(s)).map(s => "/Volumes/" + s + "/"))
|
||||
} else {
|
||||
return Promise.resolve([])
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
### ~
|
81
docs/getting-started/buttons.md
Normal file
@ -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
|
||||
### ~
|
78
docs/getting-started/coin-flipper.md
Normal file
@ -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
|
||||
### ~
|
205
docs/getting-started/rock-paper-scissors.md
Normal file
@ -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!
|
||||
### ~
|
98
docs/getting-started/screen.md
Normal file
@ -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
|
||||
### ~
|
24
docs/getting-started/shake.md
Normal file
@ -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
|
||||
### ~
|
58
docs/js/call.md
Normal file
@ -0,0 +1,58 @@
|
||||
# Call a function
|
||||
|
||||
The simplest way to get started in JavaScript with your micro:bit is to
|
||||
call one of the micro:bit's built-in JavaScript functions. Just like Blocks
|
||||
are organized into categories/drawers, the micro:bit functions are organized by
|
||||
namespaces. The `basic` namespace contains a number of very helpful
|
||||
functions:
|
||||
|
||||
```typescript
|
||||
basic.showString("Hello!")
|
||||
```
|
||||
|
||||
If you want to see all functions available in a namespace, simply type `basic`
|
||||
followed by `.`; a list of all the functions will appear.
|
||||
|
||||

|
||||
|
||||
Continue typing to select one of the functions, or click on one of the functions
|
||||
to select. You also narrow down the set of functions by typing, as below:
|
||||
|
||||

|
||||
|
||||
# Function parameters
|
||||
|
||||
You might have noticed that the call `showString` above takes one value,
|
||||
the string to be scrolled on the LED screen. There is a second (optional)
|
||||
parameter that controls the speed of the the scroll. Try this:
|
||||
|
||||
```typescript
|
||||
basic.showString("Hello!",50)
|
||||
```
|
||||
|
||||
You might have noticed that the function list above shows all
|
||||
the available parameters for each function.
|
||||
|
||||
|
||||
```typescript
|
||||
basic.showString("Hello!")
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. . # . .
|
||||
# . . . #
|
||||
. # # # .
|
||||
`)
|
||||
basic.pause(1000)
|
||||
basic.clearScreen()
|
||||
basic.showString("Goodbye!")
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. . . . .
|
||||
. # # # .
|
||||
# . . . #
|
||||
`)
|
||||
basic.pause(1000)
|
||||
basic.clearScreen()
|
||||
```
|
@ -1,11 +1,7 @@
|
||||
# Ten Projects
|
||||
|
||||
### ~avatar avatar
|
||||
# Projects
|
||||
|
||||
Here are some cool projects that you can build with your micro:bit!
|
||||
|
||||
### ~
|
||||
|
||||
|
||||
```codecard
|
||||
[{
|
||||
|
@ -59,5 +59,6 @@ input.onPinPressed(TouchPin.P2, () => {
|
||||
|
||||
* click *run* to see if the code works as expected.
|
||||
|
||||
|
||||
|
||||
### ~button /projects/telegraph
|
||||
NEXT: Telegraph
|
||||
### ~
|
@ -104,3 +104,6 @@ basic.forever(() => {
|
||||
});
|
||||
```
|
||||
|
||||
### ~button /projects/hack-your-headphones
|
||||
NEXT: Hack Your Headphones
|
||||
### ~
|
@ -112,4 +112,8 @@ basic.pause(500);
|
||||
basic.clearScreen();
|
||||
basic.pause(500);
|
||||
})
|
||||
```
|
||||
```
|
||||
|
||||
### ~button /projects/smiley-buttons
|
||||
NEXT: Smiley Buttons
|
||||
### ~
|
@ -71,3 +71,6 @@ input.onButtonPressed(Button.A, () => {
|
||||
|
||||
* click *compile* and run your code on the micro:bit.
|
||||
|
||||
### ~button /projects/banana-keyboard
|
||||
NEXT: Banana Keyboard
|
||||
### ~
|
@ -47,4 +47,8 @@ input.onPinPressed(TouchPin.P2, () => {
|
||||
. . # . .
|
||||
`);
|
||||
});
|
||||
```
|
||||
```
|
||||
|
||||
### ~button /projects/rock-paper-scissors
|
||||
NEXT: Rock Paper Scissors
|
||||
### ~
|
@ -86,3 +86,7 @@ Have fun reviewing your simulation and analyze the acceleration by chart the Exc
|
||||
* The first person and second person take turns tilting the micro:bit in the "x" direction while the other player charts the data on the micro:bit!
|
||||
* Review and analyze the actual micro:bit device acceleration data on Excel
|
||||
* Display acceleration with y or z using plot bar graph by changing acceleration from "x" to "y" or "z"
|
||||
|
||||
### ~button /projects/the-watch
|
||||
NEXT: The Watch
|
||||
### ~
|
@ -235,3 +235,7 @@ input.onButtonPressed(Button.B, () => {
|
||||
|
||||
How else can you make your game better?
|
||||
Ever hear of [Rock Paper Scissors Spock Lizard](http://www.samkass.com/theories/RPSSL.html)?
|
||||
|
||||
### ~button /projects/compass
|
||||
NEXT: Compass
|
||||
### ~
|
@ -66,4 +66,8 @@ input.onButtonPressed(Button.B, () => {
|
||||
# . . . #
|
||||
. # # # .`);
|
||||
});
|
||||
```
|
||||
```
|
||||
|
||||
### ~button /projects/love-meter
|
||||
NEXT: Love Meter
|
||||
### ~
|
@ -108,3 +108,7 @@ Your telegraph is ready!
|
||||
* Connect the first micro:bit to your computer using your USB cable and put the telegraph script on it.
|
||||
* Connect the second micro:bit to your computer using your USB cable and run the telegraph script on it.
|
||||
* The first person and second person take turns pressing button A to play the telegraph game!
|
||||
|
||||
### ~button /projects/radio
|
||||
NEXT: Radio
|
||||
### ~
|
@ -21,4 +21,16 @@ serial.writeNumber(0);
|
||||
control.inBackground(() => {
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
## Advanced
|
||||
|
||||
```namespaces
|
||||
devices.tellCameraTo(MesCameraEvent.TakePhoto);
|
||||
bluetooth.onBluetoothConnected(() => {});
|
||||
```
|
||||
|
||||
```package
|
||||
microbit-devices
|
||||
microbit-bluetooth
|
||||
```
|
24
docs/reference/bluetooth.md
Normal file
@ -0,0 +1,24 @@
|
||||
# Bluetooth
|
||||
|
||||
Support for additional Bluetooth services.
|
||||
|
||||
```cards
|
||||
bluetooth.startAccelerometerService();
|
||||
bluetooth.startButtonService();
|
||||
bluetooth.startIOPinService();
|
||||
bluetooth.startLEDService();
|
||||
bluetooth.startMagnetometerService();
|
||||
bluetooth.startTemperatureService();
|
||||
bluetooth.uartRead("");
|
||||
bluetooth.uartWrite("");
|
||||
bluetooth.onBluetoothConnected(() => {
|
||||
|
||||
});
|
||||
bluetooth.onBluetoothDisconnected(() => {
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
```package
|
||||
microbit-bluetooth
|
||||
```
|
99
docs/reference/bluetooth/about-bluetooth.md
Executable file
@ -0,0 +1,99 @@
|
||||
# About Bluetooth
|
||||
|
||||

|
||||
|
||||
## Introduction
|
||||
|
||||
Bluetooth is a wireless communications technology which allows devices to communicate with each other without the need for a central device like a router or access point.
|
||||
|
||||
Bluetooth has a special "low energy feature" which means it can be used without requiring much power from the devices using it. It's the Bluetooth low energy feature which the micro:bit uses.
|
||||
|
||||
In the world of Bluetooth low energy, a device has something called a "profile" which defines the way other devices are able to communicate over Bluetooth with it. In a way, the Bluetooth profile defines the way a device appears to other devices in terms of its features and the things it can do.
|
||||
|
||||
To put it another way, a Bluetooth profile is really an interface specification. It defines the data which a device has, what another device can do with that data over a Bluetooth connection and how the device with the profile should respond when a connected device acts upon its data in some way. Let's look at that description in a little more technical detail.
|
||||
|
||||
## Basic Concepts
|
||||
|
||||
A Bluetooth device contains a table of data called an Attribute Table which can be accessed by other connected devices in various possible ways. That table of data and the ways in which it can be exploited falls into a technical area of Bluetooth called the Generic Attribute profile or "GATT" for short and you may see the term GATT in some of the documentation for APIs such as those provided by the Android platform.
|
||||
|
||||
The Attribute Table contains something like a series of records of various types. The main types are called Services, Characteristics and Descriptors. Let's look at each of these terms in turn.
|
||||
|
||||
### Attributes
|
||||
|
||||
Services, Characteristics and Descriptors are all types of Attribute. Hence Generic Attribute Profile, Attribute Table and something called the Attribute Protocol. All attributes have a type which is identified by a UUID (Universally Unique Identifer). Some Attributes are defined by the Bluetooth SIG, the technical standards body for Bluetooth and these have UUIDs which are 16 bits in length. Some Attributes are custom designed for a particular device by the product team and these have 128 bit UUIDs. The micro:bit uses a mixture of 16 bit and 128 bit UUIDs.
|
||||
|
||||
### Structure
|
||||
|
||||
Services, Characteristics and Descriptors are organised in a hierarchy with Services at the top and Descriptors at the bottom. Services contain one or more Characteristics. A Characteristic owns zero or more Descriptors. Zero because Descriptors are completely optional whereas a Service must contain at least one Characteristic.
|
||||
|
||||

|
||||
|
||||
### Services
|
||||
|
||||
A Service is a container for logically related Bluetooth data items. Those data items are in fact called Characteristics. A Service can be thought of as the owner of the Characteristics inside it. Often a Service represents a particular feature (e.g. a hardware feature) of a device like the buttons or a particular sensor. An example of a Bluetooth SIG defined Service is the Device Information Service which, as the name suggests, is a container for various items of information about the device such as its manufacturer and serial number. The micro:bit has this service.
|
||||
|
||||
### Characteristics
|
||||
|
||||
Characteristics are items of data which relate to a particular internal state of the device or perhaps some state of the environment which the device can measure using a sensor. The current battery level is an example of internal state data whereas the ambient temperature could perhaps be measured by a sensor. Sometimes Characteristics represent configuration data such as the frequency at which you want something to be measured. In any of these cases, the way a device can expose such data to other devices to use via Bluetooth is by making them available as a Characteristic. An example of a Bluetooth SIG defined Characteristic is the Serial Number String which you'll find inside the Device Information service.
|
||||
|
||||
Characteristics contain various parts. They have a type, a value, some properties and some permissions.
|
||||
|
||||
Type is something already explained above, a UUID value which indicates which particular type of Characteristic an Attribute is. Value is the value of the associated state data item.
|
||||
|
||||
Properties define what another device can do with the characteristic over Bluetooth in terms of various defined operations such as READ, WRITE or NOTIFY. Reading a characteristic means transferring its current value from the attribute table to the connected device over Bluetooth. Writing allows the connected device to change that value in the state table. Notifications are a special message type which a device like the micro:bit can send to a connected device whenever the value of the associated characteristic changes or perhaps periodically, controlled by a timer. Not all Characteristics support all operations. The Characteristic's properties tell you which operations are supported.
|
||||
|
||||
Sometimes the device will have been programmed to respond in a special way when it processes an operation like reading or writing a value from the attribute table so operations can result in more happening than simply transferring data across the connection. Perhaps changing the value of a Characteristic will result in the device changing the frequency with which it samples readings from the device accelerometer for example.
|
||||
|
||||
Permissions are to do with security and further describe the security conditions that must be met before read or write access to the characteristic is to be granted.
|
||||
|
||||
### Descriptors
|
||||
|
||||
Descriptors contain meta data which either augments the details relating to the Characteristic which the Descriptor belongs to or allows the configuration of a behaviour involving that Characteristic. Notification messages are switched on or off using a special descriptor called the Client Characteristic Configuration Descriptor for example.
|
||||
|
||||
### Profile
|
||||
|
||||
A Bluetooth profile is a specification which pulls together all the required information about how a device behaves, how it can be accessed in terms of its services, characteristics and descriptors, security rules, concurrency limitations and so on.
|
||||
|
||||
## Client Server Architecture
|
||||
|
||||
When a smartphone application interacts with a device like the micro:bit over a Bluetooth connection we have a client/server architecture. The phone application is usually the GATT client and the micro:bit is usually the GATT server. They communicate using a protocol called the Attribute Protocol or just ATT for short. As a smartphone developer you work with APIs and do not have to worry about formulating ATT protocol data units and so on.
|
||||
|
||||

|
||||
|
||||
## Device Discovery
|
||||
|
||||
Everything described above relates to devices which are connected and communicating as GATT client and server. But there's a stage which precedes this where the two devices are not yet connected. How do they find each other and connect? The answer to this question is termed 'Device Discovery' and is the responsibility of another part of the Bluetooth architecture called the Generic Access Profile (GAP).
|
||||
|
||||
In GAP, one devices advertises, emitting small packets of data periodically. These packets contain information about the device doing the advertising. Other devices looking for devices to connect to perform something called scanning, receiving and processing advertising packets and filtering out those that come from devices of a type that are not of interest. Usually the user is given information about devices which are discovered and they then select one to be connected to. The device which advertises is called a Bluetooth Peripheral whereas the one doing the scanning is a Bluetooth Central device. micro:bit is a Bluetooth peripheral.
|
||||
|
||||
Bluetooth on the BBC micro:bit
|
||||
|
||||
Full documentation for the BBC micro:bit Bluetooth profile as used by this application can be found at the [Lancaster University documentation](http://lancaster-university.github.io/microbit-docs/ble/profile/) web site.
|
||||
|
||||
The micro:bit's accelerometer (motion detector), magnetometer (digital compass), two buttons on the front, LED Display, IO pins on the edge connector, internal message bus and internal temperature sensor are all exposed as Services so that applications can exploit these features of the device. In addition:
|
||||
|
||||
* the Bluetooth SIG defined Device Information Service is included to allow applications to obtain information such as firmware version details over Bluetooth
|
||||
* there's a Device Firmware Update (DFU) service which allows new micro:bit code to be flahsed to the device over Bluetooth instead of over USB
|
||||
* there's a UART service which allows arbitrary data to be exchanged with the micro:bit in a way resembling traditional serial communications.
|
||||
|
||||
Everything you can do with the micro:bit over Bluetooth is achieved through read, write and notify operations. Not all characteristics support all three so check the profile documentation. Often there are Characteristics whose purpose is to allow you to write configuration values which control other behviours. Technically these are called Control Points. For example you can specify the frequency with which accelerometer data is sampled before it is transmitted as a Notification message to your application.
|
||||
|
||||
## Want to Know More?
|
||||
|
||||
The Bluetooth SIG web site at http://www.bluetooth.com is a good place for further information about Bluetooth in general. You'll find all the SIG defined profiles, services, characteristics and descriptors there as well as the core specification for all Bluetooth technology.
|
||||
|
||||
That's it! Enjoy using Bluetooth on the BBC micro:bit!
|
||||
|
||||
Martin Woolley, Bluetooth SIG. Twitter: @bluetooth_mdw
|
||||
|
||||
#### Video
|
||||
https://www.youtube.com/watch?v=aep_GVowKfs
|
||||
|
||||
|
||||
### See also
|
||||
|
||||
[About Bluetooth](/reference/bluetooth/about-bluetooth), [micro:bit Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [micro:bit Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html), [Bluetooth SIG](https://www.bluetooth.com)
|
||||
|
||||
```package
|
||||
microbit-bluetooth
|
||||
```
|
100
docs/reference/bluetooth/bluetooth-pairing.md
Executable file
@ -0,0 +1,100 @@
|
||||
# Bluetooth Pairing
|
||||
|
||||
### ~hint
|
||||

|
||||
|
||||
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
|
||||
|
||||
[About Bluetooth](/reference/bluetooth/about-bluetooth), [micro:bit Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [micro:bit Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html), [Bluetooth SIG](https://www.bluetooth.com)
|
||||
|
||||
|
||||
```package
|
||||
microbit-bluetooth
|
||||
```
|
@ -3,7 +3,7 @@
|
||||
### ~hint
|
||||

|
||||
|
||||
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.
|
||||
|
||||
### ~
|
||||
|
||||
@ -30,7 +30,7 @@ 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)
|
||||
[About Bluetooth](/reference/bluetooth/about-bluetooth), [micro:bit Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [micro:bit Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html), [Bluetooth SIG](https://www.bluetooth.com)
|
||||
|
||||
```package
|
||||
microbit-bluetooth
|
||||
|
@ -1,33 +1,37 @@
|
||||
# On Bluetooth Disconnected
|
||||
|
||||
### ~hint
|
||||

|
||||
|
||||
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
|
||||
|
||||
[](
|
||||
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)
|
||||
[About Bluetooth](/reference/bluetooth/about-bluetooth), [micro:bit Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [micro:bit Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html), [Bluetooth SIG](https://www.bluetooth.com)
|
||||
|
||||
```package
|
||||
microbit-bluetooth
|
||||
```
|
||||
|
@ -1,30 +1,33 @@
|
||||
# Bluetooth Accelerometer Service
|
||||
|
||||
### ~hint
|
||||

|
||||
|
||||
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
|
||||
|
||||
[](
|
||||
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)
|
||||
[About Bluetooth](/reference/bluetooth/about-bluetooth), [micro:bit Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [micro:bit Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html), [Bluetooth SIG](https://www.bluetooth.com)
|
||||
|
||||
```package
|
||||
microbit-bluetooth
|
||||
```
|
||||
|
@ -1,7 +1,12 @@
|
||||
# Bluetooth Button Service
|
||||
|
||||
### ~hint
|
||||

|
||||
|
||||
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
|
||||
|
||||
[](
|
||||
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)
|
||||
[About Bluetooth](/reference/bluetooth/about-bluetooth), [micro:bit Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [micro:bit Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html), [Bluetooth SIG](https://www.bluetooth.com)
|
||||
|
||||
```package
|
||||
microbit-bluetooth
|
||||
```
|
||||
|
@ -1,28 +1,31 @@
|
||||
# Bluetooth IO Pin Service
|
||||
|
||||
### ~hint
|
||||

|
||||
|
||||
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
|
||||
|
||||
[](
|
||||
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)
|
||||
[About Bluetooth](/reference/bluetooth/about-bluetooth), [micro:bit Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [micro:bit Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html), [Bluetooth SIG](https://www.bluetooth.com)
|
||||
|
||||
```package
|
||||
microbit-bluetooth
|
||||
```
|
||||
|
@ -1,30 +1,33 @@
|
||||
# Bluetooth LED Service
|
||||
|
||||
### ~hint
|
||||

|
||||
|
||||
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
|
||||
|
||||
[](
|
||||
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)
|
||||
[About Bluetooth](/reference/bluetooth/about-bluetooth), [micro:bit Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [micro:bit Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html), [Bluetooth SIG](https://www.bluetooth.com)
|
||||
|
||||
```package
|
||||
microbit-bluetooth
|
||||
```
|
||||
|
@ -1,30 +1,33 @@
|
||||
# Bluetooth Magnetometer Service
|
||||
|
||||
### ~hint
|
||||

|
||||
|
||||
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
|
||||
|
||||
[](
|
||||
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)
|
||||
[About Bluetooth](/reference/bluetooth/about-bluetooth), [micro:bit Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [micro:bit Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [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
|
||||
```
|
||||
|
@ -1,30 +1,33 @@
|
||||
# Bluetooth Temperature Service
|
||||
|
||||
### ~hint
|
||||

|
||||
|
||||
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
|
||||
|
||||
[](
|
||||
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)
|
||||
[About Bluetooth](/reference/bluetooth/about-bluetooth), [micro:bit Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [micro:bit Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [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
|
||||
```
|
||||
|
||||
|
44
docs/reference/bluetooth/start-uart-service.md
Executable file
@ -0,0 +1,44 @@
|
||||
# Bluetooth UART Service
|
||||
|
||||
### ~hint
|
||||

|
||||
|
||||
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
|
||||
|
||||
[About Bluetooth](/reference/bluetooth/about-bluetooth), [micro:bit Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [micro:bit Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html), [Bluetooth SIG](https://www.bluetooth.com)
|
||||
|
||||
```package
|
||||
microbit-bluetooth
|
||||
```
|
52
docs/reference/bluetooth/uart-read.md
Executable file
@ -0,0 +1,52 @@
|
||||
# UART Read
|
||||
|
||||
### ~hint
|
||||

|
||||
|
||||
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
|
||||
|
||||
[About Bluetooth](/reference/bluetooth/about-bluetooth), [micro:bit Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [micro:bit Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html), [Bluetooth SIG](https://www.bluetooth.com)
|
||||
|
||||
```package
|
||||
microbit-bluetooth
|
||||
```
|
51
docs/reference/bluetooth/uart-write.md
Executable file
@ -0,0 +1,51 @@
|
||||
# UART Write
|
||||
|
||||
### ~hint
|
||||

|
||||
|
||||
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
|
||||
|
||||
[About Bluetooth](/reference/bluetooth/about-bluetooth), [micro:bit Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [micro:bit Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html), [Bluetooth SIG](https://www.bluetooth.com)
|
||||
|
||||
```package
|
||||
microbit-bluetooth
|
||||
```
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
19
docs/reference/devices.md
Normal file
@ -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(() => {
|
||||
|
||||
});
|
||||
```
|
@ -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)
|
||||
|
||||
|
37
docs/reference/input/set-accelerometer-range.md
Normal file
@ -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)
|
@ -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
|
||||
|
||||
|
@ -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,35 @@ pins.analogReadPin(AnalogPin.P0)
|
||||
|
||||
### Parameters
|
||||
|
||||
* name - the pin name (`P0`, `P1`, or `P2`)
|
||||
* a [string](/reference/types/string) with 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)
|
||||
});
|
||||
```
|
||||
|
||||
#### ~hint
|
||||
|
||||
If you are using **analog read pin** with another micro:bit
|
||||
running **analog write pin**, it is a good idea to check
|
||||
**analog read pin** many times and then take an average.
|
||||
|
||||
#### ~
|
||||
|
||||
### 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)
|
||||
|
@ -1,6 +1,8 @@
|
||||
# Analog Set Period
|
||||
|
||||
Configures the period of the Pulse Width Modulation (PWM) on the specified analog [pin](/device/pins) (``P0``, ``P1`` or ``P2``). Prior to calling this function, the given pin should be set as analog.
|
||||
Configure the period of Pulse Width Modulation (PWM) on the specified
|
||||
analog [pin](/device/pins).
|
||||
Before you call this function, you should set the specified pin as analog.
|
||||
|
||||
```sig
|
||||
pins.analogSetPeriod(AnalogPin.P0, 20000)
|
||||
@ -8,10 +10,11 @@ pins.analogSetPeriod(AnalogPin.P0, 20000)
|
||||
|
||||
### Parameters
|
||||
|
||||
* `name` - [String](/reference/types/string); the pin name ("P0", "P1", or "P2")
|
||||
* `micros` - a [Number](/reference/types/number) representing the micro-seconds of the analog period.
|
||||
* `pin`: a [string](/reference/types/string) that specifies the pin to configure (`P0` through `P4`, or `P10`)
|
||||
* `μs`: a [number](/reference/types/number) that specifies the analog period in microseconds.
|
||||
|
||||
The following code
|
||||
The following code first sets `P0` to analog with **analog write
|
||||
pin**, and then sets the PWM period of `P0` to 20,000 microseconds.
|
||||
|
||||
```blocks
|
||||
pins.analogWritePin(AnalogPin.P0, 512)
|
||||
@ -20,5 +23,9 @@ pins.analogSetPeriod(AnalogPin.P0, 20000)
|
||||
|
||||
### See also
|
||||
|
||||
[micro:bit pins](/device/pins), [on pin pressed](/reference/input/on-pin-pressed), [analog read pin](/reference/pins/analog-read-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 read pin](/reference/pins/analog-read-pin),
|
||||
[analog write pin](/reference/pins/analog-write-pin),
|
||||
[digital read pin](/reference/pins/digital-read-pin),
|
||||
[digital write pin](/reference/pins/digital-write-pin)
|
||||
|
@ -1,6 +1,7 @@
|
||||
# Analog Write Pin
|
||||
|
||||
Write to the specified [pin](/device/pins) (P0, P1, P2) as analog.
|
||||
Write an **analog** signal (`0` through `1023`) to the
|
||||
[pin](/device/pins) you say.
|
||||
|
||||
```sig
|
||||
pins.analogWritePin(AnalogPin.P0, 400)
|
||||
@ -8,15 +9,25 @@ pins.analogWritePin(AnalogPin.P0, 400)
|
||||
|
||||
### Parameters
|
||||
|
||||
* `name` - [String](/reference/types/string); the pin name ("P0", "P1", or "P2")
|
||||
* `value` - a [Number](/reference/types/number) between 0 and 1023 included
|
||||
* a [string](/reference/types/string) that is the pin name you say (`P0` through `P4`, or `P10`)
|
||||
* a [number](/reference/types/number) from `0` through `1023`
|
||||
|
||||
The following code writes `1023` to the `P0` pin:
|
||||
### Example
|
||||
|
||||
This program writes `1023` to pin `P0`.
|
||||
|
||||
```blocks
|
||||
pins.analogWritePin(AnalogPin.P0, 1023)
|
||||
```
|
||||
|
||||
#### ~hint
|
||||
|
||||
When you tell it to write `256` (for example), this function does not
|
||||
_really_ write `256`. Instead, it writes a lot of different numbers,
|
||||
and their average is `256`.
|
||||
|
||||
#### ~
|
||||
|
||||
### See also
|
||||
|
||||
[micro:bit pins](/device/pins), [on pin pressed](/reference/input/on-pin-pressed), [analog read pin](/reference/pins/analog-read-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
@ -1,8 +1,14 @@
|
||||
# Map
|
||||
|
||||
Re-maps a number from one range to another. That is, a value of ``from low`` would get mapped to ``to low``, a value of ``from high`` to ``to high``, values in-between to values in-between, etc.
|
||||
Remaps the specified value from one range to another. This function
|
||||
maps the value of ``from low`` to the value of ``to low``, the value
|
||||
of ``from high`` to the value of ``to high``, and intermediate values
|
||||
to intermediate values.
|
||||
|
||||
Does not constrain values to within the range, because out-of-range values are sometimes intended and useful. The `math->clamp` function may be used either before or after this function, if limits to the ranges are desired.
|
||||
This function does not constrain values to the ranges, because
|
||||
out-of-range values are sometimes intended and useful. If you need to
|
||||
limit a range, you can use the ``Math.clamp`` function before or after
|
||||
calling this function.
|
||||
|
||||
```sig
|
||||
pins.map(0, 0, 4, 0, 1023);
|
||||
@ -10,15 +16,16 @@ pins.map(0, 0, 4, 0, 1023);
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``value``: [Number](/reference/types/number) - the value to map
|
||||
* ``from low``: [Number](/reference/types/number) - lower bound of the origin interval
|
||||
* ``from high``: [Number](/reference/types/number) - upper bound of the origin interval
|
||||
* ``to low``: [Number](/reference/types/number) - lower bound of the target interval
|
||||
* ``to high``: [Number](/reference/types/number) - upper bound of the target interval
|
||||
* ``value``: a [number](/reference/types/number) that specifies the value to map
|
||||
* ``from low``: a [number](/reference/types/number) that specifies the lower bound of the origin interval
|
||||
* ``from high``: a [number](/reference/types/number) that specifies the upper bound of the origin interval
|
||||
* ``to low``: a [number](/reference/types/number) that specifies the lower bound of the target interval
|
||||
* ``to high``: a [number](/reference/types/number) that specifies the upper bound of the target interval
|
||||
|
||||
## Example
|
||||
|
||||
Map the value read from the analog pin ``P0`` to an LED index between ``0`` and ``4``.
|
||||
This example maps the value read from the analog pin `P0` to an LED
|
||||
coordinate between `0` and `4`.
|
||||
|
||||
```blocks
|
||||
let value1 = pins.analogReadPin(AnalogPin.P0)
|
||||
|
@ -1,6 +1,7 @@
|
||||
# Servo Set Pulse
|
||||
|
||||
Configures the pin [pin](/device/pins) (``P0``, ``P1`` or ``P2``) as an analog/PWM output if it isn't already, configures the period to be 20ms, and sets the pulse width, based on the value it is given.
|
||||
Configure the specified pin as analog output, set the period to 20
|
||||
ms, and set the pulse width to the specified value.
|
||||
|
||||
```sig
|
||||
pins.servoSetPulse(AnalogPin.P1, 1500)
|
||||
@ -8,12 +9,12 @@ pins.servoSetPulse(AnalogPin.P1, 1500)
|
||||
|
||||
### Parameters
|
||||
|
||||
* `name` - [String](/reference/types/string); the pin name ("P0", "P1", or "P2")
|
||||
* `micros` - a [Number](/reference/types/number) representing the micro-seconds of the pulse width.
|
||||
* `pin`: a [string](/reference/types/string) that specifies the pin to configure (`P0` through `P4`, or `P10`)
|
||||
* `μs`: a [number](/reference/types/number) that specifies the analog period in microseconds.
|
||||
|
||||
### Example
|
||||
|
||||
The following code sets the servo pulse to ``1000`` micro seconds.
|
||||
The following code sets the servo pulse to `1000` microseconds.
|
||||
|
||||
```blocks
|
||||
pins.servoSetPulse(AnalogPin.P0, 1000)
|
||||
@ -21,5 +22,8 @@ pins.servoSetPulse(AnalogPin.P0, 1000)
|
||||
|
||||
### See also
|
||||
|
||||
[BBC micro:bit pins](/device/pins), [on pin pressed](/reference/input/on-pin-pressed), [analog read pin](/reference/pins/analog-read-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin)
|
||||
|
||||
[BBC micro:bit pins](/device/pins),
|
||||
[on pin pressed](/reference/input/on-pin-pressed),
|
||||
[analog read pin](/reference/pins/analog-read-pin),
|
||||
[digital read pin](/reference/pins/digital-read-pin),
|
||||
[digital write pin](/reference/pins/digital-write-pin)
|
||||
|
BIN
docs/static/bluetooth/gatt_hierarchy.png
vendored
Executable file
After Width: | Height: | Size: 19 KiB |
BIN
docs/static/bluetooth/services_and_GATT.png
vendored
Executable file
After Width: | Height: | Size: 22 KiB |
BIN
docs/static/mb/js/basicFuns.png
vendored
Normal file
After Width: | Height: | Size: 47 KiB |
BIN
docs/static/mb/js/basicIntell.png
vendored
Normal file
After Width: | Height: | Size: 128 KiB |
BIN
docs/static/mb/projects/a1-display.png
vendored
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 26 KiB |
BIN
docs/static/mb/projects/a2-buttons.png
vendored
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 15 KiB |
BIN
docs/static/mb/projects/a3-pins.png
vendored
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 32 KiB |
BIN
docs/static/mb/projects/a4-motion.png
vendored
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 18 KiB |
BIN
docs/static/mb/projects/a5-compass.png
vendored
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 18 KiB |
BIN
docs/static/mb/projects/a6-music.png
vendored
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 16 KiB |
BIN
docs/static/mb/projects/a7-conductive.png
vendored
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 16 KiB |
BIN
docs/static/mb/projects/a8-network.png
vendored
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 16 KiB |
BIN
docs/static/mb/projects/a9-radio.png
vendored
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 30 KiB |
32
docs/streaming.md
Normal file
@ -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.
|
@ -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!
|
21
includes/docs-meta.html
Normal file
@ -0,0 +1,21 @@
|
||||
<meta name="twitter:card" content="summary" />
|
||||
<meta name="twitter:site" content="@codethemicrobit" />
|
||||
<meta name="twitter:title" content="@name@" />
|
||||
<meta name="twitter:description" content="@description@" />
|
||||
<meta name="twitter:image" content="@cardLogo@" />
|
||||
|
||||
<meta property="og:title" content="@name@" />
|
||||
<meta property="og:site_name" content="code the micro:bit" />
|
||||
<meta property="og:description" content="@description@" />
|
||||
<meta property="og:image" content="@cardLogo@" />
|
||||
<!--
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="fb:app_id" content="" />
|
||||
-->
|
||||
|
||||
<link rel="apple-touch-icon" href="@appLogo@">
|
||||
<link rel="icon" type="image/png" href="@appLogo@">
|
||||
<link rel="mask-icon" href="https://az851932.vo.msecnd.net/pub/zwxazere/safari-pinned-tab.svg" color="#000000">
|
||||
<link rel="shortcut icon" href="@appLogo@">
|
||||
<meta name="theme-color" content="@accentColor@">
|
||||
|
16
includes/head.html
Normal file
@ -0,0 +1,16 @@
|
||||
<meta name="twitter:card" content="summary" />
|
||||
<meta name="twitter:site" content="@codethemicrobit" />
|
||||
<meta name="twitter:title" content="code the micro:bit" />
|
||||
<meta name="twitter:description" content="Blocks+JavaScript for programming your micro:bit" />
|
||||
<meta name="twitter:image" content="https://az851932.vo.msecnd.net/pub/drbwxcth" />
|
||||
|
||||
<meta property="og:title" content="micro:bit editor" />
|
||||
<meta property="og:description" content="Blocks+JavaScript for programming your micro:bit" />
|
||||
<meta property="og:site_name" content="code the micro:bit" />
|
||||
<meta property="og:image" content="https://az851932.vo.msecnd.net/pub/drbwxcth" />
|
||||
<!--
|
||||
Canonical URL needs to wait until main release is updated.
|
||||
<meta property="og:url" content="https://codethemicrobit.com" />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="fb:app_id" content="" />
|
||||
-->
|
13
includes/tracking.html
Normal file
@ -0,0 +1,13 @@
|
||||
<script type="text/javascript">
|
||||
var appInsights=window.appInsights||function(config){
|
||||
function r(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},u=document,e=window,o="script",s=u.createElement(o),i,f;for(s.src=config.url||"//az416426.vo.msecnd.net/scripts/a/ai.0.js",u.getElementsByTagName(o)[0].parentNode.appendChild(s),t.cookie=u.cookie,t.queue=[],i=["Event","Exception","Metric","PageView","Trace"];i.length;)r("track"+i.pop());return r("setAuthenticatedUserContext"),r("clearAuthenticatedUserContext"),config.disableExceptionTracking||(i="onerror",r("_"+i),f=e[i],e[i]=function(config,r,u,e,o){var s=f&&f(config,r,u,e,o);return s!==!0&&t["_"+i](config,r,u,e,o),s}),t
|
||||
}({
|
||||
instrumentationKey:"e9ae05ca-350b-427a-9775-3ba3f6efabce"
|
||||
});window.appInsights=appInsights;
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
|
||||
for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d])};b.__SV=1.2;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f)}})(document,window.mixpanel||[]);
|
||||
|
||||
mixpanel.init("762fef19c053a0ea4cec43d2fecae76e");
|
||||
</script>
|
@ -724,11 +724,11 @@ function switchB(e: En) {
|
||||
return r;
|
||||
}
|
||||
|
||||
function bufferIs(b:Buffer, a:number[]) {
|
||||
function bufferIs(b: Buffer, a: number[]) {
|
||||
assert(b.length == a.length, "bis-len")
|
||||
for (let i = 0; i < a.length; ++i) {
|
||||
if (a[i] != b[i]) {
|
||||
assert(false, `bufferIs: buf[${i}]:${b[i]} != ${a[i]}`)
|
||||
assert(false, `bufferIs: buf[${ i }]:${ b[i] } != ${ a[i] }`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -742,33 +742,33 @@ function testBuffer() {
|
||||
assert(b[100000] == 0, "bufM");
|
||||
|
||||
b[0] = 42;
|
||||
bufferIs(b, [42, 0, 0]);
|
||||
bufferIs(b,[42, 0, 0]);
|
||||
b[2] = 41;
|
||||
bufferIs(b, [42, 0, 41]);
|
||||
bufferIs(b,[42, 0, 41]);
|
||||
|
||||
b.rotate(1)
|
||||
bufferIs(b, [0, 41, 42]);
|
||||
bufferIs(b,[0, 41, 42]);
|
||||
b.rotate(-2)
|
||||
bufferIs(b, [41, 42, 0]);
|
||||
bufferIs(b,[41, 42, 0]);
|
||||
b.shift(1)
|
||||
bufferIs(b, [42, 0, 0]);
|
||||
bufferIs(b,[42, 0, 0]);
|
||||
b.rotate(9)
|
||||
bufferIs(b, [42, 0, 0]);
|
||||
bufferIs(b,[42, 0, 0]);
|
||||
b.rotate(-9)
|
||||
bufferIs(b, [42, 0, 0]);
|
||||
bufferIs(b,[42, 0, 0]);
|
||||
|
||||
b.fill(4);
|
||||
bufferIs(b, [4, 4, 4]);
|
||||
bufferIs(b,[4, 4, 4]);
|
||||
|
||||
b.fill(12, 1, 1);
|
||||
bufferIs(b, [4, 12, 4]);
|
||||
bufferIs(b,[4, 12, 4]);
|
||||
|
||||
b.fill(13, 1, -1);
|
||||
bufferIs(b, [4, 13, 13]);
|
||||
bufferIs(b,[4, 13, 13]);
|
||||
|
||||
b.fill(100, -1, -1);
|
||||
bufferIs(b, [4, 13, 13]);
|
||||
bufferIs(b,[4, 13, 13]);
|
||||
|
||||
b.shift(-1)
|
||||
bufferIs(b, [0, 4, 13]);
|
||||
bufferIs(b,[0, 4, 13]);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
16
libs/microbit-bluetooth/enums.d.ts
vendored
@ -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 {
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
31
libs/microbit-bluetooth/shims.d.ts
vendored
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
4
libs/microbit-devices/shims.d.ts
vendored
@ -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 {
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "ksbit.h"
|
||||
|
||||
// keep in sync with github/pxt/pxtsim/libgeneric.ts
|
||||
enum class NumberFormat {
|
||||
Int8LE = 1,
|
||||
UInt8LE,
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-microbit",
|
||||
"version": "0.2.174",
|
||||
"version": "0.2.183",
|
||||
"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.193"
|
||||
}
|
||||
}
|
||||
|
@ -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,16 @@
|
||||
},
|
||||
"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",
|
||||
"cardLogo": "https://az851932.vo.msecnd.net/pub/drbwxcth",
|
||||
"appLogo": "https://az851932.vo.msecnd.net/pub/tbhemtig",
|
||||
"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,8 +114,12 @@
|
||||
{
|
||||
"name": "JavaScript",
|
||||
"path": "/javascript"
|
||||
},
|
||||
{
|
||||
"name": "Streaming Data",
|
||||
"path": "/streaming"
|
||||
}
|
||||
],
|
||||
"sideDoc": "getting-started"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -514,13 +514,17 @@ namespace pxsim.radio {
|
||||
}
|
||||
|
||||
namespace pxsim.pins {
|
||||
export function onPulse(name: number, pulse: number, body: RefAction) {
|
||||
export function onPulsed(name: number, pulse: number, body: RefAction) {
|
||||
}
|
||||
|
||||
export function pulseDuration(): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function createBuffer(sz: number) {
|
||||
return pxsim.BufferMethods.createBuffer(sz)
|
||||
}
|
||||
|
||||
export function digitalReadPin(pinId: number): number {
|
||||
let pin = getPin(pinId);
|
||||
if (!pin) return;
|
||||
@ -576,6 +580,15 @@ namespace pxsim.pins {
|
||||
// TODO
|
||||
}
|
||||
|
||||
export function i2cReadBuffer(address: number, size: number, repeat?: boolean): RefBuffer {
|
||||
// fake reading zeros
|
||||
return createBuffer(size)
|
||||
}
|
||||
|
||||
export function i2cWriteBuffer(address: number, buf: RefBuffer, repeat?: boolean): void {
|
||||
// fake - noop
|
||||
}
|
||||
|
||||
export function analogSetPitchPin(pinId: number) {
|
||||
let pin = getPin(pinId);
|
||||
if (!pin) return;
|
||||
|
@ -142,7 +142,6 @@
|
||||
"fbpnng",
|
||||
"fbyrog",
|
||||
"fcfoox",
|
||||
"fcgdzt",
|
||||
"fcicvk",
|
||||
"fcjlto",
|
||||
"fcvwvj",
|
||||
|