Compare commits

..

No commits in common. "master" and "v3" have entirely different histories.
master ... v3

280 changed files with 8921 additions and 20076 deletions

8
.github/lock.yml vendored
View File

@ -30,7 +30,13 @@ lockLabel: false
# Comment to post before locking. Set to `false` to disable
lockComment: false
lockComment: >
This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

View File

@ -1,51 +0,0 @@
name: "Code scanning - action"
on:
push:
pull_request:
schedule:
- cron: '0 19 * * 0'
jobs:
CodeQL-Build:
# CodeQL runs on ubuntu-latest and windows-latest
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2
# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: javascript
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

View File

@ -0,0 +1,12 @@
name: Compress images
on: pull_request
jobs:
build:
name: calibreapp/image-actions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: calibreapp/image-actions
uses: calibreapp/image-actions@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -1,31 +0,0 @@
name: pxt-buildpr
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install
run: |
sudo apt-get install xvfb
sudo npm install -g pxt
npm install
- name: pxt ci
run: |
pxt ci
env:
CHROME_BIN: chromium-browser
DISPLAY: :99.0
CI: true

View File

@ -1,39 +0,0 @@
name: pxt-buildpush
on:
push:
# main/master has its own build that includes the crowdin key
branches-ignore:
- 'main'
- 'master'
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install
run: |
sudo apt-get install xvfb
sudo npm install -g pxt
npm install
- name: pxt ci
run: |
pxt ci
env:
PXT_ACCESS_TOKEN: ${{ secrets.PXT_ACCESS_TOKEN }}
PXT_RELEASE_REPO: ${{ secrets.PXT_RELEASE_REPO }}
NPM_ACCESS_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
CHROME_BIN: chromium-browser
DISPLAY: :99.0
CI: true

View File

@ -1,10 +1,9 @@
name: pxt-buildmain
name: pxt-buildtarget
on:
push:
branches:
- 'master'
- 'main'
branches:
- master
create:
jobs:
@ -14,7 +13,7 @@ jobs:
strategy:
matrix:
node-version: [18.x]
node-version: [8.x]
steps:
- uses: actions/checkout@v1

View File

@ -11,12 +11,9 @@ jobs:
strategy:
matrix:
node-version: [8.x]
branch: [stable3.0]
steps:
- uses: actions/checkout@v2
with:
ref: ${{ matrix.branch }}
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
@ -48,5 +45,5 @@ jobs:
uses: actions/upload-artifact@v2
if: ${{ always() }}
with:
name: logs-${{ matrix.branch }}
name: logs
path: temp/ghpkgs/*.txt

27
.travis.yml Normal file
View File

@ -0,0 +1,27 @@
language: node_js
os: linux
dist: trusty
node_js:
- "8.9.4"
before_install:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
script:
- "node node_modules/pxt-core/built/pxt.js travis"
# - "(cd libs/lang-test0; node ../../node_modules/pxt-core/built/pxt.js run)"
# - "(cd libs/lang-test1; node ../../node_modules/pxt-core/built/pxt.js run)"
# - "(cd libs/lang-test0; node ../../node_modules/pxt-core/built/pxt.js test)"
# - "(cd libs/lang-test1; node ../../node_modules/pxt-core/built/pxt.js test)"
# - "node node_modules/pxt-core/built/pxt.js testdir tests"
# - "(cd libs/hello; node ../../node_modules/pxt-core/built/pxt.js testconv http://az851932.vo.msecnd.net/files/td-converter-tests-v1.json)"
sudo: false
notifications:
email:
- touchdevelop-build@microsoft.com
cache:
directories:
- node_modules
- built/cache
- libs/hello/built/cache

View File

@ -1,5 +1,6 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.autoSave": "afterDelay",
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/built/**": true,

19
.vscode/tasks.json vendored
View File

@ -1,19 +1,20 @@
{
"version": "2.0.0",
"version": "0.1.0",
// Task runner is jake
"command": "pxt",
// Need to be executed in shell / cmd
"isShellCommand": true,
"showOutput": "always",
"tasks": [
{
"label": "serve",
"type": "shell",
"command": "pxt",
"args": [
"serve"
],
// TS build command is local.
"taskName": "serve",
// Make this the default build command.
"isBuildCommand": true,
// Use the redefined Typescript output problem matcher.
"problemMatcher": [
"$tsc"
],
"group": "build"
]
}
]
}

View File

@ -1,4 +1,4 @@
# calliope target for PXT
# micro:bit target for PXT

View File

@ -1,41 +0,0 @@
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.7 BLOCK -->
## Security
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below.
## Reporting Security Issues
**Please do not report security vulnerabilities through public GitHub issues.**
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue
This information will help us triage your report more quickly.
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs.
## Preferred Languages
We prefer all communications to be in English.
## Policy
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd).
<!-- END MICROSOFT SECURITY.MD BLOCK -->

13
calliope.code-workspace Normal file
View File

@ -0,0 +1,13 @@
{
"folders": [
{
"path": "../pxt"
},
{
"path": "../pxt-common-packages"
},
{
"path": "."
}
]
}

View File

@ -1,131 +0,0 @@
/// <reference path="../node_modules/pxt-core/built/pxtcompiler.d.ts"/>
namespace ts.pxtc.extension {
pxtc.compilerHooks.postBinary = (program: ts.Program, opts: CompileOptions, res: CompileResult) => {
if (!opts.target.isNative)
return
const mbdal = res.outfiles["mbdal-binary.hex"]
const mbcodal = res.outfiles["mbcodal-binary.hex"]
if (!mbdal || !mbcodal)
return
let outp = ""
wrapHex(mbdal, 0x00, [0x99, 0x01, 0xc0, 0xde])
wrapHex(mbcodal, 0x0D, [0x99, 0x03, 0xc0, 0xde], true)
outp += ":00000001FF\n"
res.outfiles["binary.hex"] = outp
function hex2str(bytes: number[]) {
return ts.pxtc.hexfile.hexBytes([bytes.length - 3].concat(bytes)) + "\n"
}
function paddingString(len: number) {
let r = ""
const len0 = len
while (len >= 44) {
r += hex2str([0x00, 0x00, 0x0C,
0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42])
len -= 44
}
if (len >= 12) {
const numBytes = (len - 11) >> 1
const bytes = [0x00, 0x00, 0x0C]
for (let i = 0; i < numBytes; ++i) bytes.push(0x42)
const add = hex2str(bytes)
r += add
len -= add.length
}
while (len--)
r += "\n"
U.assert(r.length == len0)
return r
}
function addBlock(blk: string) {
const leftoff = blk.length & 511
outp += blk + paddingString(512 - leftoff)
}
function wrapHex(inpHex: string, dataType: number, deviceType: number[], keepSrc = false) {
let blk =
hex2str([0x00, 0x00, 0x04, 0x00, 0x00])
+ hex2str([0x00, 0x00, 0x0A].concat(deviceType))
let upperAddr = 0
const lines = inpHex.split(/\r?\n/)
for (let i = 0; i < lines.length; ++i) {
const line = lines[i]
if (!line)
continue
const parsed = ts.pxtc.hexfile.parseHexRecord(line)
switch (parsed.type) {
case 0x00:
/*
const parsed2 = parsed.len <= 16 && lines[i + 1] ?
ts.pxtc.hexfile.parseHexRecord(lines[i + 1])
: null
// if this and next line can fit in 32 bytes, concat them
if (parsed2 && parsed2.type == 0x00 &&
parsed2.addr == parsed.addr + parsed.len &&
parsed.len + parsed2.len <= 32) {
parsed.data = parsed.data.concat(parsed2.data)
parsed.len += parsed2.len
i++
}
*/
addData([parsed.addr >> 8, parsed.addr & 0xff, dataType]
.concat(parsed.data))
break
case 0x01:
flush()
if (keepSrc) break
else return
case 0x04:
const newUpper = ((parsed.data[0] << 8) | parsed.data[1]) << 16
if (upperAddr != newUpper) {
upperAddr = newUpper
addData([0, 0, 0x04, parsed.data[0], parsed.data[1]])
}
break
case 0x03:
case 0x05:
// ignore
break
case 0x0E:
// src record
addData([parsed.addr >> 8, parsed.addr & 0xff, 0x0E]
.concat(parsed.data))
break
default:
U.oops(`unknown hex record type: ${line}`)
break
}
}
flush()
function addData(bytes: number[]) {
const newData = hex2str(bytes)
blk += newData
}
function flush() {
if (blk)
addBlock(blk)
blk = ""
}
}
}
}

View File

@ -1,23 +0,0 @@
{
"compilerOptions": {
"target": "es2017",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"declaration": true,
"moduleResolution": "node",
"isolatedModules": false,
"out": "../built/compiler.js",
"rootDir": ".",
"newLine": "LF",
"sourceMap": false,
"typeRoots": ["../node_modules/@types"],
"lib": [
"dom",
"dom.iterable",
"scripthost",
"es2017",
"ES2018.Promise"
]
}
}

View File

@ -1,2 +0,0 @@
Micro:bit and micro:bit logo are trademarks and/ or copyrights of the Micro:bit
Educational Foundation. &copy; Micro:bit Educational Foundation. All rights reserved.

View File

@ -26,12 +26,12 @@ The Calliope mini is packaged with sensors, radio and other goodies. Learn about
You can program the Calliope mini using [Blocks](/blocks) or [JavaScript](/javascript) in your web browser via the [Calliope mini APIs](/reference):
```block
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
basic.showString("Hi!");
})
```
```typescript
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
basic.showString("Hi!");
})
```
@ -54,7 +54,7 @@ The simulator has support for the LED screen, buttons, as well as compass, accel
basic.forever(() => {
basic.showString("Hi!");
})
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
led.stopAnimation();
basic.showLeds(`
. . . . .
@ -63,7 +63,7 @@ input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
# . . . #
. # # # .`);
});
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.B, () => {
led.stopAnimation();
basic.showLeds(`
. # . # .
@ -78,13 +78,6 @@ input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Down), () => {
We have tons of [projects](/projects), [examples](/examples) and [courses](/courses) to get your started!
## C++ Runtime
The [C++ micro:bit runtime](http://lancaster-university.github.io/microbit-docs/), created at [Lancaster University](http://www.lancaster.ac.uk/), provides access to the hardware functions of the micro:bit,
as well as a set of helper functions (such as displaying a number/image/string on the LED screen).
The [micro:bit library](/reference) mirrors the functions of the C++ library.
When code is compiled to ARM machine code, the calls to JavaScript micro:bit functions are replaced with calls to the corresponding C++ functions.
## [Command Line Tools](/cli)

View File

@ -17,7 +17,7 @@ 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
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
let x = randint(0, 5)
if(x < 5) {
basic.showString("low");

View File

@ -7,7 +7,7 @@
If the [light level](/reference/input/light-level) is `< 100`, this code sets the brightness to `255` when the button A is pressed:
```blocks
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
if(input.lightLevel()<100){
led.setBrightness(255);
}

View File

@ -7,7 +7,7 @@
This program will show the numbers 0, 1, 2, 3, and 4 one after another on the LED screen.
```blocks
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
for(let i = 0; i < 5; ++i) {
basic.showNumber(i)
}

View File

@ -7,7 +7,7 @@
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
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
let index = 4;
while(index >= 0) {
led.plot(index, index);

View File

@ -5,7 +5,7 @@
In this example, ``on start`` sets a dimmer brightness on the screen and the button handler shows a string.
```blocks
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
basic.showString("Hello!")
})
led.setBrightness(50)

View File

@ -59,7 +59,7 @@ A counter is a great example:
```blocks
let counter = 0;
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
counter = counter + 1;
basic.showNumber(counter);
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 220 KiB

View File

@ -1,27 +0,0 @@
# Projects
Here are some cool tutorials to get you started with your @boardname@!
## Basic
```codecard
[
{
"name": "Calliope mini 2.x",
"url":"_f7ACuxgaocvr",
"description": "The Calliope mini 2.0 and newer has a larger memory than the previous versions. If you use this template for your project, you can make the most of all the features on your Calliope mini!",
"imageUrl": "/calliope/templates/32KB.png",
"largeImageUrl": "/calliope/templates/32KB_L.png",
"cardType": "sharedExample",
"buttonLabel": "New project"
},{
"name": "Calliope mini 1.x",
"url":"_7YbU6iMhoTdR",
"description": "This template is designed for all Calliope mini, but especially for those up to version 1.3. If you have such a Calliope mini or an earlier version, you can start directly with this template.",
"imageUrl": "/calliope/templates/16KB.png",
"largeImageUrl": "/calliope/templates/16KB_L.png",
"cardType": "sharedExample",
"buttonLabel": "New project"
}
]
```

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

View File

@ -38,7 +38,7 @@ Each time the crocodile clip is firmly connected and disconnected from pin `P0`,
the @boardname@ will return a random Number between 0 and the parameter limit.
```blocks
input.onPinTouchEvent(TouchPin.P0, input.buttonEventValue(ButtonEvent.Down), () => {
input.onPinPressed(TouchPin.P0, () => {
basic.showNumber(randint(0, 10))
})
```

View File

@ -63,7 +63,7 @@ for (let i = 0; i < values.length; i++) {
The ``||led:plot bar graph||`` also sends the number value it's plotting to the console. You can see the output in the Data Viewer. It charts the values and they appear as individual numbers in console.
```blocks
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Click), () => {
input.onButtonPressed(Button.B, () => {
for (let i = 0; i < 25; i++) {
if (i % 2 > 0) {
led.plotBarGraph(0, 0)

View File

@ -51,7 +51,7 @@ The first job of the scheduler is to allow multiple *subprograms* to be queued u
```typescript
let count = 0
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
count++;
})
@ -74,7 +74,7 @@ The second statement informs the scheduler that on each and every event of the *
// statement 1
let count = 0
// statement 2
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
count++;
})
```
@ -85,7 +85,7 @@ The third statement queues a `forever` loop for later execution by the scheduler
// statement 1
let count = 0
// statement 2
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
count++;
})
// statement 3
@ -157,7 +157,7 @@ As a result, you can easily add a new capability to the micro:bit by just adding
```typescript
let count = 0
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
count = count + 1
})
@ -165,7 +165,7 @@ basic.forever(() => {
basic.showNumber(count)
})
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.B, () => {
count = 0
})
```

View File

@ -6,7 +6,7 @@ The code below shows a simple script that sends a line when the BBC micro:bit st
```blocks
serial.writeLine("started...")
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
serial.writeLine("A pressed")
})
```

View File

@ -4,19 +4,19 @@ The JavaScript simulator allows you to test and execute most BBC micro:bit progr
It allows you to emulate sensor data or user interactions.
```sim
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
input.onButtonPressed(Button.A, () => {
basic.showString("A");
});
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Click), () => {
input.onButtonPressed(Button.B, () => {
basic.showString("B");
});
input.onPinTouchEvent(TouchPin.P0, input.buttonEventValue(ButtonEvent.Click), () => {
input.onPinPressed(TouchPin.P0, () => {
basic.showString("0");
});
input.onPinTouchEvent(TouchPin.P1, input.buttonEventValue(ButtonEvent.Click), () => {
input.onPinPressed(TouchPin.P1, () => {
basic.showString("1");
});
input.onPinTouchEvent(TouchPin.P2, input.buttonEventValue(ButtonEvent.Click), () => {
input.onPinPressed(TouchPin.P2, () => {
basic.showString("2");
});
input.temperature()

View File

@ -22,13 +22,13 @@ Here's a program that simulates cell life in the LED matrix. Use button ``A`` fo
let lifeChart: Image = null
//Use button A for the next iteration of game of life
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
input.onButtonPressed(Button.A, () => {
gameOfLife();
show();
})
//Use button B for reseting to random initial seed state
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Click), () => {
input.onButtonPressed(Button.B, () => {
reset();
show();
})

View File

@ -1,21 +0,0 @@
# Hero Banner
Here are some cool activities to get you started with your @boardname@!
## Intro Content
### ~ codecard
* name: CalliopEO
* description: CALLIOPEO Taking the Calliope mini to the ISS.
* imageUrl: /calliope/02_Hero_CalliopEO.png
* url: https://calliope.cc/calliopeo
* buttonLabel: Explore!
* cardType: link
---
* name: The 5x5 LED matrix
* description: KIDS LAB play, learn and hack!
* imageUrl: /calliope/03_Hero_KidsLab.png
* url: https://calliope.cc/programmieren/kidslab
* buttonLabel: Explore!
* cardType: link
### ~

View File

@ -1,3 +1,3 @@
{
"appref": "v4.0.29"
"appref": "v3.0.33"
}

View File

@ -2,12 +2,6 @@
```codecard
[
{
"name": "New Project (iPad)",
"url": "/calliope/templates",
"imageUrl": "/calliope/templates/32KB.png",
"largeImageUrl": "/calliope/templates/32KB_L.png"
},
{
"name": "First Steps",
"url": "/calliope/firststeps",
@ -29,7 +23,6 @@
## See Also
[New Project (iPad)](/calliope/templates),
[First Steps](/calliope/firststeps),
[Tutorials](/calliope/tutorials),
[Calliope Links](/calliope/links)

View File

@ -1,8 +1,5 @@
# Projects
* [New Project (iPad)](/calliope/templates)
* [Calliope mini 2.x](_f7ACuxgaocvr)
* [Calliope mini 1.x](_7YbU6iMhoTdR)
* [First Steps](/calliope/firststeps)
* [Get Ready](/calliope/firststeps/firstSteps)
* [The 5x5 LED matrix](/calliope/firststeps/5x5LED)

View File

@ -11,7 +11,7 @@ Let's create a coin flipping program to simulate a real coin toss. We'll use ico
Get an ``||input:on button A pressed||`` block from the ``||input:Input||`` drawer in the toolbox. We'll put our coin flipping code in here.
```blocks
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
input.onButtonPressed(Button.A, () => {
})
```
@ -22,7 +22,7 @@ Grab an ``||logic:if else||`` block and set it inside ``||input:on button A pres
The ``||Math:pick random true or false||`` returns a random ``true`` or ``false`` value which we use to determine a ``heads`` or ``tails`` result for a coin toss.
```blocks
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
input.onButtonPressed(Button.A, () => {
if (Math.randomBoolean()) {
} else {
}
@ -34,7 +34,7 @@ input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
Now, put a ``||basic:show icon||`` block inside both the ``||logic:if||`` and the ``||logic:else||``. Pick images to mean ``heads`` and ``tails``.
```blocks
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
input.onButtonPressed(Button.A, () => {
if (Math.randomBoolean()) {
basic.showIcon(IconNames.Skull)
} else {
@ -52,7 +52,7 @@ Press button **A** in the simulator to try the coin toss code.
You can animate the coin toss to add the feeling of suspense. Place different ``||basic:show icon||`` blocks before the ``||logic:if||`` to show that the coin is flipping.
```blocks
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
input.onButtonPressed(Button.A, () => {
basic.showIcon(IconNames.Diamond)
basic.showIcon(IconNames.SmallDiamond)
basic.showIcon(IconNames.Diamond)

View File

@ -11,7 +11,7 @@ Make a love meter, how sweet! The @boardname@ is feeling the love, then sometime
Let's build a **LOVE METER** machine. Place an ``||input:on pin pressed||`` block to run code when pin **0** is pressed. Use ``P0`` from the list of pin inputs.
```blocks
input.onPinTouchEvent(TouchPin.P0, input.buttonEventValue(ButtonEvent.Down), () => {
input.onPinPressed(TouchPin.P0, () => {
});
```
@ -20,7 +20,7 @@ input.onPinTouchEvent(TouchPin.P0, input.buttonEventValue(ButtonEvent.Down), ()
Using ``||basic:show number||`` and ``||Math:pick random||`` blocks, show a random number from `0` to `100` when pin **0** is pressed.
```blocks
input.onPinTouchEvent(TouchPin.P0, input.buttonEventValue(ButtonEvent.Down), () => {
input.onPinPressed(TouchPin.P0, () => {
basic.showNumber(randint(0, 100));
});
```
@ -34,7 +34,7 @@ Show ``"LOVE METER"`` on the screen when the @boardname@ starts.
```blocks
basic.showString("LOVE METER");
input.onPinTouchEvent(TouchPin.P0, input.buttonEventValue(ButtonEvent.Down), () => {
input.onPinPressed(TouchPin.P0, () => {
basic.showNumber(randint(0, 100));
});
```

View File

@ -12,7 +12,7 @@ Use ``||input:on button pressed||`` to send a text message over radio with ``||r
Every @boardname@ nearby will receive this message.
```blocks
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
radio.sendString("Yo");
});
```
@ -41,7 +41,7 @@ radio.onReceivedString(function (receivedString) {
Press button **A** on the simulator, you will notice that a second @boardname@ appears (if your screen is too small, the simulator might decide not to show it). Try pressing **A** again and notice that the "Yo" message gets displayed on the other @boardname@.
```blocks
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
radio.sendString("Yo");
});
radio.onReceivedString(function (receivedString) {

View File

@ -13,7 +13,7 @@ First, let's get your name to display on the screen.
From the ``||input:Input||`` Toolbox drawer, drag an ``||input:on button A pressed||`` block onto the Workspace.
```blocks
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), function () {
input.onButtonPressed(Button.A, function () {
})
```
@ -23,7 +23,7 @@ input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), functio
From the ``||basic:Basic||`` Toolbox drawer drag a ``||basic:show string||`` block into the ``||input:on button A pressed||`` block.
```blocks
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), function () {
input.onButtonPressed(Button.A, function () {
basic.showString("Hello!")
})
```
@ -33,7 +33,7 @@ input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), functio
In the ``||basic:show string||`` block, type your name.
```blocks
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), function () {
input.onButtonPressed(Button.A, function () {
basic.showString("My Name")
})
```
@ -43,7 +43,7 @@ input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), functio
Go to the simulator and test your name badge by pressing button **A**.
```sim
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), function () {
input.onButtonPressed(Button.A, function () {
basic.showString("My Name")
})
```

View File

@ -6,7 +6,7 @@ Tell everyone who you are. Show you name on the LEDs.
![Name scrolling on the LEDs](/calliope/tutorials/02_nametag_animation.gif)
## Step 1
## Step 1 @fullscreen
Place the ``||basic:show string||`` block in the ``||basic:forever||`` block to repeat it. Change the text to your name.
@ -16,12 +16,13 @@ basic.forever(() => {
});
```
## Step 2
## Step 2 @fullscreen
Look at the simulator and make sure it shows your name on the screen.
![Name scrolling on the LEDs](/calliope/tutorials/02_nametag_animation.gif)
## Step 3 @fullscreen
Place more ``||basic:show string||`` blocks to create your own story.
@ -32,6 +33,6 @@ basic.forever(() => {
})
```
## Step 4
## Step 4 @unplugged
If you have a @boardname@ connected, click ``|Download|`` to transfer your code and watch your name scroll!

View File

@ -123,7 +123,7 @@ basic.forever(function () {
**MakeCode blocks for the Robot Unicorn controller**
```blocks
input.onButtonEvent(Button.AB, input.buttonEventValue(ButtonEvent.Down), function () {
input.onButtonPressed(Button.AB, function () {
radio.sendNumber(4)
basic.showLeds(`
# . . . #

View File

@ -83,7 +83,7 @@ Now that we are detecting pulses, we can use a variable to count them too. In th
```blocks
let pulseCount = 0
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), function () {
input.onButtonPressed(Button.A, function () {
basic.showNumber(pulseCount)
pulseCount = 0
})

View File

@ -12,7 +12,7 @@ Code the buttons on the @boardname@ to show that it's happy or sad.
Place a ``||input:on button pressed||`` block to run code when button **A** is pressed.
```blocks
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
input.onButtonPressed(Button.A, () => {
});
```
@ -21,7 +21,7 @@ input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
Place a ``||basic:show leds||`` block inside ``||input:on button pressed||`` to display a smiley on the screen. Press the **A** button in the simulator to see the smiley.
```blocks
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
input.onButtonPressed(Button.A, () => {
basic.showLeds(`
# # . # #
# # . # #
@ -37,7 +37,7 @@ input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
Add ``||input:on button pressed||`` and ``||basic:show leds||`` blocks to display a frowny when button **B** is pressed.
```blocks
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Click), () => {
input.onButtonPressed(Button.B, () => {
basic.showLeds(`
# # . # #
# # . # #
@ -53,7 +53,7 @@ input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Click), () => {
Add a secret mode that happens when **A** and **B** are pressed together. For this case, add multiple ``||basic:show leds||`` blocks to create an animation.
```blocks
input.onButtonEvent(Button.AB, input.buttonEventValue(ButtonEvent.Click), () => {
input.onButtonPressed(Button.AB, () => {
basic.showLeds(`
. . . . .
# . # . .

View File

@ -59,7 +59,7 @@ Use a ``||input:on button pressed||`` block to handle the **A** button. Put in a
```blocks
let sprite = game.createSprite(2, 2)
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), function () {
input.onButtonPressed(Button.A, function () {
if (sprite.get(LedSpriteProperty.X) == 2) {
} else {
}
@ -77,7 +77,7 @@ Finally, pull out an ``||game:add score||`` and a ``||game:game over||`` block t
```blocks
let sprite = game.createSprite(2, 2)
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), function () {
input.onButtonPressed(Button.A, function () {
if (sprite.get(LedSpriteProperty.X) == 2) {
game.addScore(1)
} else {

View File

@ -18,7 +18,7 @@ basic.forever(() => {
});
basic.pause(100);
basic.showIcon(IconNames.ArrowNorth);
basic.showArrow(ArrowNames.North);
```
## See also
@ -27,4 +27,4 @@ basic.showIcon(IconNames.ArrowNorth);
[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)
[showArrow](/reference/basic/show-arrow), [showAnimation](/reference/basic/show-animation)

View File

@ -1,4 +1,4 @@
# forever
# Forever
Keep running part of a program
[in the background](/reference/control/in-background).
@ -8,20 +8,7 @@ basic.forever(() => {
})
```
You can have part of a program continuously by placing it in an **forever** loop. The **forever** loop will _yield_ to the other code in your program though, allowing that code to have time to run when needs to.
### ~ reminder
#### Event-based loops
Both the **forever** loop and the **every** loop are _event-based_ loops where the code inside is run as part of a function. These are different from the [for](/blocks/loops/for) and [while](/blocks/loops/while) loops. Those are loops are part of the programming language and can have [break](/blocks/loops/break) and [continue](/blocks/loops/continue) statements in them.
You can NOT use **break** or **continue** in either a **forever** loop or an **every** loop.
### ~
## Examples
### Example: compass
## Example: compass
The following example constantly checks the
[compass heading](/reference/input/compass-heading)
@ -45,7 +32,7 @@ basic.forever(() => {
})
```
### Example: counter
## Example: counter
The following example keeps showing the [number](/types/number) stored in a global variable.
When you press button `A`, the number gets bigger.
@ -56,7 +43,7 @@ let num = 0
basic.forever(() => {
basic.showNumber(num)
})
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
input.onButtonPressed(Button.A, () => {
num = num + 1
})
```
@ -72,12 +59,12 @@ Try this on your @boardname@:
basic.forever(() => {
basic.showNumber(6789)
})
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
input.onButtonPressed(Button.A, () => {
basic.showNumber(2)
})
```
## See also
[while](/blocks/loops/while), [in background](/reference/control/in-background), [every](/reference/loops/every-interval)
[while](/blocks/loops/while), [on button pressed](/reference/input/on-button-pressed), [in background](/reference/control/in-background)

View File

@ -24,10 +24,6 @@ for (let i = 0; i < 5; i++) {
}
```
## Advanced
If `ms` is `NaN` (not a number), it will default to `20` ms.
## See also
[while](/blocks/loops/while), [running time](/reference/input/running-time), [for](/blocks/loops/for)

View File

@ -0,0 +1,34 @@
# Plot LEDs
Display an [Image](/reference/images/image) on the @boardname@'s [LED screen](/device/screen).
```sig
basic.showLeds(`
. . . . .
. # . # .
. . # . .
# . . . #
. # # # .
`)
```
## Parameters
* leds - a series of LED on/off states that form an image (see steps below)
## Example: smiley
```blocks
basic.showLeds(`
. . . . .
. # . # .
. . # . .
# . . . #
. # # # .
`)
```
## See also
[show animation](/reference/basic/show-animation), [image](/reference/images/image), [show image](/reference/images/show-image), [scroll image](/reference/images/scroll-image)

View File

@ -1 +0,0 @@
# RGB

View File

@ -1 +0,0 @@
# Set LED Color

View File

@ -0,0 +1,64 @@
# show Animation
Show a group of image frames (pictures) one after another on the [LED screen](/device/screen). It pauses the amount of time you tell it after each frame.
```sig
basic.showAnimation(`
. . # . . . # # # . . # # # .
. # # . . . . . # . . . . # .
. . # . . . . # . . . # # # .
. . # . . . # . . . . . . # .
. . # . . . # # # . . # # # .
`)
```
## Parameters
* `leds` is a [string](/types/string) that shows which LEDs are on and off, in groups one after another.
* `interval` is an optional [number](/types/number). It means the number of milliseconds to pause after each image frame.
## Example: Animating a group of image frames
In this animation, each row is 15 spaces wide because
there are three frames in the animation, and each frame is
five spaces wide, just like the screen on the @boardname@.
```blocks
basic.showAnimation(`
. . # . . . # # # . . # # # .
. # # . . . . . # . . . . # .
. . # . . . . # . . . # # # .
. . # . . . # . . . . . . # .
. . # . . . # # # . . # # # .
`)
```
## ~hint
If the animation is too fast, make `interval` bigger.
## ~
## Example: animating frames with a pause
This example shows six frames on the screen, pausing 500 milliseconds after each frame.
In this animation, each row is 30 spaces wide because
there are six frames in the animation, and each frame is
five spaces wide, just like the screen.
```blocks
basic.showAnimation(`
. . . . . # . . . . . . . . . . . . . # . . . . . # . . . .
. . # . . . . . . . . . # . . . . . . . . . # . . . . . . .
. # . # . . . # . . . # . # . . . # . . . # . # . . . # . .
. . # . . . . . . . . . # . . . . . . . . . # . . . . . . .
. . . . . . . . . # . . . . . # . . . . . . . . . . . . . #
`, 500)
```
## ~hint
Use [forever](/reference/basic/forever) to show an animation over and over.
## ~

View File

@ -0,0 +1,29 @@
# Show Arrow
Shows the selected arrow on the LED screen
```sig
basic.showArrow(ArrowNames.North)
```
## Parameters
* ``direction``, the identifier of the arrow to display
* ``interval`` (optional), the time to display in milliseconds. default is 400.
## 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)

View File

@ -1 +0,0 @@
# Show Compass

View File

@ -8,7 +8,7 @@ basic.showNumber(2)
## Parameters
* `value` is a [Number](/types/number). If the number is not single-digit number, it will scroll on the display.
* `value` is a [Number](/types/number).
* `interval` is an optional [Number](/types/number). It means the number of milliseconds before sliding the `value` left by one LED each time. Bigger intervals make the sliding slower.
## Examples:
@ -37,10 +37,6 @@ for (let i = 0; i < 6; i++) {
}
```
## Advanced
If `value` is `NaN` (not a number), `?` is displayed.
## Other show functions
* Use [show string](/reference/basic/show-string) to show a [String](/types/string) with letters on the screen.

View File

@ -1 +0,0 @@
# Turn RGB Led Off

View File

@ -3,7 +3,6 @@
Support for additional Bluetooth services.
## ~hint
![](/static/bluetooth/Bluetooth_SIG.png)
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.
@ -35,6 +34,14 @@ bluetooth.uartWriteValue("", 0);
bluetooth.onUartDataReceived(",", () => {})
```
## Eddystone
```cards
bluetooth.advertiseUid(42, 1, 7, true);
bluetooth.advertiseUrl("https://makecode.microbit.org/", 7, true);
bluetooth.stopAdvertising();
```
## Advanced
For more advanced information on the @boardname@ Bluetooth UART service including information on using a smartphone, see the [Lancaster University @boardname@ runtime technical documentation](http://lancaster-university.github.io/microbit-docs/ble/uart-service/)
@ -49,7 +56,9 @@ For more advanced information on the @boardname@ Bluetooth UART service includin
[uartWriteNumber](/reference/bluetooth/uart-write-number),
[uartWriteValue](/reference/bluetooth/uart-write-value),
[onBluetoothConnected](/reference/bluetooth/on-bluetooth-connected),
[onBluetoothDisconnected](/reference/bluetooth/on-bluetooth-disconnected)
[onBluetoothDisconnected](/reference/bluetooth/on-bluetooth-disconnected),
[advertiseUrl](/reference/bluetooth/advertise-url),
[stopAdvertising](/reference/bluetooth/stop-advertising)
```package
bluetooth

View File

@ -2,18 +2,6 @@
Advertises a UID via the Eddystone protocol over Bluetooth.
```sig
bluetooth.advertiseUidBuffer(pins.createBuffer(16), 7, true);
```
### ~ reminder
#### Deprecated
This API is deprecated. The Eddystone beacon format is no longer supported, see [Google Beacon format (Deprecated)](https://developers.google.com/beacons/eddystone).
### ~
## ~hint
## Eddystone
@ -29,6 +17,10 @@ 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).

View File

@ -2,18 +2,6 @@
Advertises a UID via the Eddystone protocol over Bluetooth.
```sig
bluetooth.advertiseUid(42, 1, 7, true);
```
### ~ reminder
#### Deprecated
This API is deprecated. The Eddystone beacon format is no longer supported, see [Google Beacon format (Deprecated)](https://developers.google.com/beacons/eddystone).
### ~
## ~hint
## Eddystone
@ -29,6 +17,10 @@ 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)

View File

@ -2,18 +2,6 @@
Advertises a URL via the Eddystone protocol over Bluetooth.
```sig
bluetooth.advertiseUrl("https://makecode.microbit.org/", 7, true);
```
### ~ reminder
#### Deprecated
This API is deprecated. The Eddystone beacon format is no longer supported, see [Google Beacon format (Deprecated)](https://developers.google.com/beacons/eddystone).
### ~
## ~hint
## Eddystone
@ -29,6 +17,10 @@ Read more at https://lancaster-university.github.io/microbit-docs/ble/eddystone/
## ~
```sig
bluetooth.advertiseUrl("https://makecode.microbit.org/", 7, true);
```
## Parameters
* ``url`` - a [string](/types/string) containing the URL to broadcast, at most 17 characters long, excluding the protocol (eg: ``https://``) which gets encoded as 1 byte.

View File

@ -1,50 +1,21 @@
# Bluetooth On UART Data Received
Runs some code in an event when a delimiter is matched in the received data.
Registers an event to be fired when one of the delimiter is matched.
```sig
bluetooth.onUartDataReceived(serial.delimiters(Delimiters.NewLine), function() {})
bluetooth.onUartDataReceived(",", () => {})
```
## Parameters
* **delimiters**: a [string](/types/string) containing the delimiter characters to match in the received data.
### ~ hint
#### Delimiters
Delimiters are characters in a received data string which divide the string into smaller strings to form separate data items.
Although multiple delimiter characters can be set in the **delimiters** string, it is common to have received data separated using just one delimiter character, such as a comma:
``"data1,data2,data3,data4"``
So, you can specify a delimiter character using the ``||serial:serial delimiters||`` which create a single character delimiter string for you...
```block
bluetooth.onUartDataReceived(serial.delimiters(Delimiters.Comma), function () {
})
```
Or, maybe...
```block
let delim = serial.delimiters(Delimiters.NewLine)
basic.showString(bluetooth.uartReadUntil(delim))
```
### ~
* `delimiters` is a [string](/types/string) containing any of the character to match
## Example
Read the data items separated by a comma (`,`):
Read values separated by `,`:
```blocks
bluetooth.onUartDataReceived(serial.delimiters(Delimiters.Comma), function () {
basic.showString(bluetooth.uartReadUntil(serial.delimiters(Delimiters.Space)))
bluetooth.onUartDataReceived(serial.delimiters(Delimiters.Comma), () => {
basic.showString(serial.readUntil(serial.delimiters(Delimiters.Comma)))
})
```
```package
bluetooth
```

View File

@ -24,7 +24,7 @@ bluetooth.stopAdvertising();
## Example: stop advertising on button pressed
```blocks
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
bluetooth.stopAdvertising();
})
```

View File

@ -27,7 +27,7 @@ bluetooth.onBluetoothDisconnected(() => {
basic.showString("D");
connected = 0;
});
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
if (connected == 1) {
bluetooth.uartWriteLine("HELLO");
}

View File

@ -27,7 +27,7 @@ bluetooth.onBluetoothDisconnected(() => {
basic.showString("D");
connected = 0;
});
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
if (connected == 1) {
bluetooth.uartWriteString("HELLO");
}

View File

@ -4,7 +4,7 @@ Runtime and event utilities.
```cards
control.inBackground(() => {
});
control.reset();
control.waitMicros(4);

View File

@ -29,7 +29,7 @@ control.inBackground(() => {
basic.pause(100)
}
})
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
num++;
})
```
@ -42,7 +42,7 @@ let num = 0
basic.forever(() => {
basic.showNumber(num)
})
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
num++;
})
```

View File

@ -24,11 +24,11 @@ When you get tired of counting, press button `B` to reset the
```blocks
let item = 0;
basic.showNumber(item);
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
item = item + 1;
basic.showNumber(item);
});
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.B, () => {
control.reset();
});
```

33
docs/reference/devices.md Normal file
View File

@ -0,0 +1,33 @@
# Devices
Control a phone with the @boardname@ via Bluetooth.
## ~ hint
**App required** You must use one of the [micro:bit apps](https://microbit.org/guide/mobile/) to use this functionality.
## ~
```cards
devices.tellCameraTo(MesCameraEvent.TakePhoto);
devices.tellRemoteControlTo(MesRemoteControlEvent.play);
devices.raiseAlertTo(MesAlertEvent.DisplayToast);
devices.onNotified(MesDeviceInfo.IncomingCall, () => {
});
devices.onGamepadButton(MesDpadButtonInfo.ADown, () => {
});
devices.signalStrength();
devices.onSignalStrengthChanged(() => {
});
```
```package
devices
```
## See Also
[tellCameraTo](/reference/devices/tell-camera-to), [tellRemoteControlTo](/reference/devices/tell-remote-control-to), [raiseAlertTo](/reference/devices/raise-alert-to), [onNotified](/reference/devices/on-notified), [onGamepadButton](/reference/devices/on-gamepad-button), [signalStrength](/reference/devices/signal-strength), [onSignalStrengthChanged](/reference/devices/on-signal-strength-changed)

View File

@ -0,0 +1,25 @@
# On Gamepad Button
Register code to run when the @boardname@ receives a command from the paired gamepad.
## ~hint
**App required** You must use one of the [micro:bit apps](https://microbit.org/guide/mobile/) to use this functionality.
## ~
```sig
devices.onGamepadButton(MesDpadButtonInfo.ADown, () => {})
```
## Parameters
* ``body``: Action code to run when the the @boardname@ receives a command from the paired gamepad.
## See Also
[tell remote control to](/reference/devices/tell-remote-control-to), [raise alert to](/reference/devices/raise-alert-to), [signal strength](/reference/devices/signal-strength), [on signal strength changed](/reference/devices/on-signal-strength-changed)
```package
devices
```

View File

@ -0,0 +1,35 @@
# On Notified
Register code to run when the signal strength of the paired device changes.
## ~hint
**App required** You must use one of the [micro:bit apps](https://microbit.org/guide/mobile/) to use this functionality.
## ~
```sig
devices.onNotified(MesDeviceInfo.IncomingCall, () => {})
```
## Parameters
* ``body``: code to run when the signal strength changes.
## Examples
Display the signal strength on screen:
```blocks
devices.onNotified(MesDeviceInfo.IncomingCall, () => {
basic.showString("RING RING")
})
```
## See Also
[tell remote control to](/reference/devices/tell-remote-control-to), [raise alert to](/reference/devices/raise-alert-to), [signal strength](/reference/devices/signal-strength)
```package
devices
```

View File

@ -0,0 +1,37 @@
# On Signal Strength Changed
Register code to run when the signal strength of the paired device changes.
## ~hint
**App required** You must use one of the [micro:bit apps](https://microbit.org/guide/mobile/) to use this functionality.
## ~
```sig
devices.onSignalStrengthChanged(() => {})
```
## Parameters
* ``body``: code to run when the signal strength changes.
## Examples
Display the signal strength on screen:
```blocks
devices.onSignalStrengthChanged(() => {
basic.showNumber(devices.signalStrength())
})
```
## See Also
[tell remote control to](/reference/devices/tell-remote-control-to), [raise alert to](/reference/devices/raise-alert-to), [signal strength](/reference/devices/signal-strength)
```package
devices
```

View File

@ -0,0 +1,65 @@
# raise alert to
Raise an alert on a remote device.
## ~hint
**App required** You must use one of the [micro:bit apps](https://microbit.org/guide/mobile/) to use this functionality.
## ~
```sig
devices.raiseAlertTo(MesAlertEvent.Vibrate)
```
## Parameters
* event - an event identifier
## Examples
To tell the connected device to display toast
```blocks
devices.raiseAlertTo(MesAlertEvent.DisplayToast)
```
To tell the connected device to vibrate
```blocks
devices.raiseAlertTo(MesAlertEvent.Vibrate)
```
To tell the connected device to play a sound
```blocks
devices.raiseAlertTo(MesAlertEvent.PlaySound)
```
To tell the connected device to play a ringtone
```blocks
devices.raiseAlertTo(MesAlertEvent.PlayRingtone)
```
To tell the connected device to find my phone
```blocks
devices.raiseAlertTo(MesAlertEvent.FindMyPhone)
```
To tell the connected device to ring alarm
```blocks
devices.raiseAlertTo(MesAlertEvent.RingAlarm)
```
## See also
[tell remote control to](/reference/devices/tell-remote-control-to), [tell camera to](/reference/devices/tell-camera-to)
```package
devices
```

View File

@ -0,0 +1,36 @@
# Signal Strength
Returns the signal strength reported by the paired device from ``0`` (no signal) to ``4`` (full strength).
## ~hint
**App required** You must use one of the [micro:bit apps](https://microbit.org/guide/mobile/) to use this functionality.
## ~
```sig
devices.signalStrength();
```
## Returns
* the signal strength from ``0`` (no signal) to ``4`` (full strength).
## Examples
Display the signal strength on screen:
```blocks
devices.onSignalStrengthChanged(() => {
basic.showNumber(devices.signalStrength())
})
```
## See Also
[tell remote control to](/reference/devices/tell-remote-control-to), [raise alert to](/reference/devices/raise-alert-to), [on signal strength changed](/reference/devices/on-signal-strength-changed)
```package
devices
```

View File

@ -0,0 +1,76 @@
# tell camera to
Access the photo/video-taking functionality of a remote device using the ``tell camera to`` function.
## ~hint
**App required** You must use one of the [micro:bit apps](https://microbit.org/guide/mobile/) to use this functionality.
## ~
```sig
devices.tellCameraTo(MesCameraEvent.TakePhoto)
```
## Parameters
* event - an event identifier
## Examples
To tell the connected device to take a picture:
```blocks
devices.tellCameraTo(MesCameraEvent.TakePhoto)
```
To tell the connected device to start recording a video:
```blocks
devices.tellCameraTo(MesCameraEvent.StartVideoCapture)
```
To tell the connected device to stop recording a video:
```blocks
devices.tellCameraTo(MesCameraEvent.StopVideoCapture)
```
To tell the connected device to toggle front-rear:
```blocks
devices.tellCameraTo(MesCameraEvent.ToggleFrontRear)
```
To tell the connected device to launch photo mode:
```blocks
devices.tellCameraTo(MesCameraEvent.LaunchPhotoMode)
```
To tell the connected device to launch video mode:
```blocks
devices.tellCameraTo(MesCameraEvent.LaunchVideoMode)
```
To tell the connected device to stop photo mode:
```blocks
devices.tellCameraTo(MesCameraEvent.StopPhotoMode)
```
To tell the connected device to stop video mode:
```blocks
devices.tellCameraTo(MesCameraEvent.StopVideoMode)
```
## See Also
[tell remote control to](/reference/devices/tell-remote-control-to), [raise alert to](/reference/devices/raise-alert-to)
```package
devices
```

View File

@ -0,0 +1,89 @@
# tell remote control to
Control the presentation of media content available on a remote device using the `tell remote control` to function.
## ~hint
**App required** You must use one of the [micro:bit apps](https://microbit.org/guide/mobile/) to use this functionality.
## ~
```sig
devices.tellRemoteControlTo(MesRemoteControlEvent.play)
```
## Parameters
* event - an event identifier
## Event values
* play
* stop
* pause
* forward
* rewind
* volume up
* volume down
* previous track
* next track
## Examples
To tell the connected device to start playing:
```blocks
devices.tellRemoteControlTo(MesRemoteControlEvent.play)
```
To tell the connected device to stop playing
```blocks
devices.tellRemoteControlTo(MesRemoteControlEvent.stop)
```
To tell the connected device to go to next track
```blocks
devices.tellRemoteControlTo(MesRemoteControlEvent.nextTrack)
```
To tell the connected device to go to previous track
```blocks
devices.tellRemoteControlTo(MesRemoteControlEvent.previousTrack)
```
To tell the connected device to go forward
```blocks
devices.tellRemoteControlTo(MesRemoteControlEvent.forward)
```
To tell the connected device to rewind
```blocks
devices.tellRemoteControlTo(MesRemoteControlEvent.rewind)
```
To tell the connected device volume up
```blocks
devices.tellRemoteControlTo(MesRemoteControlEvent.volumeUp)
```
To tell the connected device volume down
```blocks
devices.tellRemoteControlTo(MesRemoteControlEvent.volumeDown)
```
## See also
[tell camera to](/reference/devices/tell-camera-to), [raise alert to](/reference/devices/raise-alert-to)
```package
devices
```

View File

@ -9,7 +9,7 @@ An event handler is code that is associated with a particular event, such as "bu
Functions named "on <event>" create an association between an event and the event handler code. For example, the following code registers the event handler (the code between the `do` and `end` keywords) with the event of a press of button A:
```blocks
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
input.onButtonPressed(Button.A, () => {
basic.showString("hello", 150)
})
```
@ -21,7 +21,7 @@ After this code executes, then whenever button A is pressed in the future, the s
Once you have registered an event handler for an event, like above, that event handler is active for the rest of the program execution. If you want to stop the string "hello" from printing each time button A is pressed then you need to arrange for the following code to execute:
```blocks
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
input.onButtonPressed(Button.A, () => {
})
```
@ -32,10 +32,10 @@ The above code associated an event handler that does nothing with the event of a
The above example also illustrates that there is only one event handler for each event. What is the result of the following code?
```blocks
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
input.onButtonPressed(Button.A, () => {
basic.showString("hello", 150)
})
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
input.onButtonPressed(Button.A, () => {
basic.showString("goodbye", 150)
})
```
@ -43,7 +43,7 @@ input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
The answer is that whenever button A is pressed, the string "goodbye" will be printed. If you want both the strings "hello" and "goodbye" to be printed, you need to write the code like this:
```blocks
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
input.onButtonPressed(Button.A, () => {
basic.showString("hello", 150)
basic.showString("goodbye", 150)
})

View File

@ -16,11 +16,11 @@ Press button ``A`` as much as possible to increase the score.
Press ``B`` to display the score and reset the score.
```blocks
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.B, () => {
basic.showNumber(game.score())
game.setScore(0)
})
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
```

View File

@ -16,7 +16,7 @@ Press button ``A`` as much as possible.
At the end of 10 seconds, the program will show your score.
```blocks
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
game.startCountdown(10000)

View File

@ -1,23 +1,19 @@
# change (Sprite Property)
Change a value for a [sprite](/reference/game/create-sprite) property by some amount.
Change the kind of [number](/types/number) you say for a [sprite](/reference/game/create-sprite).
```sig
game.createSprite(0,0).change(LedSpriteProperty.X, 0);
```
The value of a sprite propery is changed by using either a positive or negative number. Giving `1` will increase a property value by `1` and giving a `-1` will decrease it by `1`.
## Parameters
* **property**: the property of the **Sprite** you want to change, like:
>* ``x`` - the change in horizontal location to set the sprite at on the LED screen (`0`-`4`)
>* ``y`` - the change vertical location to set the sprite at on the LED screen (`0`-`4`)
>* ``direction`` - the change of direction in degrees for the sprite to go when the next [move](/reference/game/move) happens. Direction degree range is from `-180` to `180`.
>* ``brightness`` - the change in brightness for the LED sprite. Completely dark is `0` and very bright is `255`.
>* ``blink`` - the change in how fast the sprite is will blink on and off. The blink rate is in milliseconds.
* **value**: a [number](/types/number) value that is the amount of change for the property.
>* ``x`` - how far up or down the sprite is on the screen (`0`-`4`)
>* ``y`` - how far left or right the sprite is on the screen (`0`-`4`)
>* ``direction`` - which way the sprite is pointing (this works the same way as the [turn](/reference/game/turn) function)
>* ``brightness`` - how bright the LED sprite is (this works the same way as the [brightness](/reference/led/brightness) function)
>* ``blink`` - how fast the sprite is blinking (the bigger the number is, the faster the sprite is blinking)
## Example

View File

@ -27,7 +27,7 @@ let img = images.createImage(`
. . . . .
`)
img.showImage(0)
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
img.clear()
img.showImage(0)
})

View File

@ -14,10 +14,10 @@ If you press button `B`, it shows an animation and ends the game.
```blocks
basic.showString("PICK A BUTTON");
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
basic.showString("YOU WIN!");
});
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.B, () => {
game.gameOver();
});
```

View File

@ -1,6 +1,6 @@
# get (Sprite Property)
Get a value for a [sprite](/reference/game/create-sprite) property.
Find something out about a [sprite](/reference/game/create-sprite).
```sig
game.createSprite(0,0).get(LedSpriteProperty.X);
@ -9,11 +9,11 @@ game.createSprite(0,0).get(LedSpriteProperty.X);
## Parameters
* **property**: the property of the **Sprite** you want to know about, like:
>* ``x`` - the horizontal location to set the sprite at on the LED screen (`0`-`4`)
>* ``y`` - the vertical location to set the sprite at on the LED screen (`0`-`4`)
>* ``direction`` - the direction in degrees for the sprite to go when the next [move](/reference/game/move) happens. The degree range is from `-180` to `180`.
>* ``brightness`` - how bright the LED sprite is. Completely dark is `0` and very bright is `255`.
>* ``blink`` - how fast the sprite is will blink on and off. The blink rate is in milliseconds.
>* ``x`` - how far up or down the sprite is on the screen (`0`-`4`)
>* ``y`` - how far left or right the sprite is on the screen (`0`-`4`)
>* ``direction`` - which way the sprite is pointing (this works the same way as the [turn](/reference/game/turn) function)
>* ``brightness`` - how bright the LED sprite is (this works the same way as the [brightness](/reference/led/brightness) function)
>* ``blink`` - how fast the sprite is blinking (the bigger the number is, the faster the sprite is blinking)
## Returns

View File

@ -20,7 +20,7 @@ degrees -- exactly the opposite direction.
```blocks
let ball = game.createSprite(4, 2);
basic.showNumber(ball.get(LedSpriteProperty.Direction));
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.B, () => {
ball.ifOnEdgeBounce();
basic.showNumber(ball.get(LedSpriteProperty.Direction));
});

View File

@ -15,7 +15,7 @@ game.isPaused()
Resume the game if it's paused and button **B** is pressed.
```blocks
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Down), function () {
input.onButtonPressed(Button.B, function () {
if (game.isPaused()) {
game.resume()
}

View File

@ -15,7 +15,7 @@ game.isRunning()
If the game is currently running, end the game if button **B** is pressed.
```blocks
input.onButtonEvent(Button.B, input.buttonEventClick(), function () {
input.onButtonPressed(Button.B, function () {
if (game.isRunning()) {
game.gameOver()
}

View File

@ -13,7 +13,7 @@ This program adds one point to your score every time you press button
second) and shows your score.
```blocks
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
input.onButtonPressed(Button.A, () => {
game.addScore(1);
basic.pause(500);
basic.showNumber(game.score());

View File

@ -16,11 +16,11 @@ Press button ``A`` as much as possible to increase the score.
Press ``B`` to display the score and reset the score.
```blocks
input.onButtonEvent(Button.B, input.buttonEventClick(), () => {
input.onButtonPressed(Button.B, () => {
basic.showNumber(game.score())
game.setScore(0)
})
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
```

View File

@ -1,6 +1,6 @@
# set (Sprite Property)
Set a value for a [sprite](/reference/game/create-sprite) property.
Make a [sprite](/reference/game/create-sprite) store the kind of [number](/types/number) you say.
```sig
game.createSprite(0,0).set(LedSpriteProperty.X, 0);
@ -9,39 +9,22 @@ game.createSprite(0,0).set(LedSpriteProperty.X, 0);
## Parameters
* **property**: the property of the **Sprite** you want to store a value for, like:
>* ``x`` - the horizontal location to set the sprite at on the LED screen (`0`-`4`)
>* ``y`` - the vertical location to set the sprite at on the LED screen (`0`-`4`)
>* ``direction`` - the direction in degrees for the sprite to go when the next [move](/reference/game/move) happens. The degree range is from `-180` to `180`.
>* ``brightness`` - how bright the LED sprite is. Completely dark is `0` and very bright is `255`.
>* ``blink`` - how fast the sprite is will blink on and off. The blink rate is in milliseconds.
* **value**: the a [number](/types/number) value to set for the property.
>* ``x`` - how far up or down the sprite is on the screen (`0`-`4`)
>* ``y`` - how far left or right the sprite is on the screen (`0`-`4`)
>* ``direction`` - which way the sprite is pointing (this works the same way as the [turn](/reference/game/turn) function)
>* ``brightness`` - how bright the LED sprite is (this works the same way as the [brightness](/reference/led/brightness) function)
>* ``blink`` - how fast the sprite is blinking (the bigger the number is, the faster the sprite is blinking)
## Example
Make an LED sprite move to random locations on the screen. Use button **A** to freeze and unfreeze the sprite while it's moving. When the sprite is frozen, it will blink and dim to half brightness.
This program makes a sprite on the left side of the screen,
waits two seconds (2000 milliseconds),
and then moves it to the right side of the screen.
```blocks
input.onButtonEvent(Button.A, input.buttonEventClick(), function () {
if (freeze) {
sprite.set(LedSpriteProperty.Brightness, 255)
sprite.set(LedSpriteProperty.Blink, 0)
} else {
sprite.set(LedSpriteProperty.Brightness, 128)
sprite.set(LedSpriteProperty.Blink, 200)
}
freeze = !(freeze)
})
let freeze = false
let sprite: game.LedSprite = null
sprite = game.createSprite(0, 0)
basic.forever(function () {
if (!(freeze)) {
sprite.set(LedSpriteProperty.X, randint(0, 4))
sprite.set(LedSpriteProperty.Y, randint(0, 4))
}
basic.pause(500)
})
let ball = game.createSprite(0, 2);
basic.pause(2000);
ball.set(LedSpriteProperty.X, 4);
```
## See also

View File

@ -17,7 +17,7 @@ Press button ``A`` as much as possible.
At the end of 10 seconds, the program will show your score.
```blocks
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
game.startCountdown(10000)

View File

@ -19,12 +19,14 @@ images.createBigImage(`
`);
images.createImage(``).showImage(0);
images.createImage(``).scrollImage(0,0);
images.arrowImage(ArrowNames.North)
images.iconImage(IconNames.Heart)
images.arrowNumber(ArrowNames.North)
```
## See Also
[createImage](/reference/images/create-image), [createBigImage](/reference/images/create-big-image),
[showImage](/reference/images/show-image), [scrollImage](/reference/images/scroll-image),
[iconImage](/reference/images/icon-image),
[arrowImage](/reference/images/arrow-image), [iconImage](/reference/images/icon-image), [arrowNumber](/reference/images/arrow-number),
[pixel](/reference/images/pixel), [set-pixel](/reference/images/set-pixel)

View File

@ -0,0 +1,41 @@
# arrow Image
Create an arrow shaped [image](/reference/images/image) for the [LED screen](/device/screen).
```sig
images.arrowImage(ArrowNames.North)
```
The arrow points in the direction of the arrow name you choose, like `North`.
## Parameters
* **i**: the arrow name to make an arrow [image](/reference/images/image) for. You can make an arrow image that points in one of these directions:
>* `North`
>* `NorthEast`
>* `East`
>* `SouthEast`
>* `South`
>* `SouthWest`
>* `West`
>* `NorthWest`
## Example
Display a left arrow when button A is pressed or a right arrow when button B is pressed.
```blocks
let arrowLeft = images.arrowImage(ArrowNames.West)
let arrowRight = images.arrowImage(ArrowNames.East)
input.onButtonPressed(Button.A, () => {
arrowLeft.showImage(0);
});
input.onButtonPressed(Button.B, () => {
arrowRight.showImage(0);
});
```
## See also
[arrow number](/reference/images/arrow-number)

View File

@ -0,0 +1,33 @@
# arrow Number
Get the number that matches an arrow image name.
```sig
images.arrowNumber(ArrowNames.North)
```
Each arrow image name has a number for it. You can find the number for any arrow name with ``||Images:arrow number||``.
## Parameters
* **arrow**: the arrow name to get an arrow number for. These are the arrow names:
>* `North`
* `NorthEast`
* `East`
* `SouthEast`
* `South`
* `SouthWest`
* `West`
* `NorthWest`
## Example
Get the arrow number for `ArrowNames.South`.
```blocks
let arrowSouthNumber = images.arrowNumber(ArrowNames.South)
```
## See also
[arrow image](/reference/images/arrow-image)

View File

@ -36,10 +36,10 @@ let arrows = images.createBigImage(`
. . # . . . # # # .
. . # . . . . # . .
`);
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
input.onButtonPressed(Button.A, () => {
arrows.showImage(0);
});
input.onButtonEvent(Button.B, input.buttonEventClick(), () => {
input.onButtonPressed(Button.B, () => {
arrows.showImage(5);
});
```

View File

@ -25,7 +25,7 @@ arrow and show it on the LED screen. If you press button `B`, the
program will show a picture of the arrow upside-down.
```blocks
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
input.onButtonPressed(Button.A, () => {
images.createImage(`
. . # . .
. # # # .
@ -34,7 +34,7 @@ input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
. . # . .
`).showImage(0);
});
input.onButtonEvent(Button.B, input.buttonEventClick(), () => {
input.onButtonPressed(Button.B, () => {
images.createImage(`
. . # . .
. . # . .

View File

@ -20,10 +20,14 @@ Show a happy face when button A is pressed or a sad face when button B is presse
let iamHappy = images.iconImage(IconNames.Happy)
let iamSad = images.iconImage(IconNames.Sad)
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
input.onButtonPressed(Button.A, () => {
iamHappy.showImage(0);
});
input.onButtonEvent(Button.B, input.buttonEventClick(), () => {
input.onButtonPressed(Button.B, () => {
iamSad.showImage(0);
});
```
## See also
[arrow image](/reference/images/arrow-image)

Some files were not shown because too many files have changed in this diff Show More