Compare commits
490 Commits
Author | SHA1 | Date | |
---|---|---|---|
8e581eaa41 | |||
4252829a9e | |||
d4475645f4 | |||
44beec4661 | |||
bd1f5a2b75 | |||
2cd3bca8db | |||
7d751fa322 | |||
3ee7c7f0b2 | |||
4ebeee7cf2 | |||
ea3cf55670 | |||
7c1b761964 | |||
b0fddd7e72 | |||
5a1321c711 | |||
e448512a3a | |||
f67e79ff3e | |||
ae6108e4fe | |||
0fac3cac8f | |||
a67d9ef1ab | |||
ca61374286 | |||
37330188ef | |||
4922a4a833 | |||
9db5db5067 | |||
75331e4297 | |||
cdc0d12a98 | |||
e08148cac6 | |||
e947f4859b | |||
92508d2daf | |||
5098eaac5a | |||
3a0d4df65c | |||
c26a81dee9 | |||
0054dede9a | |||
7e9c646684 | |||
b2282b1a81 | |||
e4c0e582d3 | |||
0e18b13ea1 | |||
ab6268ea7a | |||
999a40bb0d | |||
0d4af4ea12 | |||
5209222438 | |||
f21ff4ad20 | |||
2d5a96d215 | |||
30fe647f51 | |||
2361d1910a | |||
7921caaaff | |||
8bf34ae19c | |||
0dc03c81b7 | |||
1a398e0db9 | |||
f614cb9b2b | |||
794909f09f | |||
24107d1968 | |||
dfca86999f | |||
a487c3d3ac | |||
e7ea0ba581 | |||
212da01f5b | |||
4e72713797 | |||
5d27ddb4a5 | |||
fea143f1d2 | |||
13677c47a9 | |||
ab73d77322 | |||
b8aa63411c | |||
bdc5122ce4 | |||
9709d43dad | |||
56904acb99 | |||
63d3909cad | |||
23e835b108 | |||
be1ea9a742 | |||
8d33b4ded8 | |||
c58f847b33 | |||
19eff8e642 | |||
d53c8e9bef | |||
aea8299006 | |||
90f63c597f | |||
c4db344a85 | |||
0558e8945d | |||
e90875d57d | |||
f4c1a65e7e | |||
8dc88c44f2 | |||
acbe9106cc | |||
652b09d5c4 | |||
e35312de70 | |||
82764ffcc1 | |||
f1404cef61 | |||
566b750419 | |||
b119952e75 | |||
e4e6a5effd | |||
ec1117842d | |||
de4242bf71 | |||
59322fb06b | |||
19e609c245 | |||
a5cb663316 | |||
1dd0c1793e | |||
a4a74bdd6b | |||
45c82767d0 | |||
0c77927f35 | |||
672672e632 | |||
fe2ae855b0 | |||
6612080885 | |||
8641a81e05 | |||
656e183a1a | |||
1d56be507a | |||
6504007a65 | |||
fc0526e47c | |||
cb47a6a291 | |||
6f8060a8c7 | |||
4a8897c0a4 | |||
839a26e5a7 | |||
b46802804c | |||
34d1fac337 | |||
39c41f26b1 | |||
083a192a5b | |||
76cbad0cec | |||
ed84d49667 | |||
b9d867cf4e | |||
226dfa281a | |||
cc4f6c66da | |||
49ecac6332 | |||
638e1d3c53 | |||
712bc0ada4 | |||
8437f0cf3c | |||
9641c4b5ec | |||
e29216c709 | |||
06e255eeb9 | |||
91c70e9809 | |||
8014712994 | |||
a7d5804cea | |||
2e5984a65b | |||
c13bef01a4 | |||
16c08e4c9b | |||
444c37edcb | |||
51781be90b | |||
741eb4e4b4 | |||
350f595a52 | |||
06c392f16f | |||
4bf659c9ac | |||
db4711fd26 | |||
8275fefd08 | |||
8c474c899c | |||
48bb0e238a | |||
1d47b4de0d | |||
595e4a23e6 | |||
2d3ca71ffb | |||
3ba9d2867b | |||
ff7b229a3a | |||
f944af8122 | |||
35225468e4 | |||
72d5e83e5b | |||
436b56a2fa | |||
7a41730f82 | |||
372ddfa641 | |||
30078923a3 | |||
5ab9222200 | |||
8ae5a48f1e | |||
f9ed37d07b | |||
edfbc4da18 | |||
3a1c6a6ce3 | |||
9a4a2264fa | |||
e9558ce158 | |||
50677fadc4 | |||
649e8f7c0f | |||
0cb9c28f8d | |||
004d9b4315 | |||
7a5b3aba01 | |||
dc30263642 | |||
619658a057 | |||
472846bf3c | |||
ac4fbc850b | |||
c7054b7ee0 | |||
559a43e17b | |||
7671bc46ad | |||
b3c5f2926d | |||
28830aa905 | |||
7fbbb5e65a | |||
51ebc29887 | |||
f5d1722eae | |||
5f876d5ea9 | |||
31de8892fa | |||
0d0a68122d | |||
4ad660568e | |||
58e82a571d | |||
e629b866d5 | |||
f0ac2b7a05 | |||
e3c8db28e4 | |||
2c0e19a120 | |||
595eb788b2 | |||
2e15d22e9e | |||
57082654a9 | |||
8cbf7d38e3 | |||
a99a7325bf | |||
fa3ed9dd21 | |||
45fd40a553 | |||
5a18bea9eb | |||
d310312841 | |||
a4b93f7199 | |||
538a4b7bbf | |||
0078e7bc12 | |||
d2726133a9 | |||
00f4c9cbb3 | |||
e15da5dee1 | |||
85dda4ea84 | |||
a3ffe4e1cf | |||
90c4d4f73b | |||
6484d559d6 | |||
357436f14d | |||
85fe96b3fd | |||
cdac932c42 | |||
dcfc2a110d | |||
e9561f54c3 | |||
86f6b58d38 | |||
eee52a5c04 | |||
1a0b0eac71 | |||
5a98ae0bb8 | |||
a9eea9a618 | |||
3086c521e3 | |||
6788f79650 | |||
5900239045 | |||
248267ec2c | |||
9429075555 | |||
1fa871f2e7 | |||
04dab7df2c | |||
b6474467bc | |||
79ead74af4 | |||
0f8ff95b72 | |||
05028c4527 | |||
4054da3483 | |||
7052d27d6d | |||
365af8d672 | |||
5086ca308c | |||
c1af770afc | |||
e175e70d01 | |||
cbc228dca3 | |||
462127c661 | |||
487da05eca | |||
c938618d29 | |||
91321dab83 | |||
0cb3d6e44e | |||
7a98b06424 | |||
69c80d3aff | |||
1d82f08668 | |||
4681a68ffd | |||
0a69b773de | |||
3f66a1c16d | |||
d78781ad5a | |||
46281c3cd0 | |||
a58f67064f | |||
efe784441f | |||
05174f094a | |||
42773a1a0a | |||
32f96d09d4 | |||
05d88cb4ba | |||
7fe8dad1f6 | |||
858766ea3e | |||
81fe9afbb7 | |||
65c615f256 | |||
9c5c699fe7 | |||
dcede1703a | |||
5d33ab019d | |||
f7ec452ea0 | |||
20260e8933 | |||
d7704934e8 | |||
f1eafb0a6e | |||
27d6a8281a | |||
c5128aa497 | |||
a59394646c | |||
6851169dbe | |||
36b3486194 | |||
5d8ccd1d6d | |||
c713fe9bf4 | |||
f682e5e694 | |||
d2d776fd01 | |||
641a5e9673 | |||
93d90a2bde | |||
a54504f31c | |||
03111368e0 | |||
a973b2aec6 | |||
a7adf0e6c6 | |||
c10761128e | |||
9965f169b2 | |||
8bf755c15c | |||
d0b2a7db62 | |||
780192da3b | |||
07c1f08d18 | |||
25ac847266 | |||
63c8342b86 | |||
ea2bd7ba10 | |||
cec2d1e8af | |||
1b289b688b | |||
0cf91580cb | |||
392ebc8d07 | |||
9068aab12b | |||
85327a4e69 | |||
021260b3a4 | |||
4def93d7c5 | |||
9aca0c19fc | |||
3fcbdbdd82 | |||
4b7b6eebca | |||
2da0cf1178 | |||
141cb24e3d | |||
35483487af | |||
ec3a805326 | |||
780d8bcf8d | |||
f9a12cac64 | |||
03c2df3277 | |||
a7e98ccb3d | |||
1014d2f361 | |||
89f20a64d5 | |||
fae36a74af | |||
7e57c59b6f | |||
3141e12f4c | |||
4ebe9f595a | |||
50f0e85884 | |||
e28b5d48d4 | |||
562e96e09e | |||
6c5088f811 | |||
d5ccb7ad02 | |||
ade5176d21 | |||
d2f6d51c19 | |||
92b60a251d | |||
de9f2d7e67 | |||
4de5e3bd11 | |||
86a33e8f65 | |||
89010b6a8a | |||
48d4668a7a | |||
a2755dc4d2 | |||
52e67c6bfc | |||
5a6f23a7d0 | |||
d1b36f2022 | |||
284579181b | |||
20fcb05538 | |||
e1a2074ef5 | |||
fa3e33dab9 | |||
300a98b858 | |||
5986671bcb | |||
efd5c46143 | |||
62c1a1da35 | |||
ebbc7c983d | |||
173fc4bf7b | |||
47f1eadd27 | |||
8c06277a92 | |||
395f482f11 | |||
bbd21a84d6 | |||
fcf680e9bd | |||
8ac848c812 | |||
dd591af224 | |||
e5a7a81198 | |||
7a5228a5d0 | |||
fe5c8e520a | |||
96d354a8a8 | |||
02480b1c54 | |||
4fd321cccf | |||
4641c9456f | |||
498b5ec095 | |||
912be2ddfd | |||
6d7f8c5841 | |||
a782f4731a | |||
6e067bffd5 | |||
4a4007ba41 | |||
c9db08a2c6 | |||
5ec303b95c | |||
3d0523a298 | |||
3469ad6f8d | |||
d791738d84 | |||
355c341d36 | |||
1adb4a2bac | |||
03c0339e9a | |||
1649811015 | |||
14f16f9b2c | |||
66d3c6c7e8 | |||
7f27432222 | |||
870b26a85a | |||
aa6cb58dca | |||
6398a42dad | |||
cfc3eae77c | |||
438b745d32 | |||
21473f5b9b | |||
c85b6f9507 | |||
019b00209e | |||
6c11dbcdf4 | |||
91197c5cec | |||
9e5d9787c7 | |||
1c11a4823b | |||
d457c3e8d0 | |||
2ae21efb7b | |||
30211aa006 | |||
485a42758c | |||
0da5a5a349 | |||
efca68672a | |||
41ce2f66fa | |||
9393fc166e | |||
cfb4382941 | |||
aaca24ff5b | |||
0ce9be1a2b | |||
a88eb7fe02 | |||
06e4f7fb5c | |||
1b36485208 | |||
3b54cefa95 | |||
52857c9541 | |||
d10c2a20bd | |||
e2482cdf91 | |||
c045d87e4c | |||
34e23934b0 | |||
354196e01e | |||
bb2e8d0aef | |||
90f4e895d4 | |||
58c554caa6 | |||
6c688a7e59 | |||
71244065bb | |||
bbb1bc3dd7 | |||
806d0e2cff | |||
e0c4af1cae | |||
475821564e | |||
9d65dd605b | |||
67eec44411 | |||
280b555f86 | |||
2fcd32de0d | |||
78694e86a2 | |||
aeaa3d7bc1 | |||
af8ce3fccf | |||
47ef096b0f | |||
86c5c27b12 | |||
520c9217a5 | |||
4a34f2b932 | |||
034897b0a6 | |||
b504abc6da | |||
6dbfb9e96e | |||
d1021a30ca | |||
8d37be7cbe | |||
97066e1ba4 | |||
097564748c | |||
d873cbb6c3 | |||
adef3a6487 | |||
be0984cc4a | |||
f0947cddaa | |||
c5c5362b5d | |||
bcbbb1366a | |||
19fb5ecf01 | |||
0401aa60d2 | |||
e0c016fbf4 | |||
f046f0e50c | |||
90f48ac77a | |||
23f83df6df | |||
98e4f80399 | |||
b1fcc51bc8 | |||
63e24ce90a | |||
63d0b86508 | |||
672f3b94ca | |||
f0b91b07c1 | |||
2923d045b1 | |||
3cf36b4549 | |||
a42aa553e6 | |||
b12598e421 | |||
9a85075456 | |||
ce7b630870 | |||
9ac308da92 | |||
6315ca90e5 | |||
ecfe0a7f16 | |||
f701bca23f | |||
7313c76e8b | |||
77003b30f2 | |||
274bb9e042 | |||
e316f068e2 | |||
c75e77593a | |||
ecbf8409ea | |||
411fe52813 | |||
0d04376413 | |||
5deffe832c | |||
528f696b8c | |||
dfb5f7dd11 | |||
a4fb934a18 | |||
59b11ec2a9 | |||
d961e14e5c | |||
83c8c07b94 | |||
152f84cd79 | |||
ef58b54fdb | |||
50e2f3fa94 | |||
14f4e6092a | |||
f7a005c656 | |||
7e19fbb3ca | |||
e706809037 | |||
5d6bc2f5df | |||
22433317b9 | |||
fabf09477c | |||
f9e0fe1b8d | |||
c49fb27d4c | |||
24b20543c5 | |||
be97665ea2 | |||
657cdeb53e | |||
08575d352b | |||
c9ba7af3f3 | |||
917072a336 | |||
fd5357b273 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -15,7 +15,7 @@ clients/win10/app/bld
|
||||
clients/win10/*.opendb
|
||||
clients/**/bin/**
|
||||
clients/**/obj/**
|
||||
clients/electron/projects
|
||||
electron-out
|
||||
hexcache
|
||||
|
||||
*.user
|
||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -1,6 +1,6 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"file.autoSave": "afterDelay",
|
||||
"files.autoSave": "afterDelay",
|
||||
"files.watcherExclude": {
|
||||
"**/.git/objects/**": true,
|
||||
"**/built/**": true,
|
||||
|
26
CONTRIBUTING.md
Normal file
26
CONTRIBUTING.md
Normal file
@ -0,0 +1,26 @@
|
||||
# Contributing Code
|
||||
|
||||
PXT accepts bug fix pull requests. For a bug fix PR to be accepted, it must first have a tracking issue that has been marked approved. Your PR should link to the bug you are fixing. If you've submitted a PR for a bug, please post a comment in the bug to avoid duplication of effort.
|
||||
|
||||
PXT also accepts new feature pull requests. For a feature-level PR to be accepted, it first needs to have design discussion. Design discussion can take one of two forms a) a feature request in the issue tracker that has been marked as approved or b) the PR must be accompanied by a full design spec and this spec is later approved in the open design discussion. Features are evaluated against their complexity, impact on other features, roadmap alignment, and maintainability.
|
||||
|
||||
These two blogs posts on contributing code to open source projects are a good reference: [Open Source Contribution Etiquette](http://tirania.org/blog/archive/2010/Dec-31.html) by Miguel de Icaza and [Don't "Push" Your Pull Requests](https://www.igvita.com/2011/12/19/dont-push-your-pull-requests/) by Ilya Grigorik.
|
||||
|
||||
## Security
|
||||
|
||||
If you believe you have found a security issue in PXT, please share it with us privately following the guidance at the Microsoft [Security TechCenter](https://technet.microsoft.com/en-us/security/ff852094). Reporting it via this channel helps minimize risk to projects built with PXT.
|
||||
|
||||
## Legal
|
||||
|
||||
You will need to complete a Contributor License Agreement (CLA) before your pull request can be accepted. This agreement testifies that you are granting us permission to use the source code you are submitting, and that this work is being submitted under appropriate license that we can use it.
|
||||
|
||||
You can complete the CLA by going through the steps at https://cla.microsoft.com. Once we have received the signed CLA, we'll review the request. You will only need to do this once.
|
||||
|
||||
## Housekeeping
|
||||
|
||||
Your pull request should:
|
||||
* Include a description of what your change intends to do
|
||||
* Be a child commit of a reasonably recent commit in the master branch
|
||||
* Pass all unit tests
|
||||
* Have a clear commit message
|
||||
* Include adequate tests
|
25
LICENSE.txt
Normal file
25
LICENSE.txt
Normal file
@ -0,0 +1,25 @@
|
||||
PXT - Programming Experience Toolkit
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Microsoft Corporation
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -7,6 +7,10 @@ PXT ([Microsoft Programming Experience Toolkit](https://github.com/Microsoft/pxt
|
||||
|
||||
[](https://travis-ci.org/Microsoft/pxt-microbit)
|
||||
|
||||
## Issue tracking
|
||||
|
||||
All issue tracking for this repo happens at https://github.com/Microsoft/pxt, see you there!
|
||||
|
||||
## Local server
|
||||
|
||||
The local server allows to run the editor and the documentation from your computer.
|
||||
|
43
THIRD-PARTY-NOTICES.txt
Normal file
43
THIRD-PARTY-NOTICES.txt
Normal file
@ -0,0 +1,43 @@
|
||||
/*!----------------- PXT ThirdPartyNotices -------------------------------------------------------
|
||||
|
||||
PXT uses third party material from the projects listed below.
|
||||
The original copyright notice and the license under which Microsoft
|
||||
received such third party material are set forth below. Microsoft
|
||||
reserves all other rights not expressly granted, whether by
|
||||
implication, estoppel or otherwise.
|
||||
|
||||
In the event that we accidentally failed to list a required notice, please
|
||||
bring it to our attention. Post an issue or email us:
|
||||
|
||||
abchatra@microsoft.com
|
||||
|
||||
---------------------------------------------
|
||||
Third Party Code Components
|
||||
---------------------------------------------
|
||||
|
||||
Some code derived (as noted) from
|
||||
|
||||
https://github.com/bbcmicrobit/micropython
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2016 The MicroPython-on-micro:bit Developers, as listed
|
||||
in the accompanying AUTHORS file
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
@ -1,5 +1,5 @@
|
||||
# microbit-chrome
|
||||
Prototype chrome addon that exposes the micro:bit's serial output to webpages.
|
||||
Prototype chrome addon that exposes the @boardname@'s serial output to webpages.
|
||||
* watch the [demo video](https://vimeo.com/146207766)
|
||||
|
||||
# Installation
|
||||
|
2
clients/electron/.gitignore
vendored
2
clients/electron/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
node_modules
|
||||
projects
|
@ -1,5 +0,0 @@
|
||||
# PXT micro:bit Electron app
|
||||
|
||||
A very basic wrapper around the web app. To install, copy the contents of this
|
||||
directory to somewhere outside the main `pxt-microbit` repository. Then run `npm
|
||||
install && npm start`.
|
@ -1,15 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>code the micro:bit</title>
|
||||
</head>
|
||||
<body>
|
||||
<webview id="webview" style="position:absolute; left:0; top:0; right:0; bottom:0"/>
|
||||
<script>
|
||||
const webview = document.getElementById("webview")
|
||||
const url = `http://localhost:3232/${window.location.hash}`
|
||||
webview.src = url
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,39 +0,0 @@
|
||||
const {app, BrowserWindow, Menu} = require('electron')
|
||||
const pxt = require('pxt-core')
|
||||
const path = require('path')
|
||||
|
||||
let win
|
||||
|
||||
const cliPath = path.join(process.cwd(), "node_modules/pxt-microbit")
|
||||
|
||||
function startServerAndCreateWindow() {
|
||||
pxt.mainCli(cliPath, ["serve", "-no-browser"])
|
||||
createWindow()
|
||||
}
|
||||
|
||||
function createWindow () {
|
||||
win = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
title: "code the micro:bit"
|
||||
})
|
||||
Menu.setApplicationMenu(null)
|
||||
win.loadURL(`file://${__dirname}/index.html#local_token=${pxt.globalConfig.localToken}`)
|
||||
win.on('closed', () => {
|
||||
win = null
|
||||
})
|
||||
}
|
||||
|
||||
app.on('ready', startServerAndCreateWindow)
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
||||
app.on('activate', () => {
|
||||
if (win === null) {
|
||||
createWindow()
|
||||
}
|
||||
})
|
@ -1,14 +0,0 @@
|
||||
{
|
||||
"name" : "code-the-microbit",
|
||||
"version" : "1.0.0",
|
||||
"description": "Blocks / Javascript editor",
|
||||
"author": "Microsoft",
|
||||
"main" : "main.js",
|
||||
"scripts": {
|
||||
"start": "node_modules/.bin/electron ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"electron": "*",
|
||||
"pxt-microbit": "*"
|
||||
}
|
||||
}
|
59
cmds/cmds.ts
59
cmds/cmds.ts
@ -1,59 +0,0 @@
|
||||
/// <reference path="../node_modules/pxt-core/built/pxt.d.ts"/>
|
||||
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import * as child_process from "child_process";
|
||||
|
||||
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.pxtc.CompileResult) {
|
||||
return getBitDrivesAsync()
|
||||
.then(drives => {
|
||||
if (drives.length == 0) {
|
||||
console.log("cannot find any drives to deploy to");
|
||||
return Promise.resolve(0);
|
||||
}
|
||||
|
||||
console.log(`copy ${ts.pxtc.BINARY_HEX} to ` + drives.join(", "));
|
||||
|
||||
let writeHexFile = (filename: string) => {
|
||||
return writeFileAsync(filename + ts.pxtc.BINARY_HEX, res.outfiles[ts.pxtc.BINARY_HEX])
|
||||
.then(() => console.log("wrote hex file to " + filename));
|
||||
};
|
||||
|
||||
return Promise.map(drives, d => writeHexFile(d))
|
||||
.then(() => drives.length);
|
||||
});
|
||||
}
|
||||
|
||||
function getBitDrivesAsync(): Promise<string[]> {
|
||||
if (process.platform == "win32") {
|
||||
const rx = new RegExp("^([A-Z]:).* " + pxt.appTarget.compile.deployDrives)
|
||||
return execAsync("wmic PATH Win32_LogicalDisk get DeviceID, VolumeName, FileSystem")
|
||||
.then(buf => {
|
||||
let res: string[] = []
|
||||
buf.toString("utf8").split(/\n/).forEach(ln => {
|
||||
let m = rx.exec(ln)
|
||||
if (m) {
|
||||
res.push(m[1] + "/")
|
||||
}
|
||||
})
|
||||
return res
|
||||
})
|
||||
}
|
||||
else if (process.platform == "darwin") {
|
||||
const rx = new RegExp(pxt.appTarget.compile.deployDrives)
|
||||
return readDirAsync("/Volumes")
|
||||
.then(lst => lst.filter(s => rx.test(s)).map(s => "/Volumes/" + s + "/"))
|
||||
} else if (process.platform == "linux") {
|
||||
const rx = new RegExp(pxt.appTarget.compile.deployDrives)
|
||||
const user = process.env["USER"]
|
||||
return readDirAsync(`/media/${user}`)
|
||||
.then(lst => lst.filter(s => rx.test(s)).map(s => `/media/${user}/${s}/`))
|
||||
} else {
|
||||
return Promise.resolve([])
|
||||
}
|
||||
}
|
7
cmds/pxtrequire.ts
Normal file
7
cmds/pxtrequire.ts
Normal file
@ -0,0 +1,7 @@
|
||||
/// <reference path="../node_modules/pxt-core/typings/globals/node/index.d.ts"/>
|
||||
/// <reference path="../node_modules/pxt-core/built/pxtlib.d.ts" />
|
||||
|
||||
import * as path from "path";
|
||||
export let pxtCore = require("pxt-core");
|
||||
// require.resolve() gives path to [pxt dir]/built/pxt.js, so move up twice to get pxt root dir
|
||||
export let pxtCoreDir = path.resolve(require.resolve("pxt-core"), "..", "..");
|
@ -1,6 +1,10 @@
|
||||
# Blocks language
|
||||
|
||||
### @description Langugage constructs for the Block editor.
|
||||
### @description Language constructs for the Block editor.
|
||||
|
||||
Blocks snap into each other to define the program that your @boardname@ will run.
|
||||
Blocks can be event (buttons, shake, ...) or need to be snapped into an event to run.
|
||||
The [on-start](/blocks/on-start) event runs first.
|
||||
|
||||
```namespaces
|
||||
for (let i = 0;i<5;++i) {}
|
||||
@ -11,4 +15,4 @@ Math.random(5);
|
||||
|
||||
## See Also
|
||||
|
||||
[logic](/blocks/logic), [loops](/blocks/loops), [math](/blocks/math), [variables](/blocks/variables)
|
||||
[logic](/blocks/logic), [loops](/blocks/loops), [math](/blocks/math), [variables](/blocks/variables), [on-start](/blocks/on-start), [javascript blocks](/blocks/javascript-blocks)
|
65
docs/blocks/javascript-blocks.md
Normal file
65
docs/blocks/javascript-blocks.md
Normal file
@ -0,0 +1,65 @@
|
||||
# JavaScript Block
|
||||
|
||||
JavaScript is a very powerful language; so powerful that some concepts in
|
||||
JavaScript can't be shown using blocks. When PXT encounters a piece of code
|
||||
that can't be converted into blocks, it instead creates a grey JavaScript block
|
||||
to preserve it. These blocks get converted right back into the original
|
||||
JavaScript when you switch back to the text editor.
|
||||
|
||||
```blocks
|
||||
for (let index = 0; index <= 5; index++) {
|
||||
basic.showNumber(fibonacci(index))
|
||||
}
|
||||
|
||||
function fibonacci(n: number): number {
|
||||
if (n === 0 || n === 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return fibonacci(n - 1) + fibonacci(n - 2);
|
||||
}
|
||||
```
|
||||
|
||||
The code in JavaScript blocks cannot be edited, but the blocks
|
||||
themselves can be moved, copied, pasted, and deleted just like any
|
||||
other block.
|
||||
|
||||
|
||||
## How do I get my JavaScript code to convert without any grey blocks?
|
||||
|
||||
The easiest way to write code that will convert cleanly back to blocks
|
||||
is to write the code using blocks and convert it to JavaScript. Many blocks
|
||||
have a very specifc structure to their JavaScript that must be
|
||||
followed in order to have them convert properly. If you have a
|
||||
piece of your code that does not convert, try looking at the block
|
||||
you were expecting and the JavaScript it produces.
|
||||
|
||||
For example, a for-loop must have this structure to convert to a block:
|
||||
|
||||
```typescript
|
||||
for (let x = 0; x <= 5; x++) {
|
||||
}
|
||||
```
|
||||
|
||||
The following examples can't be represented by the blocks:
|
||||
|
||||
```typescript
|
||||
// Condition must be either < or <= with a variable on the left side
|
||||
for (let x = 0; x > -1; x++) {
|
||||
}
|
||||
|
||||
// The variable in the condition and incrementor must be the declared variable
|
||||
for (let x = 0; x <= 5; y++) {
|
||||
}
|
||||
|
||||
// The declared variable must be initialized to 0
|
||||
for (let x = 2; x <= 5; x++) {
|
||||
}
|
||||
|
||||
// All three parts of the for-loop must be present
|
||||
for (;;) {
|
||||
}
|
||||
```
|
||||
|
||||
Try to match the JavaScript of the desired block as closely as
|
||||
possible.
|
@ -86,12 +86,14 @@ if (led.point(1,1) && led.point(2,2)) {
|
||||
When you compare two Numbers, you get a Boolean value, such as the comparison `x < 5` in the code below:
|
||||
|
||||
```blocks
|
||||
let x = Math.random(5)
|
||||
if(x < 5) {
|
||||
basic.showString("low");
|
||||
} else {
|
||||
basic.showString("high");
|
||||
}
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.random(5)
|
||||
if(x < 5) {
|
||||
basic.showString("low");
|
||||
} else {
|
||||
basic.showString("high");
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
See the documentation on [Numbers](/reference/types/number) for more information on comparing two Numbers. You can also [compare strings](/reference/types/string-functions) using the `equals` function.
|
||||
|
@ -14,13 +14,15 @@ Click on the dark blue gear icon (see above) to add an *else* or *if* to the cur
|
||||
|
||||
### Example: adjusting screen brightness
|
||||
|
||||
```blocks
|
||||
if(input.lightLevel()<100){
|
||||
led.setBrightness(255);
|
||||
}
|
||||
```
|
||||
If the [light level](/reference/input/light-level) is `< 100`, this code sets the brightness to `255` when the button A is pressed:
|
||||
|
||||
If the [light level](/reference/input/light-level) is `< 100`, this code sets the brightness to `255`:
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
if(input.lightLevel()<100){
|
||||
led.setBrightness(255);
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
|
@ -4,14 +4,21 @@
|
||||
|
||||
Run part of the program the number of times you say.
|
||||
|
||||
```block
|
||||
for(let i = 0; i <= 4; ++i) {
|
||||
}
|
||||
```
|
||||
|
||||
### Example: Count to 4
|
||||
|
||||
This program will show the numbers 0, 1, 2, 3, and 4 one after another on the LED screen.
|
||||
|
||||
```blocks
|
||||
for(let i = 0; i < 5; ++i) {
|
||||
basic.showNumber(i)
|
||||
}
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
for(let i = 0; i < 5; ++i) {
|
||||
basic.showNumber(i)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### See also
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
Repeat code while a [Boolean](/blocks/logic/boolean) `condition` is true.
|
||||
|
||||
```blocks
|
||||
```block
|
||||
while(true) {
|
||||
}
|
||||
```
|
||||
@ -16,11 +16,13 @@ The condition is tested before any code runs. Which means that if the condition
|
||||
The following example uses a while loop to make a diagonal line on the LED screen (points `0, 0`, `1, 1`, `2, 2`, `3, 3`, `4, 4`).
|
||||
|
||||
```blocks
|
||||
let index = 4;
|
||||
while(index >= 0) {
|
||||
led.plot(index, index);
|
||||
index--;
|
||||
}
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let index = 4;
|
||||
while(index >= 0) {
|
||||
led.plot(index, index);
|
||||
index--;
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### See also
|
||||
|
28
docs/blocks/on-start.md
Normal file
28
docs/blocks/on-start.md
Normal file
@ -0,0 +1,28 @@
|
||||
# On Start
|
||||
|
||||
An event that runs when the program starts.
|
||||
|
||||
The ``on start`` is a special event that runs when the program starts, before any other event.
|
||||
Use this event to initialize your program.
|
||||
|
||||
## Example
|
||||
|
||||
In this example, ``on start`` sets a dimmer brightness on the screen and the button handler shows a string.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("Hello!")
|
||||
})
|
||||
led.setBrightness(50)
|
||||
```
|
||||
|
||||
## What about JavaScript?
|
||||
|
||||
``on-start`` only exists in the block editor. In JavaScript, all code executes sequentially from the first line.
|
||||
|
||||
## Hey, my events moved!
|
||||
|
||||
When we transform the blocks into JavaScript, we always place all the event registrations (buttons, shake, ...)
|
||||
before launching the ``on start`` code.
|
||||
|
||||
If a block from ``on start`` pauses, other registered events will have the opportunity to run as well.
|
116
docs/device/servo.md
Normal file
116
docs/device/servo.md
Normal file
@ -0,0 +1,116 @@
|
||||
# Equipping a microservo with Crocodile clips
|
||||
|
||||
## Materials
|
||||
* Cutting pliers or wire cutter
|
||||
* Tape (masking, duct tape, and/or packing tape)
|
||||
* 3 crocodile clips, yellow, red and black.
|
||||
* 1 micro servo 9g (SG90)
|
||||
|
||||
## Using a microservo with the @boardname@
|
||||
|
||||
The @boardname@ provides just enough current to operate the SG90 microservo.
|
||||
The servo requires 3 connections: GND, 3V and a logic pin.
|
||||
In this tutorial, we will equip the servo with crocodile clips to make it easier to use.
|
||||
However, you could also use a shield or female to crocodile clips to acheive the same effect.
|
||||
|
||||
If you are running a class or activity, you should consider preparing all servos before hand.
|
||||
|
||||
### ~ hint
|
||||
|
||||
Kitronik wrote an excellent in-depth guide about using servos with the @boardname@.
|
||||
Check it out at https://www.kitronik.co.uk/blog/using-bbc-microbit-control-servo/ .
|
||||
|
||||
### ~
|
||||
|
||||
## Step 1: cutout the connector
|
||||
|
||||
Using the cutting pliers, cut out the dark plastic connector.
|
||||
|
||||

|
||||
|
||||
## Step 2: strip out cables
|
||||
|
||||
Using the plier or a wire stripper, strip the plastic from the cables.
|
||||
|
||||

|
||||
|
||||
## Step 3: threading the servo cablers
|
||||
|
||||
Thread the servo cables.
|
||||
|
||||

|
||||
|
||||
## Step 4: crocobile clip claps
|
||||
|
||||
Cut a crocodile cable in two and strip out the casing.
|
||||
If possible try to use the same cable colors as the servo!
|
||||
|
||||

|
||||
|
||||
## Step 5: thread cables together
|
||||
|
||||
Place the cables next to each other
|
||||
|
||||

|
||||
|
||||
... and thread them together.
|
||||
|
||||

|
||||
|
||||
### ~ hint
|
||||
|
||||
It is very **important** to ensure that there is a good connection between the 2 cables.
|
||||
If the connection is weak, the microservo will not receive enough current and it will not work.
|
||||
**If you have access to a soldering iron, we strongly recommend to solder this connection.**
|
||||
|
||||
### ~
|
||||
|
||||
## Step 4: protect the connection
|
||||
|
||||
Protect the connection with electrical or duct tape.
|
||||
|
||||

|
||||
|
||||
## Step 5: repeat for all cables
|
||||
|
||||
Repeat the same process until all cables are connected.
|
||||
|
||||

|
||||
|
||||
## Step 6: testing!
|
||||
|
||||
It's time to test that your connection are all proper and that the servo will function **when the @boardname@ is powered by battery**.
|
||||
|
||||
* Connect the microservo to the @boardname@. Black cable on ``GND``, red cable on ``3V`` and remaining cable on ``P0``.
|
||||
|
||||

|
||||
|
||||
### ~ hint
|
||||
|
||||
When attaching the crocodile clips to the pins, don't hesitate to grab the side of the board with the jaws.
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
|
||||
* Download the following code to your @boardname@
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
pins.servoWritePin(AnalogPin.P0, pins.map(
|
||||
input.acceleration(Dimension.X),
|
||||
-512,
|
||||
512,
|
||||
0,
|
||||
180
|
||||
))
|
||||
})
|
||||
```
|
||||
|
||||
* When powered by USB, make sure that the servo moves when you tilt the board.
|
||||
* When powered by batteries **only**, make sure that the servo moves when you tilt the board.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If your servo seems to sutter and stay stuck at a particular position, it means that it is not receiving enough power.
|
||||
This is probably due to a weak connection or low battery level. Check each connection and check your batteries.
|
@ -6,6 +6,7 @@
|
||||
|
||||
* **[Getting Started](/getting-started)**
|
||||
* [Projects](/projects)
|
||||
* [Examples](/examples)
|
||||
* [Lessons](/lessons)
|
||||
|
||||
### @boardname@ reference
|
||||
|
41
docs/examples.md
Normal file
41
docs/examples.md
Normal file
@ -0,0 +1,41 @@
|
||||
# Examples
|
||||
|
||||
Here are some fun programs for your @boardname@!
|
||||
|
||||
## Fun stuff
|
||||
|
||||
```codecard
|
||||
[{
|
||||
"name": "Blinky",
|
||||
"description": "A blinking LED",
|
||||
"url":"/examples/blinky"
|
||||
},
|
||||
{
|
||||
"name": "Name Tag",
|
||||
"description": "Scroll your name on the screen",
|
||||
"url":"/examples/name-tag"
|
||||
},
|
||||
{
|
||||
"name": "Rando",
|
||||
"description": "Randomly blinking LEDs",
|
||||
"url":"/examples/rando"
|
||||
}]
|
||||
```
|
||||
|
||||
## Sensors
|
||||
|
||||
```codecard
|
||||
[{
|
||||
"name": "Plot Acceleration",
|
||||
"description": "chart acceleration on the LED screen",
|
||||
"url":"/examples/plot-acceleration"
|
||||
}, {
|
||||
"name": "Plot Light Level",
|
||||
"description": "chart light level on the LED screen",
|
||||
"url":"/examples/plot-light-level"
|
||||
}, {
|
||||
"name": "Plot Analog Pin",
|
||||
"description": "chart analog input on the LED screen",
|
||||
"url":"/examples/plot-analog-pin"
|
||||
}]
|
||||
```
|
20
docs/examples/blinky.md
Normal file
20
docs/examples/blinky.md
Normal file
@ -0,0 +1,20 @@
|
||||
# Blinky
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .`
|
||||
);
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . . . .`
|
||||
);
|
||||
})
|
||||
```
|
7
docs/examples/name-tag.md
Normal file
7
docs/examples/name-tag.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Name Tag
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showString("JAMES")
|
||||
})
|
||||
```
|
10
docs/examples/plot-acceleration.md
Normal file
10
docs/examples/plot-acceleration.md
Normal file
@ -0,0 +1,10 @@
|
||||
# Plot Acceleration
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plotBarGraph(
|
||||
input.acceleration(Dimension.X),
|
||||
1023
|
||||
)
|
||||
})
|
||||
```
|
10
docs/examples/plot-analog-pin.md
Normal file
10
docs/examples/plot-analog-pin.md
Normal file
@ -0,0 +1,10 @@
|
||||
# Plot Analog Pin
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plotBarGraph(
|
||||
pins.analogReadPin(AnalogPin.P0),
|
||||
1023
|
||||
)
|
||||
})
|
||||
```
|
10
docs/examples/plot-light-level.md
Normal file
10
docs/examples/plot-light-level.md
Normal file
@ -0,0 +1,10 @@
|
||||
# Plot Light level
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plotBarGraph(
|
||||
input.lightLevel(),
|
||||
255
|
||||
)
|
||||
})
|
||||
```
|
7
docs/examples/rando.md
Normal file
7
docs/examples/rando.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Rando
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.toggle(Math.random(5), Math.random(5))
|
||||
})
|
||||
```
|
@ -33,7 +33,7 @@ basic.forever(() => {
|
||||
|
||||
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.)
|
||||
`[basic.forever(() => {})]` block.)
|
||||
|
||||
Click **Download** to move your program to the @boardname@!
|
||||
Make sure to follow the instructions.
|
||||
|
@ -17,7 +17,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
|
||||
#### ~hint
|
||||
|
||||
The ``showString`` block can show letters, numbers, and punctuation
|
||||
The `[basic.showString("HI")]` block can show letters, numbers, and punctuation
|
||||
on the @boardname@ screen.
|
||||
|
||||
#### ~
|
||||
@ -33,7 +33,7 @@ input.onButtonPressed(Button.B, () => {
|
||||
#### ~hint
|
||||
|
||||
You can find the letter `B` by clicking the letter `A` on the
|
||||
``onButtonPressed`` block.
|
||||
`[input.onButtonPressed(Button.A, () => {})]` block.
|
||||
|
||||
#### ~
|
||||
|
||||
|
@ -23,8 +23,8 @@ input.onButtonPressed(Button.B, () => {
|
||||
```
|
||||
### ~hint
|
||||
|
||||
The ``pick random true or false`` block randomly tells the ``if``
|
||||
block `true` or `false`. If the ``pick`` block picked `true`, the
|
||||
The `[Math.randomBoolean()]` block randomly tells the ``if``
|
||||
block `true` or `false`. If value picked is `true`, the
|
||||
``if`` block shows the letter `H`. Otherwise, it shows the letter `T`.
|
||||
|
||||
That's it!
|
||||
|
@ -9,7 +9,7 @@ There are 25 bright LEDs on the @boardname@ screen. Let's use them to create som
|
||||
### 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.
|
||||
in the second `[basic.showLeds("")]` 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 @boardname@)!
|
||||
@ -36,7 +36,7 @@ Click **Download** to move your program to the @boardname@!
|
||||
|
||||
### Your turn!
|
||||
|
||||
Pile up more ``show leds`` blocks to create an animation! Create an
|
||||
Pile up more `[basic.showLeds("")]` blocks to create an animation! Create an
|
||||
animation with at least 5 pictures. What does this animation show?
|
||||
|
||||
```blocks
|
||||
@ -87,12 +87,6 @@ basic.forever(() => {
|
||||
```
|
||||
Click **Download** to move your program to the @boardname@!
|
||||
|
||||
#### ~hint
|
||||
|
||||
You can find the ``show leds`` block in the **Basic** part of the editor.
|
||||
|
||||
#### ~
|
||||
|
||||
### ~button /getting-started/buttons
|
||||
NEXT: BUTTONS
|
||||
### ~
|
@ -1,3 +1,3 @@
|
||||
{
|
||||
"appref": "v0.5.33"
|
||||
"appref": "v0.9.35"
|
||||
}
|
||||
|
@ -5,12 +5,11 @@ but this may feel a bit awkward to programmers more comfortable with an object-o
|
||||
and objects are built from these classes.
|
||||
|
||||
Starting with ECMAScript 2015, also known as ECMAScript 6, JavaScript programmers will be able to build their applications using
|
||||
this object-oriented class-based approach. TypeScript, allows you to use these techniques now, compiling them
|
||||
down to JavaScript that works across all major browsers and platforms, without having to wait for the next version of JavaScript.
|
||||
this object-oriented class-based approach. TypeScript, allows you to use these techniques.
|
||||
|
||||
Let's take a look at a simple class-based example:
|
||||
|
||||
```ts
|
||||
```typescript
|
||||
class Greeter {
|
||||
greeting: string;
|
||||
constructor(message: string) {
|
||||
@ -34,16 +33,12 @@ This calls into the constructor we defined earlier, creating a new object with t
|
||||
|
||||
# Inheritance
|
||||
|
||||
### ~hint
|
||||
### Inheritance is not supported yet for the @boardname@. Coming soon...
|
||||
### ~
|
||||
|
||||
In TypeScript, we can use common object-oriented patterns.
|
||||
Of course, one of the most fundamental patterns in class-based programming is being able to extend existing classes to create new ones using inheritance.
|
||||
|
||||
Let's take a look at an example:
|
||||
|
||||
```ts-ignore
|
||||
```typescript-ignore
|
||||
class Animal {
|
||||
name: string;
|
||||
constructor(theName: string) { this.name = theName; }
|
||||
@ -105,7 +100,7 @@ In TypeScript, each member is `public` by default.
|
||||
You may still mark a member `public` explicitly.
|
||||
We could have written the `Animal` class from the previous section in the following way:
|
||||
|
||||
```ts-ignore
|
||||
```typescript-ignore
|
||||
class Animal {
|
||||
public name: string;
|
||||
public constructor(theName: string) { this.name = theName; }
|
||||
@ -119,7 +114,7 @@ class Animal {
|
||||
|
||||
When a member is marked `private`, it cannot be accessed from outside of its containing class. For example:
|
||||
|
||||
```ts-ignore
|
||||
```typescript-ignore
|
||||
class Animal {
|
||||
private name: string;
|
||||
constructor(theName: string) { this.name = theName; }
|
||||
@ -138,7 +133,7 @@ The same applies to `protected` members.
|
||||
|
||||
Let's look at an example to better see how this plays out in practice:
|
||||
|
||||
```ts-ignore
|
||||
```typescript-ignore
|
||||
class Animal {
|
||||
private name: string;
|
||||
constructor(theName: string) { this.name = theName; }
|
||||
@ -174,7 +169,7 @@ Even though `Employee` also has a `private` member called `name`, it's not the o
|
||||
The `protected` modifier acts much like the `private` modifier with the exception that members
|
||||
declared `protected` can also be accessed by instances of deriving classes. For example,
|
||||
|
||||
```ts-ignore
|
||||
```typescript-ignore
|
||||
class Person {
|
||||
protected name: string;
|
||||
constructor(name: string) { this.name = name; }
|
||||
@ -204,7 +199,7 @@ we can still use it from within an instance method of `Employee` because `Employ
|
||||
A constructor may also be marked `protected`.
|
||||
This means that the class cannot be instantiated outside of its containing class, but can be extended. For example,
|
||||
|
||||
```ts-ignore
|
||||
```typescript-ignore
|
||||
class Person {
|
||||
protected name: string;
|
||||
protected constructor(theName: string) { this.name = theName; }
|
||||
@ -233,7 +228,7 @@ let john = new Person("John"); // Error: The 'Person' constructor is protected
|
||||
You can make properties readonly by using the `readonly` keyword.
|
||||
Readonly properties must be initialized at their declaration or in the constructor.
|
||||
|
||||
```ts-ignore
|
||||
```typescript-ignore
|
||||
class Octopus {
|
||||
readonly name: string;
|
||||
readonly numberOfLegs: number = 8;
|
||||
@ -252,7 +247,7 @@ This turns out to be a very common practice.
|
||||
*Parameter properties* let you create and initialize a member in one place.
|
||||
Here's a further revision of the previous `Octopus` class using a parameter property:
|
||||
|
||||
```ts-ignore
|
||||
```typescript-ignore
|
||||
class Octopus {
|
||||
readonly numberOfLegs: number = 8;
|
||||
constructor(readonly name: string) {
|
||||
|
@ -6,15 +6,14 @@ For the @boardname@, we support a "static" subset of TypeScript (itself a supers
|
||||
|
||||
## Supported language features
|
||||
|
||||
* variables with `let`, `const`, and `var`
|
||||
* variables with `let` and `const`
|
||||
* functions with lexical scoping and recursion
|
||||
* top-level code in the file; hello world really is `console.log("Hello world")`
|
||||
* `if ... else if ... else` statements
|
||||
* `while` and `do ... while` loops
|
||||
* `for(;;)` loops (see below about `for ... in/of`)
|
||||
* `for(;;)` loops and for ... of
|
||||
* `break/continue`; also with labeled loops
|
||||
* `switch` statement (on numbers only)
|
||||
* `debugger` statement for breakpoints
|
||||
* conditional operator `? :`; lazy boolean operators
|
||||
* namespaces (a form of modules)
|
||||
* all arithmetic operators (including bitwise operators); note that in microcontroller targets
|
||||
@ -25,6 +24,7 @@ For the @boardname@, we support a "static" subset of TypeScript (itself a supers
|
||||
* classes with fields, methods and constructors; `new` keyword
|
||||
* array literals `[1, 2, 3]`
|
||||
* enums
|
||||
* class inheritance
|
||||
|
||||
## Unsupported language features
|
||||
|
||||
@ -32,10 +32,10 @@ We generally stay away from the more dynamic parts of JavaScript.
|
||||
Things you may miss and we may implement:
|
||||
|
||||
* exceptions (`throw`, `try ... catch`, `try ... finally`)
|
||||
* `for ... of` statements
|
||||
* `for ... in` statements
|
||||
* object literals `{ foo: 1, bar: "two" }`
|
||||
* method-like properties (get/set accessors)
|
||||
* class inheritance
|
||||
* `debugger` statement for breakpoints
|
||||
|
||||
For JS-only targets we may implement the following:
|
||||
|
||||
@ -55,4 +55,4 @@ Things that we are not very likely to implement:
|
||||
* `eval`
|
||||
* `delete` statement
|
||||
* `for ... in` statements
|
||||
* JSX (HTML as part of JavaScript)
|
||||
* JSX (HTML as part of JavaScript)
|
||||
|
@ -3,7 +3,7 @@
|
||||
Functions are the fundamental building block of programs. Here is the simplest
|
||||
way to make a function that adds two numbers:
|
||||
|
||||
```ts
|
||||
```typescript
|
||||
// Named function
|
||||
function add(x : number, y : number) {
|
||||
return x + y;
|
||||
@ -19,7 +19,7 @@ For the @boardname@, you must specify a [type](/js/types) for each function para
|
||||
Functions can refer to variables outside of the function body.
|
||||
When they do so, they're said to `capture` these variables.
|
||||
|
||||
```ts
|
||||
```typescript
|
||||
let z = 100;
|
||||
|
||||
function addToZ(x: number, y: number) {
|
||||
@ -29,11 +29,9 @@ function addToZ(x: number, y: number) {
|
||||
basic.showNumber(addToZ(1, 2))
|
||||
```
|
||||
|
||||
## Typing the function
|
||||
|
||||
Let's add a return type to our add function:
|
||||
|
||||
```ts
|
||||
```typescript
|
||||
function add(x: number, y: number): number {
|
||||
return x + y;
|
||||
}
|
||||
@ -41,11 +39,24 @@ function add(x: number, y: number): number {
|
||||
|
||||
TypeScript can figure the return type out by looking at the return statements, so you can optionally leave this off in many cases.
|
||||
|
||||
# Arrow Functions
|
||||
|
||||
Arrow functions (also known as "lamba" functions) are used extensively to provide event handlers for
|
||||
many APIs. For example:
|
||||
|
||||
```typescript
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
[Read more about arrow functions...](http://devdocs.io/javascript/functions/arrow_functions)
|
||||
|
||||
# Optional and Default Parameters
|
||||
|
||||
In TypeScript, the number of arguments given to a function has to match the number of parameters the function expects.
|
||||
|
||||
```ts-ignore
|
||||
```typescript-ignore
|
||||
function buildName(firstName: string, lastName: string) {
|
||||
return firstName + " " + lastName;
|
||||
}
|
||||
@ -60,7 +71,7 @@ When they do, their value is `undefined`.
|
||||
We can get this functionality in TypeScript by adding a `?` to the end of parameters we want to be optional.
|
||||
For example, let's say we want the last name parameter from above to be optional:
|
||||
|
||||
```ts-ignore
|
||||
```typescript-ignore
|
||||
function buildName(firstName: string, lastName?: string) {
|
||||
if (lastName)
|
||||
return firstName + " " + lastName;
|
||||
@ -80,7 +91,7 @@ In TypeScript, we can also set a value that a parameter will be assigned if the
|
||||
These are called default-initialized parameters.
|
||||
Let's take the previous example and default the last name to `"Smith"`.
|
||||
|
||||
```ts-ignore
|
||||
```typescript-ignore
|
||||
function buildName(firstName: string, lastName = "Smith") {
|
||||
return firstName + " " + lastName;
|
||||
}
|
||||
@ -94,7 +105,7 @@ let result4 = buildName("Bob", "Adams"); // ah, just right
|
||||
Default-initialized parameters that come after all required parameters are treated as optional, and just like optional parameters, can be omitted when calling their respective function.
|
||||
This means optional parameters and trailing default parameters will share commonality in their types, so both
|
||||
|
||||
```ts
|
||||
```typescript
|
||||
function buildName(firstName: string, lastName?: string) {
|
||||
// ...
|
||||
}
|
||||
@ -102,7 +113,7 @@ function buildName(firstName: string, lastName?: string) {
|
||||
|
||||
and
|
||||
|
||||
```ts
|
||||
```typescript
|
||||
function buildName(firstName: string, lastName = "Smith") {
|
||||
// ...
|
||||
}
|
||||
@ -115,7 +126,7 @@ Unlike plain optional parameters, default-initialized parameters don't *need* to
|
||||
If a default-initialized parameter comes before a required parameter, users need to explicitly pass `undefined` to get the default initialized value.
|
||||
For example, we could write our last example with only a default initializer on `firstName`:
|
||||
|
||||
```ts-ignore
|
||||
```typescript-ignore
|
||||
function buildName(firstName = "Will", lastName: string) {
|
||||
return firstName + " " + lastName;
|
||||
}
|
||||
@ -134,7 +145,7 @@ In JavaScript, you can work with the arguments directly using the `arguments` va
|
||||
|
||||
In TypeScript, you can gather these arguments together into a variable:
|
||||
|
||||
```ts-ignore
|
||||
```typescript-ignore
|
||||
function buildName(firstName: string, ...restOfName: string[]) {
|
||||
return firstName + " " + restOfName.join(" ");
|
||||
}
|
||||
@ -148,7 +159,7 @@ The compiler will build an array of the arguments passed in with the name given
|
||||
|
||||
The ellipsis is also used in the type of the function with rest parameters:
|
||||
|
||||
```ts-ignore
|
||||
```typescript-ignore
|
||||
function buildName(firstName: string, ...restOfName: string[]) {
|
||||
return firstName + " " + restOfName.join(" ");
|
||||
}
|
||||
|
@ -18,13 +18,6 @@ This also is true when simulating in the browser.
|
||||
* comparison operators - [read more](http://devdocs.io/javascript/operators/comparison_operators)
|
||||
* conditional operator - [read more](http://devdocs.io/javascript/operators/conditional_operator)
|
||||
|
||||
## More
|
||||
|
||||
* lambda functions `() => { ... }`
|
||||
* array literals `[1, 2, 3]`
|
||||
* strings, with a few common methods
|
||||
* [string templates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) (`` `x is ${x}` ``)
|
||||
|
||||
### ~button /js/statements
|
||||
NEXT: Statements
|
||||
### ~
|
@ -5,7 +5,6 @@ The following JavaScript statements are supported for the @boardname@:
|
||||
## Variable declarations
|
||||
* `const` statement - [read more](http://devdocs.io/javascript/statements/const)
|
||||
* `let` statement - [read more](http://devdocs.io/javascript/statements/let)
|
||||
* `var` statement - [read more](http://devdocs.io/javascript/statements/var)
|
||||
|
||||
## Block-structured statements
|
||||
|
||||
|
@ -3,11 +3,27 @@
|
||||
For programs to be useful, we need to be able to work with some of the simplest units of data:
|
||||
numbers, strings, structures, boolean values, and the like.
|
||||
|
||||
# Type Inference
|
||||
|
||||
In TypeScript, there are several places where type inference is used to provide type information when there is
|
||||
no explicit type annotation. For example, in this code
|
||||
|
||||
```typescript
|
||||
let x = 3;
|
||||
let y = x + 3
|
||||
```
|
||||
|
||||
The type of the `x` variable is inferred to be `number`. Similarly, the type of `y` variable also is inferred to be `number`.
|
||||
This kind of inference takes place when initializing variables and members,
|
||||
setting parameter default values, and determining function return types.
|
||||
|
||||
All the examples below give an example type annotation, but will work just the same without the annotation.
|
||||
|
||||
# Boolean
|
||||
|
||||
The most basic datatype is the simple true/false value, which is called a `boolean` value.
|
||||
|
||||
```ts
|
||||
```typescript
|
||||
let isDone: boolean = false;
|
||||
```
|
||||
|
||||
@ -20,7 +36,7 @@ However, for the @boardname@, `numbers` are integer values.
|
||||
|
||||
Integer values can be specified via decimal, hexadecimal and octal notation:
|
||||
|
||||
```ts
|
||||
```typescript
|
||||
let decimal: number = 42;
|
||||
let hex: number = 0xf00d;
|
||||
let binary: number = 0b1010;
|
||||
@ -32,7 +48,7 @@ let octal: number = 0o744;
|
||||
As in other languages, we use the type `string` to refer to textual data.
|
||||
Use double quotes (`"`) or single quotes (`'`) to surround string data.
|
||||
|
||||
```ts
|
||||
```typescript
|
||||
let color: string = "blue";
|
||||
color = 'red';
|
||||
```
|
||||
@ -40,7 +56,7 @@ color = 'red';
|
||||
You can also use *template strings*, which can span multiple lines and have embedded expressions.
|
||||
These strings are surrounded by the backtick/backquote (`` ` ``) character, and embedded expressions are of the form `${ expr }`.
|
||||
|
||||
```ts
|
||||
```typescript
|
||||
let fullName: string = `Bob Bobbington`;
|
||||
let age: number = 37;
|
||||
let sentence: string = `Hello, my name is ${ fullName }.
|
||||
@ -50,7 +66,7 @@ I'll be ${ age + 1 } years old next month.`
|
||||
|
||||
This is equivalent to declaring `sentence` like so:
|
||||
|
||||
```ts
|
||||
```typescript
|
||||
let fullName: string = `Bob Bobbington`;
|
||||
let age: number = 37;
|
||||
let sentence: string = "Hello, my name is " + fullName + ".\n\n" +
|
||||
@ -63,13 +79,13 @@ Arrays allow you to work with an expandable sequence of values, addressed by an
|
||||
Array types can be written in one of two ways.
|
||||
In the first, you use the type of the elements followed by `[]` to denote an array of that element type:
|
||||
|
||||
```ts
|
||||
```typescript
|
||||
let list: number[] = [1, 2, 3];
|
||||
```
|
||||
|
||||
The second way uses a generic array type, `Array<elemType>`:
|
||||
|
||||
```ts
|
||||
```typescript
|
||||
let list: Array<number> = [1, 2, 3];
|
||||
```
|
||||
|
||||
@ -77,13 +93,12 @@ let list: Array<number> = [1, 2, 3];
|
||||
For the @boardname@, all elements of an array must have the same type.
|
||||
### ~
|
||||
|
||||
|
||||
# Enum
|
||||
|
||||
A helpful addition to the standard set of datatypes from JavaScript is the `enum`.
|
||||
As in languages like C#, an enum is a way of giving more friendly names to sets of numeric values.
|
||||
|
||||
```ts
|
||||
```typescript
|
||||
enum Color {Red, Green, Blue}
|
||||
let c: Color = Color.Green;
|
||||
```
|
||||
@ -92,14 +107,14 @@ By default, enums begin numbering their members starting at `0`.
|
||||
You can change this by manually setting the value of one of its members.
|
||||
For example, we can start the previous example at `1` instead of `0`:
|
||||
|
||||
```ts
|
||||
```typescript
|
||||
enum Color {Red = 1, Green, Blue}
|
||||
let c: Color = Color.Green;
|
||||
```
|
||||
|
||||
Or, even manually set all the values in the enum:
|
||||
|
||||
```ts
|
||||
```typescript
|
||||
enum Color {Red = 1, Green = 2, Blue = 4}
|
||||
let c: Color = Color.Green;
|
||||
```
|
||||
@ -108,13 +123,12 @@ let c: Color = Color.Green;
|
||||
|
||||
The TypeScript type `any` is not supported in the @boardname@.
|
||||
|
||||
|
||||
# Void
|
||||
|
||||
`void` is the absence of having any type at all.
|
||||
You may commonly see this as the return type of functions that do not return a value:
|
||||
|
||||
```ts
|
||||
```typescript
|
||||
function warnUser(): void {
|
||||
basic.showString("This is my warning message");
|
||||
}
|
||||
@ -122,21 +136,6 @@ function warnUser(): void {
|
||||
|
||||
Declaring variables of type `void` is not useful.
|
||||
|
||||
# Type Inference
|
||||
|
||||
In TypeScript, there are several places where type inference is used to provide type information when there is
|
||||
no explicit type annotation. For example, in this code
|
||||
|
||||
```ts
|
||||
let x = 3;
|
||||
let y = x + 3
|
||||
```
|
||||
|
||||
The type of the `x` variable is inferred to be `number`. Similarly, the type of `y` variable also is inferred to be `number`.
|
||||
This kind of inference takes place when initializing variables and members,
|
||||
setting parameter default values, and determining function return types.
|
||||
|
||||
|
||||
### ~button /js/classes
|
||||
NEXT: Classes
|
||||
### ~
|
@ -1,8 +1,16 @@
|
||||
# Variable Declarations
|
||||
|
||||
Declaring a variable should be done using the ``let`` keyword:
|
||||
|
||||
```typescript
|
||||
let a = 10;
|
||||
```
|
||||
|
||||
## ``var`` vs ``let``
|
||||
|
||||
Declaring a variable in JavaScript has always traditionally been done with the `var` keyword.
|
||||
|
||||
```typescript
|
||||
```typescript-ignore
|
||||
var a = 10;
|
||||
```
|
||||
|
||||
@ -16,6 +24,10 @@ let a = 10;
|
||||
|
||||
The key difference is not in the syntax, but in the semantics, which we'll now dive into.
|
||||
|
||||
### ~hint
|
||||
### Use `let` instead of `var` to introduce a new variable.
|
||||
### ~
|
||||
|
||||
## Block-scoping
|
||||
|
||||
When a variable is declared using `let`, it uses what some call *lexical-scoping* or *block-scoping*.
|
||||
|
@ -39,8 +39,8 @@ coll.push("cat")
|
||||
|
||||
## 4. Write the five (5) lines of code that will add the following five words to `data->coll`: puppy, clock, night, cat, cow.
|
||||
|
||||
```ts
|
||||
let coll = (<string[]>[])
|
||||
```typescript
|
||||
let coll : string[] = [];
|
||||
```
|
||||
|
||||
<br/>
|
||||
|
@ -3,27 +3,48 @@
|
||||
You can publish libraries (also known as packages or extensions)
|
||||
that users can then add to their scripts. These typically
|
||||
provide a driver for a particular hardware device you can connect
|
||||
to a microbit.
|
||||
to a microbit.
|
||||
|
||||
### ~ hint
|
||||
|
||||
All packages need to be approved by the Micro:bit Foundation before being available in the web editor.
|
||||
See **Approval** section below.
|
||||
|
||||
### ~
|
||||
|
||||
* [pxt-max6675](https://github.com/Microsoft/pxt-max6675) -- TypeScript
|
||||
* [pxt-neopixel](https://github.com/Microsoft/pxt-neopixel) -- TypeScript + ARM Thumb assembly package
|
||||
* [pxt-max6675](https://github.com/Microsoft/pxt-max6675) -- TypeScript
|
||||
* [pxt-sonar](https://github.com/microsoft/pxt-sonar) -- TypeScript
|
||||
* [pxt-i2c-fram](https://github.com/microsoft/pxt-i2c-fram) -- TypeScript
|
||||
|
||||
* [Sample C++ extension](https://github.com/Microsoft/pxt-microbit-cppsample)
|
||||
* [Sample TypeScript extension](https://github.com/Microsoft/pxt-microbit/tree/master/libs/i2c-fram)
|
||||
|
||||
## Finding packages
|
||||
|
||||
From the editor, the user clicks on **More** then **Add Package** and searches for the package.
|
||||
From the block editor, the user clicks on **Add Package** and searches for the package.
|
||||
Otherwise, the **Add Package** is also available from the gearwheel menu.
|
||||
|
||||
To see the list of packages, click on **More** then **Show Files** to see the project file list.
|
||||
To see the list of packages, switch to JavaScript and use the **Explorer** view to find them.
|
||||
|
||||
To remove a package, click on the garbage button in the file list next to the package.
|
||||
To remove a package, click on the garbage button in the **Explorer** view next to the package.
|
||||
|
||||
## Publishing packages
|
||||
## Publishing and Approving packages
|
||||
|
||||
Packages can be published from the pxt command line. Check out [the docs](https://www.pxt.io/packages).
|
||||
Once your package is ready, follow these steps to get it approved and listed in the pxt.microbit.org web site:
|
||||
|
||||
1. setup a public GitHub repository with your package sources
|
||||
2. ensure that the license is **Apache2** or **MIT**
|
||||
3. fill ``test.ts`` with a test scenario
|
||||
4. ensure that the package builds by running ``pxt`` from the package folder. [Read more...](https://www.pxt.io/packages).
|
||||
5. fill up the ``README.md`` file with documentation. See [markdown docs](https://pxt.io/writing-docs) for syntax.
|
||||
6. publish a release by running ``pxt bump`` from the package folder.
|
||||
7. open a support ticket at https://support.microbit.org, add **package approval** in the subject line.
|
||||
|
||||
```
|
||||
Package approval request
|
||||
|
||||
github repo: .....
|
||||
```
|
||||
|
||||
## Localizing packages
|
||||
|
||||
|
@ -57,18 +57,18 @@ Fun games to build with your @boardname@.
|
||||
"imageUrl":"/static/mb/projects/wallet.png"
|
||||
}, {
|
||||
"name": "Watch",
|
||||
"url":"/projects/the-watch",
|
||||
"url":"/projects/watch",
|
||||
"imageUrl":"/static/mb/projects/a10-watch.png"
|
||||
}]
|
||||
```
|
||||
|
||||
## Science and Engineering
|
||||
## Toys
|
||||
|
||||
```codecard
|
||||
[{
|
||||
"name": "Timing gates",
|
||||
"url":"/projects/timing-gates",
|
||||
"imageUrl":"/static/mb/projects/timing-gates.jpg"
|
||||
"name": "Inchworm",
|
||||
"url":"/projects/inchworm",
|
||||
"imageUrl":"/static/mb/projects/inchworm.jpg"
|
||||
}]
|
||||
```
|
||||
|
||||
@ -76,6 +76,10 @@ Fun games to build with your @boardname@.
|
||||
|
||||
```codecard
|
||||
[{
|
||||
"name": "Timing gates",
|
||||
"url":"/projects/timing-gates",
|
||||
"imageUrl":"/static/mb/projects/timing-gates.jpg"
|
||||
}, {
|
||||
"name": "Compass",
|
||||
"url":"/projects/compass",
|
||||
"imageUrl":"/static/mb/projects/a5-compass.png"
|
||||
@ -92,4 +96,4 @@ Fun games to build with your @boardname@.
|
||||
|
||||
### See Also
|
||||
|
||||
[Flashing Heart](/projects/flashing-heart), [Smiley Buttons](/projects/smiley-buttons), [Love Meter](/projects/love-meter), [Rock Paper Scissors](/projects/rock-paper-scissors), [Compass](/projects/compass), [Hack your headphones](/projects/hack-your-headphones), [Banana keyboard](/projects/banana-keyboard), [Telegraph](/projects/telegraph), [Radio](/projects/radio), [Guitar](/projects/guitar), [Watch](/projects/the-watch)
|
||||
[Flashing Heart](/projects/flashing-heart), [Smiley Buttons](/projects/smiley-buttons), [Love Meter](/projects/love-meter), [Rock Paper Scissors](/projects/rock-paper-scissors), [Compass](/projects/compass), [Hack your headphones](/projects/hack-your-headphones), [Banana keyboard](/projects/banana-keyboard), [Telegraph](/projects/telegraph), [Radio](/projects/radio), [Guitar](/projects/guitar), [Wallet](/projects/wallet), [Watch](/projects/watch)
|
||||
|
@ -21,8 +21,8 @@ Build your own @boardname@ piano using bananas!
|
||||
|
||||
## Activities
|
||||
|
||||
* [Making the keyboard](/projects/banana-keyboard/make)
|
||||
* [Beat box](/projects/banana-keyboard/beat-box)
|
||||
* [Make](/projects/banana-keyboard/make)
|
||||
* [Code](/projects/banana-keyboard/code)
|
||||
|
||||
### ~button /projects/banana-keyboard/make
|
||||
Let's get started!
|
||||
|
@ -1,4 +1,4 @@
|
||||
# banana keyboard - beat box
|
||||
# Code
|
||||
|
||||
Have you ever tried to making beat box sounds? Let's try making a beatbox with code!
|
||||
|
@ -1,4 +1,4 @@
|
||||
# banana keyboard - making
|
||||
# Make
|
||||
|
||||
## Materials
|
||||
|
||||
@ -80,6 +80,6 @@ input.onPinPressed(TouchPin.P1, () => {
|
||||
|
||||
Tap your banana instrument to play sound against... the fruit!
|
||||
|
||||
### ~button /projects/banana-keyboard/beat-box
|
||||
### ~button /projects/banana-keyboard/code
|
||||
NEXT: beat box
|
||||
### ~
|
||||
|
43
docs/projects/coffee-cup-monster.md
Normal file
43
docs/projects/coffee-cup-monster.md
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
# Coffee Cup Monster
|
||||
|
||||
### @description A monster made of cardboard that responds to light
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Make a coffee cup monster that responds to light!
|
||||
|
||||
### ~
|
||||
|
||||
https://youtu.be/BiZLjugXMbM
|
||||
|
||||
## Duration
|
||||
|
||||
3 Activities, approx 30-45 min each based on familiarity with the coding concepts
|
||||
|
||||
## Materials
|
||||
|
||||
* 3 Coffee cup holders
|
||||
* 2 Coffee cup strirer wood sticks
|
||||
* Glue gun
|
||||
* Scissors that can cut cardboard
|
||||
* 1 @boardname@, battery holder and 2 AAA batteries
|
||||
* 3 Crocodile clips
|
||||
* 1 micro servo 9g SG90
|
||||
* 1 paper clip
|
||||
|
||||
## Preparation
|
||||
|
||||
* [Equip the microservo with crocodile clips](/device/servo)
|
||||
|
||||
## Activities
|
||||
|
||||
* [Make](/projects/coffee-cup-monster/make)
|
||||
* [Code](/projects/coffee-cup-monster/code)
|
||||
* [Connect](/projects/coffee-cup-monster/connect)
|
||||
|
||||
### ~button /projects/coffee-cup-monster/make
|
||||
|
||||
Let's get started!
|
||||
|
||||
### ~
|
29
docs/projects/coffee-cup-monster/code.md
Normal file
29
docs/projects/coffee-cup-monster/code.md
Normal file
@ -0,0 +1,29 @@
|
||||
# Code
|
||||
### @description code to make the coffee cup monster alive
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Add code to open the mouth when light is detected.
|
||||
|
||||
### ~
|
||||
|
||||
## Duration: ~30 minutes
|
||||
|
||||
We are going to add code to open the mouth proportionally to the amount of light on the @boardname@.
|
||||
In a loop, we will read the light and map it to an angle using the ``pins.map`` function.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
pins.servoWritePin(AnalogPin.P0, pins.map(
|
||||
input.lightLevel(),
|
||||
0,
|
||||
255,
|
||||
30,
|
||||
150
|
||||
))
|
||||
})
|
||||
```
|
||||
|
||||
### ~button /projects/coffee-cup-monster/connect
|
||||
NEXT: Connect
|
||||
### ~
|
29
docs/projects/coffee-cup-monster/connect.md
Normal file
29
docs/projects/coffee-cup-monster/connect.md
Normal file
@ -0,0 +1,29 @@
|
||||
# Connect
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Remote control your monster with another @boardname@
|
||||
|
||||
### ~
|
||||
|
||||
## Duration: ~30 minutes
|
||||
|
||||
You will need 2 @boardname@ for this part. By using the radio, we can make the inchworm controlled by another @boardname@.
|
||||
Download the code below to the @boardname@ on the inchworm and another "controller" @boardname@.
|
||||
Whenere A is pressed, the monster will open and close it's mouth will move once.
|
||||
|
||||
```blocks
|
||||
radio.onDataPacketReceived(({receivedNumber}) => {
|
||||
pins.servoWritePin(AnalogPin.P0, 30)
|
||||
basic.pause(500)
|
||||
pins.servoWritePin(AnalogPin.P0, 150)
|
||||
basic.pause(500)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
radio.sendNumber(0)
|
||||
})
|
||||
```
|
||||
|
||||
```package
|
||||
radio
|
||||
```
|
25
docs/projects/coffee-cup-monster/make.md
Normal file
25
docs/projects/coffee-cup-monster/make.md
Normal file
@ -0,0 +1,25 @@
|
||||
# Make
|
||||
### @description Building the coffee cup monster
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Turn a piece of coffee holders into a monster!
|
||||
|
||||
### ~
|
||||
|
||||
## Duration: ~60 minutes
|
||||
|
||||
## Materials
|
||||
* 3 Coffee cup holders
|
||||
* 2 Coffee cup strirer wood sticks
|
||||
* Scissors
|
||||
* glue gun or tape
|
||||
* 1 paper clip
|
||||
|
||||
## Step 1: cardboard
|
||||
|
||||
TODO
|
||||
|
||||
### ~button /projects/coffee-cup-monster/code
|
||||
NEXT: Code
|
||||
### ~
|
@ -10,12 +10,10 @@ Welcome! This guided tutorial will show you how to program a script that display
|
||||
|
||||
### ~
|
||||
|
||||
|
||||
## Step 1
|
||||
|
||||
Create a loop that will continuously update the reading of the compass.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
|
||||
|
@ -1,26 +1,8 @@
|
||||
# flashing heart
|
||||
|
||||

|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
```sim
|
||||
basic.forever(() => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .`
|
||||
);
|
||||
basic.pause(500);
|
||||
basic.clearScreen();
|
||||
basic.pause(500);
|
||||
})
|
||||
```
|
||||
|
||||
Use the LEDs to display a flashing heart, and then create
|
||||
an animation of a broken heart. :(
|
||||
Use the LEDs to display a flashing heart!
|
||||
|
||||
### ~
|
||||
|
||||
@ -55,19 +37,19 @@ basic.clearScreen();
|
||||
|
||||
## Step 3
|
||||
|
||||
Put a [forever loop](/reference/basic/forever) around it.
|
||||
Put a [forever loop](/reference/basic/forever) around it to repeat the animation.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .`
|
||||
);
|
||||
basic.pause(500);
|
||||
basic.clearScreen();
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .`
|
||||
);
|
||||
basic.pause(500);
|
||||
basic.clearScreen();
|
||||
})
|
||||
```
|
||||
|
||||
@ -77,45 +59,50 @@ Add a [pause](/reference/basic/pause) to wait after clearing the screen.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .`
|
||||
);
|
||||
basic.pause(500);
|
||||
basic.clearScreen();
|
||||
basic.pause(500);
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .`
|
||||
);
|
||||
basic.pause(500);
|
||||
basic.clearScreen();
|
||||
basic.pause(500);
|
||||
})
|
||||
```
|
||||
|
||||
## Step 5
|
||||
## Send your heartbeats over radio!
|
||||
|
||||
Add a second image of a broken heart.
|
||||
Do you have a second @boardname@ at hand? You could use radio and send your heartbeats to other
|
||||
@boardname@ and show a heart when you receive one.
|
||||
|
||||
* move the code in the **forever** inside
|
||||
a [on data packet received](/reference/radio/on-data-packet-received) handler.
|
||||
The handler will run whenever a message is received from another @boardname@.
|
||||
* use [send number](/reference/radio/send-number) and [pause](/reference/basic/pause)
|
||||
to broadcast a packet of data every second.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .`
|
||||
);
|
||||
basic.pause(500);
|
||||
basic.clearScreen();
|
||||
basic.pause(500);
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# . # # #
|
||||
# . . . #
|
||||
. # # # .
|
||||
. . # . .`
|
||||
);
|
||||
basic.pause(500);
|
||||
basic.clearScreen();
|
||||
basic.pause(500);
|
||||
radio.sendNumber(0)
|
||||
basic.pause(1000)
|
||||
})
|
||||
radio.onDataPacketReceived(({receivedNumber}) => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .`);
|
||||
basic.pause(500)
|
||||
basic.clearScreen()
|
||||
basic.pause(500)
|
||||
})
|
||||
```
|
||||
|
||||
Download the .hex file onto both @boardname@ and try it out!
|
||||
|
||||
```package
|
||||
radio
|
||||
```
|
@ -1,7 +1,5 @@
|
||||
# Guitar
|
||||
|
||||

|
||||
|
||||
### @description A beginner-intermediate maker activity, building a guitar with the @boardname@
|
||||
|
||||
### ~avatar avatar
|
||||
@ -9,7 +7,7 @@
|
||||
Make a @boardname@ guitar with this guided tutorial!
|
||||
|
||||
### ~
|
||||
*playing @boardname@ guitar*
|
||||
|
||||
https://youtu.be/GYmdTFvxz80
|
||||
|
||||
## Duration
|
||||
|
@ -21,7 +21,7 @@ Use pin press to switch guitar play on/off
|
||||
## Blocks
|
||||
|
||||
```cards
|
||||
var on = false
|
||||
let on = false
|
||||
on;
|
||||
if (on) { } else {}
|
||||
input.onPinPressed(TouchPin.P1, () => {})
|
||||
@ -106,7 +106,7 @@ input.onPinPressed(TouchPin.P1, () => {
|
||||
*Final code*
|
||||
TODO: do we want to use `on = !on;` or be more direct in flipping the switch? `on = true; on = false;`
|
||||
```blocks
|
||||
var on = false
|
||||
let on = false
|
||||
basic.forever(() => {
|
||||
if (on) {
|
||||
music.setTempo(pins.map(Math.abs(input.acceleration(Dimension.Y)),
|
||||
|
@ -19,17 +19,17 @@ Build your own music player @boardname@ from headphones.
|
||||
* Headphones
|
||||
* Crocodile clips
|
||||
|
||||
## Activities
|
||||
|
||||
* [Connect your headphone](/projects/hack-your-headphones/make)
|
||||
* [Play sounds!]()
|
||||
|
||||
# ~hint
|
||||
|
||||
**No crocodile clips!?!?!** Use wires or Aluminium foil! [Read more...](/device/foil-circuits)
|
||||
|
||||
# ~
|
||||
|
||||
## Activities
|
||||
|
||||
* [Make](/projects/hack-your-headphones/make)
|
||||
* [Code](/projects/hack-your-headphones/code)
|
||||
|
||||
### ~button /projects/hack-your-headphones/make
|
||||
|
||||
Let's get started!
|
||||
|
@ -1,4 +1,4 @@
|
||||
# hack your headphones - music of light
|
||||
# Code
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
@ -10,7 +10,9 @@ Let's start by adding a variable where you can store data. Then rename the varia
|
||||
|
||||
|
||||
```blocks
|
||||
let light = input.lightLevel();
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let light = input.lightLevel();
|
||||
});
|
||||
```
|
||||
|
||||
We want to play music on button pressed in order to register an event handler that will execute whenever when you run a script and click on button pressed on the simulator. We must start by opening the Input drawer and adding `on button pressed` A. Then add a block `rest` to plays nothing for a `1/16` beat. Modify your code so that your code looks like this.
|
@ -1,4 +1,4 @@
|
||||
# hack your headphones - making
|
||||
# Make
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
@ -46,7 +46,7 @@ Using the 2nd crocodile clip, connect the second end of the crocodile clip onto
|
||||
|
||||
You hacked your headphones!
|
||||
|
||||
### ~button /projects/hack-your-headphones/music-of-light
|
||||
### ~button /projects/hack-your-headphones/code
|
||||
|
||||
NEXT: music of light
|
||||
|
||||
|
44
docs/projects/inchworm.md
Normal file
44
docs/projects/inchworm.md
Normal file
@ -0,0 +1,44 @@
|
||||
|
||||
# Inchworm
|
||||
|
||||
### @description A inchworm like robot built with the @boardname@
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Make a funny inchworm robot!
|
||||
|
||||
### ~
|
||||
|
||||
https://youtu.be/BiZLjugXMbM
|
||||
|
||||
## Duration
|
||||
|
||||
3 Activities, approx 30-45 min each based on familiarity with the coding concepts
|
||||
|
||||
## Materials
|
||||
|
||||
* Cardboard pieces (recycle!)
|
||||
* Glue gun or Tape (masking, duct tape, and/or packing tape)
|
||||
* Scissors that can cut cardboard
|
||||
* 1 @boardname@, battery holder and 2 AAA batteries
|
||||
* 3 Crocodile clips
|
||||
* 1 micro servo 9g SG90
|
||||
* 1 paper clip
|
||||
|
||||

|
||||
|
||||
## Preparation
|
||||
|
||||
* [Equip the microservo with crocodile clips](/device/servo)
|
||||
|
||||
## Activities
|
||||
|
||||
* [Make](/projects/inchworm/make)
|
||||
* [Code](/projects/inchworm/code)
|
||||
* [Connect](/projects/inchworm/connect)
|
||||
|
||||
### ~button /projects/inchworm/make
|
||||
|
||||
Let's get started!
|
||||
|
||||
### ~
|
35
docs/projects/inchworm/code.md
Normal file
35
docs/projects/inchworm/code.md
Normal file
@ -0,0 +1,35 @@
|
||||
# Code
|
||||
### @description code to make the inchworm alive
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Add code to make the inchworm move.
|
||||
|
||||
### ~
|
||||
|
||||
## Duration: ~30 minutes
|
||||
|
||||
## Step 1: walk forever
|
||||
|
||||
In order for the inchworm to move, the @boardname@ needs to command the servo to go between ``0`` and ``180`` degrees
|
||||
at a certain pace. In the code below, the user pressed button ``A`` to launch the inchworm.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
pins.servoWritePin(AnalogPin.P0, 0);
|
||||
basic.pause(500);
|
||||
pins.servoWritePin(AnalogPin.P0, 180);
|
||||
basic.pause(500);
|
||||
});
|
||||
```
|
||||
|
||||
### ~ hint
|
||||
|
||||
You may have noticed that the inchworm can be rather slow or simply won't move. Try to improve the design of your legs, teeth
|
||||
so that the inchworm goes as fast as possible. Trying it on carpet also great helps avoiding skidding.
|
||||
|
||||
### ~
|
||||
|
||||
### ~button /projects/inchworm/connect
|
||||
NEXT: Connect
|
||||
### ~
|
28
docs/projects/inchworm/connect.md
Normal file
28
docs/projects/inchworm/connect.md
Normal file
@ -0,0 +1,28 @@
|
||||
# Connect
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Remote control your inchworm with another @boardname@
|
||||
|
||||
### ~
|
||||
|
||||
## Duration: ~30 minutes
|
||||
|
||||
You will need 2 @boardname@ for this part. By using the radio, we can make the inchworm controlled by another @boardname@.
|
||||
Download the code below to the @boardname@ on the inchworm and another "controller" @boardname@. Whenere A is pressed, the inchworm will move once.
|
||||
|
||||
```blocks
|
||||
radio.onDataPacketReceived(({receivedNumber}) => {
|
||||
pins.servoWritePin(AnalogPin.P0, 0)
|
||||
basic.pause(500)
|
||||
pins.servoWritePin(AnalogPin.P0, 180)
|
||||
basic.pause(500)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
radio.sendNumber(0)
|
||||
})
|
||||
```
|
||||
|
||||
```package
|
||||
radio
|
||||
```
|
88
docs/projects/inchworm/make.md
Normal file
88
docs/projects/inchworm/make.md
Normal file
@ -0,0 +1,88 @@
|
||||
# Make
|
||||
### @description Building the cardboard inchworm
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Turn a piece of cardboard into an inchworm!
|
||||
|
||||
### ~
|
||||
|
||||
## Duration: ~45 minutes
|
||||
|
||||
## Materials
|
||||
* Cardboard
|
||||
* Scissors or cutters
|
||||
* glue gun or tape
|
||||
* 1 paper clip
|
||||
|
||||
## Step 1: cardboard
|
||||
|
||||
Cutout a cardboard rectangle. You can use the @boardname@ as a ruler to figure out the size.
|
||||
|
||||

|
||||
|
||||
## Step 2: center fold
|
||||
|
||||
Fold the cardboard in half over the short edge.
|
||||
|
||||

|
||||
|
||||
## Step 3: legs
|
||||
|
||||
Fold each end so they rest flat on the ground.
|
||||
|
||||

|
||||
|
||||
## Step 4: front teeth
|
||||
|
||||
Fold each corners on one end of the cardbard. This will be the front of the inchworm which is supposed to grip the ground.
|
||||
|
||||

|
||||
|
||||
## Step 5: back teeth
|
||||
|
||||
Using a scissor or a cutter (watch the fingers!), cut out various strips in the other edge. Fold one after the other.
|
||||
|
||||

|
||||
|
||||
## Step 6: mounting the board
|
||||
|
||||
Using tape or a glue gun, mount the @boardname@ on one side and the microservo on the cardobard.
|
||||
|
||||

|
||||
|
||||
## Step 7: mounting the servo
|
||||
|
||||
Attach the servo on the **edge** of the other cardboard side.
|
||||
|
||||

|
||||
|
||||
## Step 8: Cable clean up (optional)
|
||||
|
||||
Use tape to route the cables nicely on the inchworm.
|
||||
|
||||

|
||||
|
||||
## Step 9: attaching paper clip to servo
|
||||
|
||||
Unfold a paper clip and attach it to the servo arm.
|
||||
|
||||

|
||||
|
||||
## Step 10: attaching paper clip to cardboard
|
||||
|
||||
Slide the folder paper clip into the cardboard, and use tape to secure it.
|
||||
You might need to toy around with the size of the clip so that the servo rotation opens the inchworm sufficiently.
|
||||
|
||||

|
||||
|
||||
|
||||
## Step 11: it's ready!
|
||||
|
||||
Your inchworm is ready!
|
||||
|
||||

|
||||
|
||||
### ~button /projects/inchworm/code
|
||||
NEXT: Code
|
||||
### ~
|
@ -1,8 +1,10 @@
|
||||
# love meter
|
||||
|
||||

|
||||
### ~avatar avatar
|
||||
|
||||
Use pins P0, P1 and P2 to change the display by creating a circuit with your body.
|
||||
Use pins and your body to change the display!
|
||||
|
||||
### ~
|
||||
|
||||
## Step 1
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
# magic button trick
|
||||
|
||||
Perform a magic trick where you appear to make the **A** and **B** button of your @boardname@ swap over just by moving a sticky label.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! This activity will teach you how to use the @boardname@'s compass to detect a nearby magnet
|
||||
Build a magic trick that uses the @boardname@'s compass to detect a nearby magnet!
|
||||
|
||||
### ~
|
||||
This is a simple magic trick you can perform to amaze your friends, where by moving the sticky labels on your @boardname@'s **A** and **B** button you appear to make the buttons really switch over. To see the trick performed watch the video below.
|
||||
@ -39,7 +37,7 @@ input.onButtonPressed(Button.B, () => {
|
||||
|
||||
We will use the @boardname@'s compass to detect the magnet. Compass's tell us what direction we are pointing by detecting the Earth's magnetic field but they can also detect any other magnet nearby. We will use that to check if our magnet is next to the @boardname@ by using the [magnetic force](/reference/input/magnetic-force) block found in the input menu's 'more' section. As we only want to measure the strength we change the drop down to select 'strength':
|
||||
|
||||
```blocks
|
||||
```block
|
||||
input.magneticForce(Dimension.Strength)
|
||||
```
|
||||
|
||||
@ -52,16 +50,19 @@ If you have ever played with magnets you know they have two ends, often called a
|
||||
So in the code below we will check if the absolute value of our magnetic field strength reading is more than 100 and save the result of that check in a new variable called 'isSwitched':
|
||||
|
||||
```blocks
|
||||
let isSwitched = Math.abs(input.magneticForce(Dimension.Strength)) > 100
|
||||
let force = Math.abs(input.magneticForce(Dimension.Strength));
|
||||
let isSwitched = force > 100
|
||||
```
|
||||
## Step 4: running our 'magnet nearby' check all the time
|
||||
|
||||
At the moment our code to detect the magnet being nearby will only run once so we need to put it into a [forever](/reference/basic/forever) block so that it keeps getting run again and again checking for the magnet to come near to the @boardname@. We should also make sure 'isSwitched' is false when our program starts.
|
||||
|
||||
```blocks
|
||||
let force = 0;
|
||||
let isSwitched = false;
|
||||
basic.forever(() => {
|
||||
let isSwitched = Math.abs(input.magneticForce(Dimension.Strength)) > 100
|
||||
force = Math.abs(input.magneticForce(Dimension.Strength));
|
||||
isSwitched = force > 100
|
||||
})
|
||||
```
|
||||
|
||||
@ -70,10 +71,11 @@ basic.forever(() => {
|
||||
Now we can check the value of our variable 'isSwitched' whenever we want and we will know that the magnet is nearby if it's value is 'true'. Let's use that to change how the buttons work and complete the code for our trick. We will add an 'if, else' block to each button's code and check if we should swap over what each button displays because 'isSwitched' is equal to true:
|
||||
|
||||
```blocks
|
||||
|
||||
let force = 0;
|
||||
let isSwitched = false;
|
||||
basic.forever(() => {
|
||||
isSwitched = Math.abs(input.magneticForce(Dimension.Strength)) > 100
|
||||
force = Math.abs(input.magneticForce(Dimension.Strength));
|
||||
isSwitched = force > 100
|
||||
})
|
||||
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
|
@ -1,51 +1,11 @@
|
||||
# rock paper scissors
|
||||
|
||||

|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
```sim
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img = Math.random(3)
|
||||
if (img == 0) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# # # # #
|
||||
`)
|
||||
|
||||
} else if (img == 1) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. . . . .
|
||||
`)
|
||||
} else {
|
||||
basic.showLeds(`
|
||||
# # . . #
|
||||
# # . # .
|
||||
. . # . .
|
||||
# # . # .
|
||||
# # . . #
|
||||
`)
|
||||
}
|
||||
})
|
||||
```
|
||||
In this project, you will build a Rock Paper Scissors game with the @boardname@.
|
||||
You can play the game with a friend who has it on a @boardname@.
|
||||
You can also play it with friends who are just using their hands.
|
||||
Build a rock paper scissors game!
|
||||
|
||||
### ~
|
||||
|
||||
|
||||
## Materials needed
|
||||
|
||||
* Your @boardname@ -- that's it!
|
||||
|
||||
## Step 1: Getting started
|
||||
|
||||
We want the @boardname@ to choose rock, paper, or scissors when you shake it.
|
||||
|
@ -1,8 +1,10 @@
|
||||
# smiley buttons
|
||||
|
||||

|
||||
### ~avatar
|
||||
|
||||
Use buttons to show a smiley or frowny face.
|
||||
Use buttons to show a smiley face!
|
||||
|
||||
### ~
|
||||
|
||||
## Step 1
|
||||
|
||||
@ -10,8 +12,8 @@ Use [show leds](/reference/basic/show-leds) to make a smiley face:
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. # . # .
|
||||
# # . # #
|
||||
# # . # #
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .`
|
||||
@ -20,56 +22,93 @@ basic.showLeds(`
|
||||
|
||||
## Step 2
|
||||
|
||||
Add an input block for when [button A is pressed](/reference/input/button-is-pressed), and put a
|
||||
frowny face inside it:
|
||||
Add an input block for when [button A is pressed](/reference/input/button-is-pressed),
|
||||
and **move** the smiley face inside it:
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. # . # .
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .`
|
||||
);
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # # # .
|
||||
# . . . #`
|
||||
);
|
||||
});
|
||||
```
|
||||
|
||||
## Step 3
|
||||
|
||||
Now add blocks so that when [button B is pressed](/reference/input/button-is-pressed), a smiley appears:
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. # . # .
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .`
|
||||
);
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # # # .
|
||||
# . . . #`
|
||||
);
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. # . # .
|
||||
# # . # #
|
||||
# # . # #
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .`
|
||||
);
|
||||
});
|
||||
```
|
||||
|
||||
Try pressing button A!
|
||||
|
||||
## Step 3
|
||||
|
||||
Now add blocks so that when [button B is pressed](/reference/input/on-button-pressed),
|
||||
a frowney appears:
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showLeds(`
|
||||
# # . # #
|
||||
# # . # #
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .`
|
||||
);
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.showLeds(`
|
||||
# # . # #
|
||||
# # . # #
|
||||
. . . . .
|
||||
. # # # .
|
||||
# . . . #`
|
||||
);
|
||||
});
|
||||
```
|
||||
|
||||
Try pressing ``A`` or ``B``!
|
||||
|
||||
## Send your smileys over radio
|
||||
|
||||
Do you have a second @boardname@ at hand? You could use radio and send your smileys or frownies to other
|
||||
@boardname@.
|
||||
|
||||
Since radio can send numbers, we decide that ``0`` is the code for displaying a smiley
|
||||
and ``1`` is the code for a frowney.
|
||||
|
||||
Change your code as follows:
|
||||
* [radio send number](/reference/radio/send-number) sends a number
|
||||
to any other @boardname@ in range
|
||||
* [radio on data packet received](/reference/radio/on-data-packet-received) runs code
|
||||
when data is received over radio
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
radio.sendNumber(0)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
radio.sendNumber(1)
|
||||
})
|
||||
radio.onDataPacketReceived(({receivedNumber}) => {
|
||||
if (receivedNumber == 0) {
|
||||
basic.showLeds(`
|
||||
# # . # #
|
||||
# # . # #
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .
|
||||
`)
|
||||
} else {
|
||||
basic.showLeds(`
|
||||
# # . # #
|
||||
# # . # #
|
||||
. . . . .
|
||||
. # # # .
|
||||
# . . . #
|
||||
`)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
```package
|
||||
radio
|
||||
```
|
||||
|
@ -17,8 +17,8 @@ Build a telegraph between two @boardname@s to communicate with your friends!
|
||||
|
||||
## Activities
|
||||
|
||||
* [Making the circuit](/projects/telegraph/make)
|
||||
* [Manual telegraph](/projects/telegraph/manual-telegraph)
|
||||
* [Make](/projects/telegraph/make)
|
||||
* [Code](/projects/telegraph/code)
|
||||
|
||||
### ~button /projects/telegraph/make
|
||||
Let's get started!
|
||||
|
@ -1,4 +1,4 @@
|
||||
# telegraph - manual telegraph
|
||||
# Code
|
||||
|
||||
Let's build the code that will send a impulse while the user presses ``A``.
|
||||
|
@ -1,4 +1,4 @@
|
||||
# telegraph - making
|
||||
# Make
|
||||
|
||||
### ~avatar
|
||||
|
||||
@ -68,8 +68,8 @@ Using the 4th crocodile clip, connect the unattached end of the crocodile clip o
|
||||

|
||||
|
||||
|
||||
### ~button /projects/telegraph/manual-telegraph
|
||||
### ~button /projects/telegraph/code
|
||||
|
||||
NEXT: manual telegraph
|
||||
NEXT: Code
|
||||
|
||||
### ~
|
||||
|
@ -1,7 +1,5 @@
|
||||
# Wallet
|
||||
|
||||

|
||||
|
||||
### @description A beginner maker activity, building a duct tape wallet with the @boardname@
|
||||
|
||||
### ~avatar avatar
|
||||
@ -12,23 +10,6 @@ Make a @boardname@ wallet with this guided tutorial!
|
||||
|
||||

|
||||
|
||||
## Duration
|
||||
|
||||
2 Activities, approx 30-45 min each based on familiarity with the coding concepts
|
||||
|
||||
## Materials
|
||||
|
||||
* Paper sheet
|
||||
* Tape (masking, duct tape, and/or packing tape)
|
||||
* Scissors
|
||||
* 1 @boardname@, battery holder and 2 AAA batteries
|
||||
* Marker or pen
|
||||
|
||||
## Activities
|
||||
|
||||
* [Make](/projects/wallet/make)
|
||||
* [Code](/projects/wallet/code)
|
||||
|
||||
### ~button /projects/wallet/make
|
||||
|
||||
Let's get started!
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Wallet - Code
|
||||
# Code
|
||||
|
||||
## Simple animation
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Wallet - Make
|
||||
# Make
|
||||
|
||||
### @description Maker Project for Wallet
|
||||
|
||||
|
20
docs/projects/watch.md
Normal file
20
docs/projects/watch.md
Normal file
@ -0,0 +1,20 @@
|
||||
# the watch
|
||||
|
||||
### ~avatar
|
||||
|
||||
Build your own @boardname@ watch from an old pair of jeans and T-shirt!
|
||||
|
||||
### ~
|
||||
|
||||

|
||||
|
||||
### ~button /projects/watch/make
|
||||
|
||||
Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
### Acknowledgements
|
||||
|
||||
Artistic design by Melinda Hoeneisen.
|
||||
|
@ -1,12 +1,14 @@
|
||||

|
||||
# the watch - Make
|
||||
|
||||
# the watch
|
||||
### @description Maker Project for Watch
|
||||
|
||||

|
||||
### ~avatar avatar
|
||||
|
||||
In this project, you will build your own wearable @boardname@ watch from an old pair of jeans and T-shirt. Project duration: 15 minutes.
|
||||
Make a watch for your @boardname@
|
||||
|
||||

|
||||
### ~
|
||||
|
||||
## Duration: ~30 minutes
|
||||
|
||||
## Materials
|
||||
|
||||
@ -147,8 +149,3 @@ Trim any leftover fabric, threads or tape.
|
||||

|
||||
|
||||
Your watch is ready!
|
||||
|
||||
### Acknowledgements
|
||||
|
||||
Artistic design by Melinda Hoeneisen.
|
||||
|
@ -30,7 +30,7 @@ control.inBackground(() => {
|
||||
```
|
||||
|
||||
## Bluetooth
|
||||
|
||||
|
||||
```namespaces
|
||||
devices.tellCameraTo(MesCameraEvent.TakePhoto);
|
||||
bluetooth.onBluetoothConnected(() => {});
|
||||
|
@ -4,6 +4,7 @@ Provides access to basic @boardname@ functionality.
|
||||
|
||||
```cards
|
||||
basic.showNumber(0);
|
||||
basic.showIcon(IconNames.Heart);
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
@ -24,6 +25,7 @@ basic.plotLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
`);
|
||||
basic.showArrow(ArrowNames.North);
|
||||
basic.showAnimation(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
@ -35,6 +37,8 @@ basic.showAnimation(`
|
||||
|
||||
### See Also
|
||||
|
||||
[showNumber](/reference/basic/show-number), [showLeds](/reference/basic/show-leds), [showString](/reference/basic/show-string),
|
||||
[showNumber](/reference/basic/show-number),
|
||||
[showIcon](/reference/basic/show-icon),
|
||||
[showLeds](/reference/basic/show-leds), [showString](/reference/basic/show-string),
|
||||
[clearScreen](/reference/basic/clear-screen), [forever](/reference/basic/forever), [pause](/reference/basic/pause),
|
||||
[showAnimation](/reference/basic/show-animation)
|
||||
|
@ -18,15 +18,15 @@ and updates the screen with the direction.
|
||||
basic.forever(() => {
|
||||
let heading = input.compassHeading()
|
||||
if (heading < 45) {
|
||||
basic.showString("N", 100)
|
||||
basic.showString("N")
|
||||
} else if (heading < 135) {
|
||||
basic.showString("E", 100)
|
||||
basic.showString("E")
|
||||
}
|
||||
else if (heading < 225) {
|
||||
basic.showString("S", 100)
|
||||
basic.showString("S")
|
||||
}
|
||||
else {
|
||||
basic.showString("W", 100)
|
||||
basic.showString("W")
|
||||
}
|
||||
})
|
||||
```
|
||||
@ -40,7 +40,7 @@ You can use a program like this to count things with your @boardname@.
|
||||
```blocks
|
||||
let num = 0
|
||||
basic.forever(() => {
|
||||
basic.showNumber(num, 150)
|
||||
basic.showNumber(num)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
num = num + 1
|
||||
@ -56,10 +56,10 @@ Try this on your @boardname@:
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showNumber(6789, 150)
|
||||
basic.showNumber(6789)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showNumber(2, 150)
|
||||
basic.showNumber(2)
|
||||
})
|
||||
```
|
||||
|
||||
|
23
docs/reference/basic/show-arrow.md
Normal file
23
docs/reference/basic/show-arrow.md
Normal file
@ -0,0 +1,23 @@
|
||||
# Show Arrow
|
||||
|
||||
Shows the selected arrow on the LED screen
|
||||
|
||||
```sig
|
||||
basic.showArrow(ArrowNames.North)
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
This program shows all eight arrows.
|
||||
|
||||
```blocks
|
||||
for (let index = 0; index <= 7; index++) {
|
||||
basic.showArrow(index)
|
||||
basic.pause(300)
|
||||
}
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[showIcon](/reference/basic/show-icon),
|
||||
[showLeds](/reference/basic/show-leds)
|
21
docs/reference/basic/show-icon.md
Normal file
21
docs/reference/basic/show-icon.md
Normal file
@ -0,0 +1,21 @@
|
||||
# Show Icon
|
||||
|
||||
Shows the selected icon on the LED screen
|
||||
|
||||
```sig
|
||||
basic.showIcon(IconNames.Heart)
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
This program shows a happy face and then a sad face with the ``show icon`` function, with a one second pause in between.
|
||||
|
||||
```blocks
|
||||
basic.showIcon(IconNames.Happy)
|
||||
basic.pause(1000)
|
||||
basic.showIcon(IconNames.Sad)
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[showLeds](/reference/basic/show-leds)
|
@ -19,6 +19,7 @@ bluetooth.startMagnetometerService();
|
||||
bluetooth.startTemperatureService();
|
||||
bluetooth.onBluetoothConnected(() => {});
|
||||
bluetooth.onBluetoothDisconnected(() => {});
|
||||
bluetooth.setTransmitPower(7);
|
||||
```
|
||||
|
||||
## UART
|
||||
@ -31,6 +32,14 @@ bluetooth.uartWriteNumber(0);
|
||||
bluetooth.uartWriteValue("", 0);
|
||||
```
|
||||
|
||||
## Eddystone
|
||||
|
||||
```cards
|
||||
bluetooth.advertiseUid(42, 1, 7, true);
|
||||
bluetooth.advertiseUrl("https://pxt.microbit.org/", 7, true);
|
||||
bluetooth.stopAdvertising();
|
||||
```
|
||||
|
||||
```package
|
||||
bluetooth
|
||||
```
|
||||
@ -47,4 +56,7 @@ For more advanced information on the @boardname@ Bluetooth UART service includin
|
||||
[uartWriteString](/reference/bluetooth/uart-write-string),
|
||||
[uartWriteNumber](/reference/bluetooth/uart-write-number),
|
||||
[uartWriteValue](/reference/bluetooth/uart-write-value),
|
||||
[onBluetoothConnected](/reference/bluetooth/on-bluetooth-connected), [onBluetoothDisconnected](/reference/bluetooth/on-bluetooth-disconnected)
|
||||
[onBluetoothConnected](/reference/bluetooth/on-bluetooth-connected),
|
||||
[onBluetoothDisconnected](/reference/bluetooth/on-bluetooth-disconnected),
|
||||
[advertiseUrl](/reference/bluetooth/advertise-url),
|
||||
[stopAdvertising](/reference/bluetooth/stop-advertising)
|
||||
|
37
docs/reference/bluetooth/advertise-uid-buffer.md
Normal file
37
docs/reference/bluetooth/advertise-uid-buffer.md
Normal file
@ -0,0 +1,37 @@
|
||||
# Avertise UID Buffer
|
||||
|
||||
Advertises a UID via the Eddystone protocol over Bluetooth.
|
||||
|
||||
## ~hint
|
||||
|
||||
### Eddystone
|
||||
|
||||
Bluetooth beacons are used to indicate proximity to a place or object of interest.
|
||||
Beacons use Bluetooth advertising to broadcast a small amount of data,
|
||||
which can be received and acted upon by anyone in range with a suitable device and software, typically a smartphone and application.
|
||||
|
||||
There are various beacon message formats, which define the way Bluetooth advertising packets are used as containers for beacon data.
|
||||
iBeacon is Apple's beacon message format. Eddystone comes from Google.
|
||||
|
||||
Read more at https://lancaster-university.github.io/microbit-docs/ble/eddystone/ .
|
||||
|
||||
## ~
|
||||
|
||||
```sig
|
||||
bluetooth.advertiseUidBuffer(pins.createBuffer(16), 7, true);
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``buffer`` - a 16 bytes buffer containing the namespace (first 10 bytes) and instance (last 6 bytes).
|
||||
* ``power`` - a [number](/reference/types/number) representing the power level between 0 (short) and 7 (maximum range).
|
||||
* ``connectable`` - a [boolean](/blocks/logic/boolean) indicating whether or not the @boardname@ should accept connections.
|
||||
|
||||
|
||||
## See Also
|
||||
|
||||
[stop-advertising](/reference/bluetooth/stop-advertising), [advertise-uid](/reference/bluetooth/advertise-uid)
|
||||
|
||||
```package
|
||||
bluetooth
|
||||
```
|
46
docs/reference/bluetooth/advertise-uid.md
Normal file
46
docs/reference/bluetooth/advertise-uid.md
Normal file
@ -0,0 +1,46 @@
|
||||
# Avertise UID
|
||||
|
||||
Advertises a UID via the Eddystone protocol over Bluetooth.
|
||||
|
||||
## ~hint
|
||||
|
||||
### Eddystone
|
||||
|
||||
Bluetooth beacons are used to indicate proximity to a place or object of interest.
|
||||
Beacons use Bluetooth advertising to broadcast a small amount of data,
|
||||
which can be received and acted upon by anyone in range with a suitable device and software, typically a smartphone and application.
|
||||
|
||||
There are various beacon message formats, which define the way Bluetooth advertising packets are used as containers for beacon data.
|
||||
iBeacon is Apple's beacon message format. Eddystone comes from Google.
|
||||
|
||||
Read more at https://lancaster-university.github.io/microbit-docs/ble/eddystone/ .
|
||||
|
||||
## ~
|
||||
|
||||
```sig
|
||||
bluetooth.advertiseUid(42, 1, 7, true);
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``namespace`` last 4 bytes of the namespace uid (6 to 9)
|
||||
* ``instance`` last 4 bytes of the instance (2 to 5)
|
||||
* ``power`` - a [number](/reference/types/number) representing the power level between 0 (short) and 7 (maximum range).
|
||||
* ``connectable`` - a [boolean](/blocks/logic/boolean) indicating whether or not the @boardname@ should accept connections.
|
||||
|
||||
## Encoding
|
||||
|
||||
The bytes of ``namespace`` and ``instance`` are encoded to generate the 10 bytes UID namespace and 6 bytes UID instance.
|
||||
|
||||
```
|
||||
UID namespace: [0, ..., namespace]
|
||||
UID instance: [0, ..., instance]
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
[stop-advertising](/reference/bluetooth/stop-advertising), [advertise-uid-buffer](/reference/bluetooth/advertise-uid-buffer)
|
||||
|
||||
```package
|
||||
bluetooth
|
||||
```
|
42
docs/reference/bluetooth/advertise-url.md
Normal file
42
docs/reference/bluetooth/advertise-url.md
Normal file
@ -0,0 +1,42 @@
|
||||
# Avertise Url
|
||||
|
||||
Advertises a URL via the Eddystone protocol over Bluetooth.
|
||||
|
||||
## ~hint
|
||||
|
||||
### Eddystone
|
||||
|
||||
Bluetooth beacons are used to indicate proximity to a place or object of interest.
|
||||
Beacons use Bluetooth advertising to broadcast a small amount of data,
|
||||
which can be received and acted upon by anyone in range with a suitable device and software, typically a smartphone and application.
|
||||
|
||||
There are various beacon message formats, which define the way Bluetooth advertising packets are used as containers for beacon data.
|
||||
iBeacon is Apple's beacon message format. Eddystone comes from Google.
|
||||
|
||||
Read more at https://lancaster-university.github.io/microbit-docs/ble/eddystone/ .
|
||||
|
||||
## ~
|
||||
|
||||
```sig
|
||||
bluetooth.advertiseUrl("https://pxt.microbit.org/", 7, true);
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``url`` - a [string](/reference/types/string) containing the URL to broadcast, at most 17 characters long, excluding the protocol (eg: ``https://``) which gets encoded as 1 byte.
|
||||
* ``power`` - a [number](/reference/types/number) representing the power level between 0 (short) and 7 (maximum range).
|
||||
* ``connectable`` - a [boolean](/blocks/logic/boolean) indicating whether or not the @boardname@ should accept connections.
|
||||
|
||||
### Example: Broadcast a secret code
|
||||
|
||||
```blocks
|
||||
bluetooth.advertiseUrl("https://pxt.io?secret=42", 7, true);
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
[stop-advertising](/reference/bluetooth/stop-advertising), [advertise-uid](/reference/bluetooth/advertise-uid)
|
||||
|
||||
```package
|
||||
bluetooth
|
||||
```
|
26
docs/reference/bluetooth/set-transmit-power.md
Normal file
26
docs/reference/bluetooth/set-transmit-power.md
Normal file
@ -0,0 +1,26 @@
|
||||
# Bluetooth Set Transmit Power
|
||||
|
||||
### ~hint
|
||||

|
||||
|
||||
For another device like a smartphone to use any of the Bluetooth "services" which the @boardname@ has, it must first be [paired with the @boardname@](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the @boardname@ and exchange data relating to many of the @boardname@'s features.
|
||||
|
||||
### ~
|
||||
|
||||
Change the output power level of the transmitter to the given value.
|
||||
|
||||
```sig
|
||||
bluetooth.setTransmitPower(7);
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* `power`: a [number](/reference/types/number) in the range ``0..7``, where ``0`` is the lowest power and ``7`` is the highest.
|
||||
|
||||
### See also
|
||||
|
||||
[About Bluetooth](/reference/bluetooth/about-bluetooth), [@boardname@ Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [@boardname@ Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [Bluetooth on @boardname@ resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html), [Bluetooth SIG](https://www.bluetooth.com)
|
||||
|
||||
```package
|
||||
bluetooth
|
||||
```
|
38
docs/reference/bluetooth/stop-advertising.md
Normal file
38
docs/reference/bluetooth/stop-advertising.md
Normal file
@ -0,0 +1,38 @@
|
||||
# Stop Advertising
|
||||
|
||||
Stops advertising URL via the Eddystone protocol over Bluetooth.
|
||||
|
||||
## ~hint
|
||||
|
||||
### Eddystone
|
||||
|
||||
Bluetooth beacons are used to indicate proximity to a place or object of interest.
|
||||
Beacons use Bluetooth advertising to broadcast a small amount of data,
|
||||
which can be received and acted upon by anyone in range with a suitable device and software, typically a smartphone and application.
|
||||
|
||||
There are various beacon message formats, which define the way Bluetooth advertising packets are used as containers for beacon data.
|
||||
iBeacon is Apple's beacon message format. Eddystone comes from Google.
|
||||
|
||||
Read more at https://lancaster-university.github.io/microbit-docs/ble/eddystone/ .
|
||||
|
||||
## ~
|
||||
|
||||
```sig
|
||||
bluetooth.stopAdvertising();
|
||||
```
|
||||
|
||||
### Example: stop advertising on button pressed
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
bluetooth.stopAdvertising();
|
||||
})
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
[advertise-url](/reference/bluetooth/advertise-url)
|
||||
|
||||
```package
|
||||
bluetooth
|
||||
```
|
29
docs/reference/music/begin-melody.md
Normal file
29
docs/reference/music/begin-melody.md
Normal file
@ -0,0 +1,29 @@
|
||||
# Begin Melody
|
||||
|
||||
Begin playing a musical melody through pin ``P0`` of the @boardname@.
|
||||
|
||||
## Simulator
|
||||
|
||||
This function only works on the @boardname@ and in some browsers.
|
||||
|
||||
```sig
|
||||
music.beginMelody(music.builtInMelody(Melodies.Entertainer), MelodyOptions.Once)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``melody`` is the array representation of a melody you wish to play
|
||||
|
||||
## Example
|
||||
|
||||
This example plays the ``Entertainer`` built-in melody.
|
||||
|
||||
```blocks
|
||||
music.beginMelody(music.builtInMelody(Melodies.Entertainer), MelodyOptions.Once)
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[play tone](/reference/music/play-tone), [rest](/reference/music/rest), [ring tone](/reference/music/ring-tone) , [tempo](/reference/music/tempo), [set tempo](/reference/music/set-tempo),
|
||||
[change tempo by](/reference/music/change-tempo-by)
|
||||
|
@ -25,6 +25,15 @@ let freq = music.noteFrequency(Note.C)
|
||||
music.playTone(freq, 1000)
|
||||
```
|
||||
|
||||
|
||||
### Using other pins
|
||||
|
||||
Use [analogSetPitchPin](/reference/pins/analog-set-pitch-pin) to change that pin used to generate music.
|
||||
|
||||
```blocks
|
||||
pins.analogSetPitchPin(AnalogPin.P1);
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[rest](/reference/music/rest), [ring tone](/reference/music/ring-tone) , [tempo](/reference/music/tempo), [set tempo](/reference/music/set-tempo),
|
||||
|
@ -32,6 +32,14 @@ basic.forever(() => {
|
||||
})
|
||||
```
|
||||
|
||||
### Using other pins
|
||||
|
||||
Use [analogSetPitchPin](/reference/pins/analog-set-pitch-pin) to change that pin used to generate music.
|
||||
|
||||
```blocks
|
||||
pins.analogSetPitchPin(AnalogPin.P1);
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[rest](/reference/music/rest), [play tone](/reference/music/play-tone),
|
||||
|
@ -1,6 +1,7 @@
|
||||
# Analog Pitch
|
||||
|
||||
Emits a Pulse With Modulation (PWM) signal to the current pitch [pin](/device/pins). Use [analog set pitch pin](/reference/pins/analog-set-pitch-pin) to set the current pitch pin.
|
||||
Emits a Pulse With Modulation (PWM) signal to the pin ``P0``.
|
||||
Use [analog set pitch pin](/reference/pins/analog-set-pitch-pin) to set the current pitch pin.
|
||||
|
||||
```sig
|
||||
pins.analogPitch(440, 300)
|
||||
@ -17,6 +18,7 @@ pins.analogPitch(440, 300)
|
||||
pins.analogSetPitchPin("P0")
|
||||
let frequency1 = 440
|
||||
let duration = 1000
|
||||
pins.analogSetPitchPin(AnalogPin.P1);
|
||||
pins.analogPitch(frequency1, duration)
|
||||
```
|
||||
|
||||
|
30
docs/reference/pins/set-events.md
Normal file
30
docs/reference/pins/set-events.md
Normal file
@ -0,0 +1,30 @@
|
||||
# Set Events
|
||||
|
||||
Configure the type of events emitted by a given pin.
|
||||
|
||||
```sig
|
||||
pins.setEvents(DigitalPin.P0, PinEventType.Edge);
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``name``: The @boardname@ hardware pin to configure (``P0`` through ``P20``)
|
||||
* ``type``: The type of events this pin should emit
|
||||
|
||||
### Example
|
||||
|
||||
The following example configures pin ``P0`` and then
|
||||
subscribes to the rise and fall events.
|
||||
|
||||
```blocks
|
||||
control.onEvent(control.eventSourceId(EventBusSource.MICROBIT_ID_IO_P0), control.eventValueId(EventBusValue.MICROBIT_PIN_EVT_RISE), () => {
|
||||
basic.showString("Rise")
|
||||
})
|
||||
control.onEvent(control.eventSourceId(EventBusSource.MICROBIT_ID_IO_P0), control.eventValueId(EventBusValue.MICROBIT_PIN_EVT_FALL), () => {
|
||||
basic.showString("Fall")
|
||||
})
|
||||
pins.setEvents(DigitalPin.P0, PinEventType.Edge)
|
||||
```
|
||||
|
||||
**This is an advanced API.** For more information, see the
|
||||
[@boardname@ runtime messageBus documentation](https://lancaster-university.github.io/microbit-docs/ubit/messageBus/)
|
@ -21,7 +21,7 @@ To add or remove the parts of the packet from the block, try clicking the blue g
|
||||
* `receivedString` - The [string](/reference/types/string) that was sent in this packet or the empty string if this packet did not contain a string. See [send string](/reference/radio/send-string) and [send value](/reference/radio/send-value)
|
||||
* `time` - The system time of the @boardname@ that sent this packet at the time the packet was sent.
|
||||
* `serial` - The serial number of the @boardname@ that sent this packet or `0` if the @boardname@ did not include its serial number.
|
||||
* `signal` - How strong the radio signal is from `255` (weak) to `0` (strong).
|
||||
* `signal` - How strong the radio signal is from `-128` (weak) to `-42` (strong).
|
||||
|
||||
### Example
|
||||
|
||||
@ -39,6 +39,23 @@ radio.onDataPacketReceived(({ receivedNumber }) => {
|
||||
})
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
This program uses the signal strength from received packets to graph the
|
||||
approximate distance between two @boardname@s.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
radio.sendNumber(0)
|
||||
})
|
||||
radio.onDataPacketReceived(({ signal, receivedNumber }) => {
|
||||
led.plotBarGraph(
|
||||
Math.abs(signal + 42),
|
||||
128 - 42
|
||||
)
|
||||
})
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[send number](/reference/radio/send-number),
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
> Note: This API has been deprecated! Use [on data packet received](/reference/radio/on-data-packet-received) instead.
|
||||
|
||||
Find how strong the ``radio`` signal is, from `255` to `0`.
|
||||
(`255` means a weak signal and `0` means a strong one.)
|
||||
Find how strong the ``radio`` signal is, from `-128` to `-42`.
|
||||
(`-128` means a weak signal and `-42` means a strong one.)
|
||||
|
||||
The @boardname@ finds the signal strength by checking how strong it was
|
||||
the last time it ran the
|
||||
@ -16,7 +16,7 @@ radio.receivedSignalStrength();
|
||||
|
||||
### Returns
|
||||
|
||||
* a [number](/reference/types/number) between `255` and `0` that means
|
||||
* a [number](/reference/types/number) between `-128` and `-42` that means
|
||||
how strong the signal is.
|
||||
|
||||
### Simulator
|
||||
|
@ -7,8 +7,11 @@ serial.writeLine("");
|
||||
serial.writeNumber(0);
|
||||
serial.writeValue("x", 0);
|
||||
serial.writeString("");
|
||||
serial.readUntil(",");
|
||||
serial.readLine();
|
||||
serial.readString();
|
||||
serial.redirect(SerialPin.P0, SerialPin.P0, BaudRate.BaudRate115200);
|
||||
serial.onDataReceived(",", () => {})
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
29
docs/reference/serial/on-data-received.md
Normal file
29
docs/reference/serial/on-data-received.md
Normal file
@ -0,0 +1,29 @@
|
||||
# Serial On Data Received
|
||||
|
||||
Registers an event to be fired when one of the delimiter is matched.
|
||||
|
||||
|
||||
```sig
|
||||
serial.onDataReceived(",", () => {})
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* `delimiters` is a [string](/reference/types/string) containing any of the character to match
|
||||
|
||||
### Example
|
||||
|
||||
Read values separated by `,`:
|
||||
|
||||
```blocks
|
||||
serial.onDataReceived(serial.delimiters(Delimiters.Comma), () => {
|
||||
basic.showString(serial.readUntil(serial.delimiters(Delimiters.Comma)))
|
||||
})
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[serial](/device/serial),
|
||||
[serial write line](/reference/serial/write-line),
|
||||
[serial write value](/reference/serial/write-value)
|
||||
|
27
docs/reference/serial/read-string.md
Normal file
27
docs/reference/serial/read-string.md
Normal file
@ -0,0 +1,27 @@
|
||||
# Serial Read String
|
||||
|
||||
Read the buffered serial data as a string
|
||||
|
||||
```sig
|
||||
serial.readString();
|
||||
```
|
||||
|
||||
### Returns
|
||||
|
||||
* a [string](/reference/types/string) containing input from the serial port. Empty if no data available.
|
||||
|
||||
### Example
|
||||
|
||||
The following program scrolls text on the screen as it arrives from serial.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showString(serial.readString());
|
||||
});
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[serial](/device/serial),
|
||||
[serial write line](/reference/serial/write-line),
|
||||
[serial write value](/reference/serial/write-value)
|
28
docs/reference/serial/read-until.md
Normal file
28
docs/reference/serial/read-until.md
Normal file
@ -0,0 +1,28 @@
|
||||
# Serial Read Until
|
||||
|
||||
Read a text from the serial port until a delimiter is found.
|
||||
|
||||
```sig
|
||||
serial.readUntil(",");
|
||||
```
|
||||
|
||||
### Returns
|
||||
|
||||
* a [string](/reference/types/string) containing input from the serial port, such as a response typed by a user
|
||||
|
||||
### Example
|
||||
|
||||
The following example reads strings separated by commands (``,``).
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let answer = serial.readUntil(",");
|
||||
serial.writeLine(answer);
|
||||
});
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[serial](/device/serial),
|
||||
[serial write line](/reference/serial/write-line),
|
||||
[serial write value](/reference/serial/write-value)
|
BIN
docs/static/Microsoft-logo_rgb_c-gray-square.png
vendored
Normal file
BIN
docs/static/Microsoft-logo_rgb_c-gray-square.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
docs/static/Microsoft-logo_rgb_c-white.png
vendored
Normal file
BIN
docs/static/Microsoft-logo_rgb_c-white.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
61
docs/static/avatar.svg
vendored
Normal file
61
docs/static/avatar.svg
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
role="img"
|
||||
aria-labelledby="title desc"
|
||||
xml:space="preserve"
|
||||
enable-background="new 0 0 280 32.755"
|
||||
height="52.672001"
|
||||
width="52.672001"
|
||||
version="1.1"
|
||||
id="svg2"
|
||||
inkscape:version="0.91 r13725"
|
||||
sodipodi:docname="logo.square.black.svg"><sodipodi:namedview
|
||||
pagecolor="#ff00ff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1536"
|
||||
inkscape:window-height="801"
|
||||
id="namedview14"
|
||||
showgrid="false"
|
||||
inkscape:zoom="2.0836233"
|
||||
inkscape:cx="83.390493"
|
||||
inkscape:cy="16.071144"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg2" /><rect
|
||||
id="backgroundrect"
|
||||
width="195.47368"
|
||||
height="34.210526"
|
||||
x="0"
|
||||
y="18.461473"
|
||||
class=""
|
||||
style="fill:none;stroke:none" /><title
|
||||
id="title"
|
||||
lang="en-GB">BBC micro:bit</title><desc
|
||||
id="desc"
|
||||
lang="en-GB">BBC micro:bit logo</desc><metadata
|
||||
id="metadata37"><rdf:rdf><cc:work
|
||||
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:work></rdf:rdf><rdf:RDF><cc:Work
|
||||
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title>BBC micro:bit</dc:title></cc:Work></rdf:RDF></metadata><defs
|
||||
id="defs35" /><path
|
||||
inkscape:connector-curvature="0"
|
||||
class=""
|
||||
d="m 37.363,29.377 c -1.677,0 -3.035,-1.364 -3.035,-3.042 0,-1.678 1.357,-3.038 3.035,-3.038 1.684,0 3.039,1.36 3.039,3.038 0,1.678 -1.355,3.042 -3.039,3.042 M 15.052,23.3 c -1.677,0 -3.042,1.357 -3.042,3.035 0,1.678 1.363,3.042 3.042,3.042 1.674,0 3.036,-1.364 3.036,-3.042 0,-1.678 -1.363,-3.035 -3.036,-3.035 m -0.003,-5.99 22.576,0 c 4.979,0 9.027,4.047 9.027,9.027 0,4.979 -4.049,9.031 -9.027,9.031 l -22.576,0 c -4.977,0 -9.0299993,-4.053 -9.0299993,-9.031 C 6.0180007,21.357 10.072,17.31 15.049,17.31 m 22.576,24.076 c 8.299,0 15.047,-6.75 15.047,-15.049 0,-8.299 -6.748,-15.051 -15.047,-15.051 l -22.576,0 C 6.7500007,11.286 6.9250488e-7,18.038 6.9250488e-7,26.337 6.9250488e-7,34.636 6.7500007,41.386 15.049,41.386 l 22.576,0"
|
||||
id="path21"
|
||||
style="fill:#000000"
|
||||
sodipodi:nodetypes="csssccsssccsssscccsssssc" /></svg>
|
After Width: | Height: | Size: 2.8 KiB |
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user