Compare commits
34 Commits
dependabot
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
b0af4b54b2 | ||
|
5aade18a66 | ||
|
77ed2ccfb1 | ||
|
1aaedf1fa0 | ||
|
6a5d25197b | ||
|
6d4b2185b4 | ||
|
5a1ba75dc9 | ||
|
b4f625d44c | ||
|
2f7a536874 | ||
|
0e78265f35 | ||
|
c9560c7411 | ||
|
5f7a8e5301 | ||
|
32783f38ba | ||
|
fa34fe5fd2 | ||
|
5aba020bb3 | ||
|
3838b46f1d | ||
|
5188a57927 | ||
|
3fd2c31481 | ||
|
2457725e0c | ||
|
75d7bfb7c2 | ||
|
36ee2958e1 | ||
|
0b6b882b7d | ||
|
4ae3308ef2 | ||
|
4b241dd0c7 | ||
|
f8c7d0f275 | ||
|
a93febb5b7 | ||
|
3b9d90e551 | ||
|
e2b28e7847 | ||
|
63571fb12f | ||
|
ec378c5b09 | ||
|
d4214c65f2 | ||
|
4ad5c2d4a0 | ||
|
b86010f1e6 | ||
|
3e0c9b43a2 |
8
.github/lock.yml
vendored
@ -30,13 +30,7 @@ lockLabel: false
|
||||
|
||||
# Comment to post before locking. Set to `false` to disable
|
||||
|
||||
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.
|
||||
lockComment: false
|
||||
|
||||
|
||||
|
||||
|
51
.github/workflows/codeql.yml
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
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
|
@ -1,12 +0,0 @@
|
||||
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 }}
|
@ -1,9 +1,10 @@
|
||||
name: pxt-buildtarget
|
||||
name: pxt-buildmain
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
branches:
|
||||
- 'master'
|
||||
- 'main'
|
||||
create:
|
||||
|
||||
jobs:
|
||||
@ -13,7 +14,7 @@ jobs:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [8.x]
|
||||
node-version: [18.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
31
.github/workflows/pxt-buildpr.yml
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
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
|
39
.github/workflows/pxt-buildpush.yml
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
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
|
7
.github/workflows/testghpkgs.yml
vendored
@ -11,9 +11,12 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [8.x]
|
||||
branch: [stable3.0]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ matrix.branch }}
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
@ -45,5 +48,5 @@ jobs:
|
||||
uses: actions/upload-artifact@v2
|
||||
if: ${{ always() }}
|
||||
with:
|
||||
name: logs
|
||||
name: logs-${{ matrix.branch }}
|
||||
path: temp/ghpkgs/*.txt
|
||||
|
27
.travis.yml
@ -1,27 +0,0 @@
|
||||
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
|
||||
|
1
.vscode/settings.json
vendored
@ -1,6 +1,5 @@
|
||||
// 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
@ -1,20 +1,19 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"version": "2.0.0",
|
||||
// Task runner is jake
|
||||
"command": "pxt",
|
||||
// Need to be executed in shell / cmd
|
||||
"isShellCommand": true,
|
||||
"showOutput": "always",
|
||||
"tasks": [
|
||||
{
|
||||
// TS build command is local.
|
||||
"taskName": "serve",
|
||||
// Make this the default build command.
|
||||
"isBuildCommand": true,
|
||||
// Use the redefined Typescript output problem matcher.
|
||||
"label": "serve",
|
||||
"type": "shell",
|
||||
"command": "pxt",
|
||||
"args": [
|
||||
"serve"
|
||||
],
|
||||
"problemMatcher": [
|
||||
"$tsc"
|
||||
]
|
||||
],
|
||||
"group": "build"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
41
SECURITY.md
Normal file
@ -0,0 +1,41 @@
|
||||
<!-- 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 -->
|
@ -1,13 +0,0 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "../pxt"
|
||||
},
|
||||
{
|
||||
"path": "../pxt-common-packages"
|
||||
},
|
||||
{
|
||||
"path": "."
|
||||
}
|
||||
]
|
||||
}
|
131
compiler/combiner.ts
Normal file
@ -0,0 +1,131 @@
|
||||
/// <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 = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
23
compiler/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"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"
|
||||
]
|
||||
}
|
||||
}
|
2
docfiles/offline-app-trademarks.html
Normal file
@ -0,0 +1,2 @@
|
||||
Micro:bit and micro:bit logo are trademarks and/ or copyrights of the Micro:bit
|
||||
Educational Foundation. © Micro:bit Educational Foundation. All rights reserved.
|
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
basic.showString("Hi!");
|
||||
})
|
||||
```
|
||||
```typescript
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
led.stopAnimation();
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
@ -63,7 +63,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
# . . . #
|
||||
. # # # .`);
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
led.stopAnimation();
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
@ -78,6 +78,13 @@ input.onButtonPressed(Button.B, () => {
|
||||
|
||||
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)
|
||||
|
||||
|
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
let x = randint(0, 5)
|
||||
if(x < 5) {
|
||||
basic.showString("low");
|
||||
|
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
if(input.lightLevel()<100){
|
||||
led.setBrightness(255);
|
||||
}
|
||||
|
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
for(let i = 0; i < 5; ++i) {
|
||||
basic.showNumber(i)
|
||||
}
|
||||
|
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
let index = 4;
|
||||
while(index >= 0) {
|
||||
led.plot(index, index);
|
||||
|
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
basic.showString("Hello!")
|
||||
})
|
||||
led.setBrightness(50)
|
||||
|
@ -59,7 +59,7 @@ A counter is a great example:
|
||||
|
||||
```blocks
|
||||
let counter = 0;
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
counter = counter + 1;
|
||||
basic.showNumber(counter);
|
||||
});
|
||||
|
BIN
docs/calliope/02_Hero_CalliopEO.png
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
docs/calliope/03_Hero_KidsLab.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
docs/calliope/calliopeo-header.png
Normal file
After Width: | Height: | Size: 220 KiB |
27
docs/calliope/templates.md
Normal file
@ -0,0 +1,27 @@
|
||||
# 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"
|
||||
}
|
||||
]
|
||||
```
|
BIN
docs/calliope/templates/16KB.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
docs/calliope/templates/16KB_L.png
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
docs/calliope/templates/32KB.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
docs/calliope/templates/32KB_L.png
Normal file
After Width: | Height: | Size: 34 KiB |
@ -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.onPinPressed(TouchPin.P0, () => {
|
||||
input.onPinTouchEvent(TouchPin.P0, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
basic.showNumber(randint(0, 10))
|
||||
})
|
||||
```
|
||||
|
@ -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.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Click), () => {
|
||||
for (let i = 0; i < 25; i++) {
|
||||
if (i % 2 > 0) {
|
||||
led.plotBarGraph(0, 0)
|
||||
|
@ -51,7 +51,7 @@ The first job of the scheduler is to allow multiple *subprograms* to be queued u
|
||||
```typescript
|
||||
let count = 0
|
||||
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
count = count + 1
|
||||
})
|
||||
|
||||
@ -165,7 +165,7 @@ basic.forever(() => {
|
||||
basic.showNumber(count)
|
||||
})
|
||||
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
count = 0
|
||||
})
|
||||
```
|
||||
|
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
serial.writeLine("A pressed")
|
||||
})
|
||||
```
|
||||
|
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
|
||||
basic.showString("A");
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Click), () => {
|
||||
basic.showString("B");
|
||||
});
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
input.onPinTouchEvent(TouchPin.P0, input.buttonEventValue(ButtonEvent.Click), () => {
|
||||
basic.showString("0");
|
||||
});
|
||||
input.onPinPressed(TouchPin.P1, () => {
|
||||
input.onPinTouchEvent(TouchPin.P1, input.buttonEventValue(ButtonEvent.Click), () => {
|
||||
basic.showString("1");
|
||||
});
|
||||
input.onPinPressed(TouchPin.P2, () => {
|
||||
input.onPinTouchEvent(TouchPin.P2, input.buttonEventValue(ButtonEvent.Click), () => {
|
||||
basic.showString("2");
|
||||
});
|
||||
input.temperature()
|
||||
|
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
|
||||
gameOfLife();
|
||||
show();
|
||||
})
|
||||
|
||||
//Use button B for reseting to random initial seed state
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Click), () => {
|
||||
reset();
|
||||
show();
|
||||
})
|
||||
|
21
docs/hero-banner.md
Normal file
@ -0,0 +1,21 @@
|
||||
# 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
|
||||
### ~
|
@ -1,3 +1,3 @@
|
||||
{
|
||||
"appref": "v3.0.33"
|
||||
"appref": "v4.0.29"
|
||||
}
|
||||
|
@ -2,6 +2,12 @@
|
||||
|
||||
```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",
|
||||
@ -23,6 +29,7 @@
|
||||
|
||||
## See Also
|
||||
|
||||
[New Project (iPad)](/calliope/templates),
|
||||
[First Steps](/calliope/firststeps),
|
||||
[Tutorials](/calliope/tutorials),
|
||||
[Calliope Links](/calliope/links)
|
||||
|
@ -1,5 +1,8 @@
|
||||
# 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)
|
||||
|
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
|
||||
})
|
||||
```
|
||||
|
||||
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
|
||||
if (Math.randomBoolean()) {
|
||||
} else {
|
||||
}
|
||||
@ -34,7 +34,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
|
||||
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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
|
||||
basic.showIcon(IconNames.Diamond)
|
||||
basic.showIcon(IconNames.SmallDiamond)
|
||||
basic.showIcon(IconNames.Diamond)
|
||||
|
@ -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.onPinPressed(TouchPin.P0, () => {
|
||||
input.onPinTouchEvent(TouchPin.P0, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
});
|
||||
```
|
||||
|
||||
@ -20,7 +20,7 @@ input.onPinPressed(TouchPin.P0, () => {
|
||||
Using ``||basic:show number||`` and ``||Math:pick random||`` blocks, show a random number from `0` to `100` when pin **0** is pressed.
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
input.onPinTouchEvent(TouchPin.P0, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
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.onPinPressed(TouchPin.P0, () => {
|
||||
input.onPinTouchEvent(TouchPin.P0, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
basic.showNumber(randint(0, 100));
|
||||
});
|
||||
```
|
||||
|
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
radio.sendString("Yo");
|
||||
});
|
||||
radio.onReceivedString(function (receivedString) {
|
||||
|
@ -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.onButtonPressed(Button.A, function () {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), function () {
|
||||
|
||||
})
|
||||
```
|
||||
@ -23,7 +23,7 @@ input.onButtonPressed(Button.A, function () {
|
||||
From the ``||basic:Basic||`` Toolbox drawer drag a ``||basic:show string||`` block into the ``||input:on button A pressed||`` block.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, function () {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), function () {
|
||||
basic.showString("Hello!")
|
||||
})
|
||||
```
|
||||
@ -33,7 +33,7 @@ input.onButtonPressed(Button.A, function () {
|
||||
In the ``||basic:show string||`` block, type your name.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, function () {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), function () {
|
||||
basic.showString("My Name")
|
||||
})
|
||||
```
|
||||
@ -43,7 +43,7 @@ input.onButtonPressed(Button.A, function () {
|
||||
Go to the simulator and test your name badge by pressing button **A**.
|
||||
|
||||
```sim
|
||||
input.onButtonPressed(Button.A, function () {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), function () {
|
||||
basic.showString("My Name")
|
||||
})
|
||||
```
|
||||
|
@ -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 @fullscreen
|
||||
## Step 1
|
||||
|
||||
Place the ``||basic:show string||`` block in the ``||basic:forever||`` block to repeat it. Change the text to your name.
|
||||
|
||||
@ -16,13 +16,12 @@ basic.forever(() => {
|
||||
});
|
||||
```
|
||||
|
||||
## Step 2 @fullscreen
|
||||
## Step 2
|
||||
|
||||
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.
|
||||
|
||||
@ -33,6 +32,6 @@ basic.forever(() => {
|
||||
})
|
||||
```
|
||||
|
||||
## Step 4 @unplugged
|
||||
## Step 4
|
||||
|
||||
If you have a @boardname@ connected, click ``|Download|`` to transfer your code and watch your name scroll!
|
||||
|
@ -123,7 +123,7 @@ basic.forever(function () {
|
||||
**MakeCode blocks for the Robot Unicorn controller**
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.AB, function () {
|
||||
input.onButtonEvent(Button.AB, input.buttonEventValue(ButtonEvent.Down), function () {
|
||||
radio.sendNumber(4)
|
||||
basic.showLeds(`
|
||||
# . . . #
|
||||
|
@ -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.onButtonPressed(Button.A, function () {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), function () {
|
||||
basic.showNumber(pulseCount)
|
||||
pulseCount = 0
|
||||
})
|
||||
|
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
|
||||
});
|
||||
```
|
||||
|
||||
@ -21,7 +21,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), () => {
|
||||
basic.showLeds(`
|
||||
# # . # #
|
||||
# # . # #
|
||||
@ -37,7 +37,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
Add ``||input:on button pressed||`` and ``||basic:show leds||`` blocks to display a frowny when button **B** is pressed.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Click), () => {
|
||||
basic.showLeds(`
|
||||
# # . # #
|
||||
# # . # #
|
||||
@ -53,7 +53,7 @@ input.onButtonPressed(Button.B, () => {
|
||||
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.onButtonPressed(Button.AB, () => {
|
||||
input.onButtonEvent(Button.AB, input.buttonEventValue(ButtonEvent.Click), () => {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
# . # . .
|
||||
|
@ -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.onButtonPressed(Button.A, function () {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), 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.onButtonPressed(Button.A, function () {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Click), function () {
|
||||
if (sprite.get(LedSpriteProperty.X) == 2) {
|
||||
game.addScore(1)
|
||||
} else {
|
||||
|
@ -18,7 +18,7 @@ basic.forever(() => {
|
||||
|
||||
});
|
||||
basic.pause(100);
|
||||
basic.showArrow(ArrowNames.North);
|
||||
basic.showIcon(IconNames.ArrowNorth);
|
||||
```
|
||||
|
||||
## See also
|
||||
@ -27,4 +27,4 @@ basic.showArrow(ArrowNames.North);
|
||||
[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),
|
||||
[showArrow](/reference/basic/show-arrow), [showAnimation](/reference/basic/show-animation)
|
||||
[showAnimation](/reference/basic/show-animation)
|
@ -1,4 +1,4 @@
|
||||
# Forever
|
||||
# forever
|
||||
|
||||
Keep running part of a program
|
||||
[in the background](/reference/control/in-background).
|
||||
@ -8,7 +8,20 @@ basic.forever(() => {
|
||||
})
|
||||
```
|
||||
|
||||
## Example: compass
|
||||
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
|
||||
|
||||
The following example constantly checks the
|
||||
[compass heading](/reference/input/compass-heading)
|
||||
@ -32,7 +45,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.
|
||||
@ -43,7 +56,7 @@ let num = 0
|
||||
basic.forever(() => {
|
||||
basic.showNumber(num)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
|
||||
num = num + 1
|
||||
})
|
||||
```
|
||||
@ -59,12 +72,12 @@ Try this on your @boardname@:
|
||||
basic.forever(() => {
|
||||
basic.showNumber(6789)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
|
||||
basic.showNumber(2)
|
||||
})
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[while](/blocks/loops/while), [on button pressed](/reference/input/on-button-pressed), [in background](/reference/control/in-background)
|
||||
[while](/blocks/loops/while), [in background](/reference/control/in-background), [every](/reference/loops/every-interval)
|
||||
|
||||
|
@ -24,6 +24,10 @@ 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)
|
||||
|
@ -1,34 +0,0 @@
|
||||
# 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)
|
||||
|
1
docs/reference/basic/rgb.md
Normal file
@ -0,0 +1 @@
|
||||
# RGB
|
1
docs/reference/basic/set-led-color.md
Normal file
@ -0,0 +1 @@
|
||||
# Set LED Color
|
@ -1,64 +0,0 @@
|
||||
# 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.
|
||||
|
||||
## ~
|
@ -1,29 +0,0 @@
|
||||
# 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)
|
1
docs/reference/basic/show-compass.md
Normal file
@ -0,0 +1 @@
|
||||
# Show Compass
|
@ -8,7 +8,7 @@ basic.showNumber(2)
|
||||
|
||||
## Parameters
|
||||
|
||||
* `value` is a [Number](/types/number).
|
||||
* `value` is a [Number](/types/number). If the number is not single-digit number, it will scroll on the display.
|
||||
* `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,6 +37,10 @@ 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.
|
||||
|
1
docs/reference/basic/turn-rgb-led-off.md
Normal file
@ -0,0 +1 @@
|
||||
# Turn RGB Led Off
|
@ -3,6 +3,7 @@
|
||||
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.
|
||||
@ -34,14 +35,6 @@ 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/)
|
||||
@ -56,9 +49,7 @@ 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),
|
||||
[advertiseUrl](/reference/bluetooth/advertise-url),
|
||||
[stopAdvertising](/reference/bluetooth/stop-advertising)
|
||||
[onBluetoothDisconnected](/reference/bluetooth/on-bluetooth-disconnected)
|
||||
|
||||
```package
|
||||
bluetooth
|
||||
|
@ -2,6 +2,18 @@
|
||||
|
||||
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
|
||||
@ -17,10 +29,6 @@ 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).
|
||||
|
@ -2,6 +2,18 @@
|
||||
|
||||
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
|
||||
@ -17,10 +29,6 @@ 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)
|
||||
|
@ -2,6 +2,18 @@
|
||||
|
||||
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
|
||||
@ -17,10 +29,6 @@ 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.
|
||||
|
@ -1,21 +1,50 @@
|
||||
# Bluetooth On UART Data Received
|
||||
|
||||
Registers an event to be fired when one of the delimiter is matched.
|
||||
Runs some code in an event when a delimiter is matched in the received data.
|
||||
|
||||
```sig
|
||||
bluetooth.onUartDataReceived(",", () => {})
|
||||
bluetooth.onUartDataReceived(serial.delimiters(Delimiters.NewLine), function() {})
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
* `delimiters` is a [string](/types/string) containing any of the character to match
|
||||
* **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))
|
||||
```
|
||||
|
||||
### ~
|
||||
|
||||
## Example
|
||||
|
||||
Read values separated by `,`:
|
||||
Read the data items separated by a comma (`,`):
|
||||
|
||||
```blocks
|
||||
bluetooth.onUartDataReceived(serial.delimiters(Delimiters.Comma), () => {
|
||||
basic.showString(serial.readUntil(serial.delimiters(Delimiters.Comma)))
|
||||
bluetooth.onUartDataReceived(serial.delimiters(Delimiters.Comma), function () {
|
||||
basic.showString(bluetooth.uartReadUntil(serial.delimiters(Delimiters.Space)))
|
||||
})
|
||||
```
|
||||
|
||||
```package
|
||||
bluetooth
|
||||
```
|
||||
|
@ -24,7 +24,7 @@ bluetooth.stopAdvertising();
|
||||
## Example: stop advertising on button pressed
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
bluetooth.stopAdvertising();
|
||||
})
|
||||
```
|
||||
|
@ -27,7 +27,7 @@ bluetooth.onBluetoothDisconnected(() => {
|
||||
basic.showString("D");
|
||||
connected = 0;
|
||||
});
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
if (connected == 1) {
|
||||
bluetooth.uartWriteLine("HELLO");
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ bluetooth.onBluetoothDisconnected(() => {
|
||||
basic.showString("D");
|
||||
connected = 0;
|
||||
});
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
if (connected == 1) {
|
||||
bluetooth.uartWriteString("HELLO");
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ Runtime and event utilities.
|
||||
|
||||
```cards
|
||||
control.inBackground(() => {
|
||||
|
||||
|
||||
});
|
||||
control.reset();
|
||||
control.waitMicros(4);
|
||||
|
@ -29,7 +29,7 @@ control.inBackground(() => {
|
||||
basic.pause(100)
|
||||
}
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
num++;
|
||||
})
|
||||
```
|
||||
@ -42,7 +42,7 @@ let num = 0
|
||||
basic.forever(() => {
|
||||
basic.showNumber(num)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
num++;
|
||||
})
|
||||
```
|
||||
|
@ -24,11 +24,11 @@ When you get tired of counting, press button `B` to reset the
|
||||
```blocks
|
||||
let item = 0;
|
||||
basic.showNumber(item);
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
item = item + 1;
|
||||
basic.showNumber(item);
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
control.reset();
|
||||
});
|
||||
```
|
||||
|
@ -1,33 +0,0 @@
|
||||
# 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)
|
@ -1,25 +0,0 @@
|
||||
# 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
|
||||
```
|
@ -1,35 +0,0 @@
|
||||
# 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
|
||||
```
|
@ -1,37 +0,0 @@
|
||||
# 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
|
||||
```
|
@ -1,65 +0,0 @@
|
||||
# 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
|
||||
```
|
@ -1,36 +0,0 @@
|
||||
# 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
|
||||
```
|
@ -1,76 +0,0 @@
|
||||
# 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
|
||||
```
|
@ -1,89 +0,0 @@
|
||||
# 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
|
||||
```
|
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
|
||||
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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
|
||||
})
|
||||
```
|
||||
|
||||
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
|
||||
basic.showString("hello", 150)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
|
||||
basic.showString("goodbye", 150)
|
||||
})
|
||||
```
|
||||
@ -43,7 +43,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
|
||||
basic.showString("hello", 150)
|
||||
basic.showString("goodbye", 150)
|
||||
})
|
||||
|
@ -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.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
basic.showNumber(game.score())
|
||||
game.setScore(0)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
```
|
||||
|
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
game.startCountdown(10000)
|
||||
|
@ -1,19 +1,23 @@
|
||||
# change (Sprite Property)
|
||||
|
||||
Change the kind of [number](/types/number) you say for a [sprite](/reference/game/create-sprite).
|
||||
Change a value for a [sprite](/reference/game/create-sprite) property by some amount.
|
||||
|
||||
```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`` - 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)
|
||||
>* ``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.
|
||||
|
||||
## Example
|
||||
|
||||
|
@ -27,7 +27,7 @@ let img = images.createImage(`
|
||||
. . . . .
|
||||
`)
|
||||
img.showImage(0)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
img.clear()
|
||||
img.showImage(0)
|
||||
})
|
||||
|
@ -14,10 +14,10 @@ If you press button `B`, it shows an animation and ends the game.
|
||||
|
||||
```blocks
|
||||
basic.showString("PICK A BUTTON");
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
basic.showString("YOU WIN!");
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
game.gameOver();
|
||||
});
|
||||
```
|
||||
|
@ -1,6 +1,6 @@
|
||||
# get (Sprite Property)
|
||||
|
||||
Find something out about a [sprite](/reference/game/create-sprite).
|
||||
Get a value for a [sprite](/reference/game/create-sprite) property.
|
||||
|
||||
```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`` - 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)
|
||||
>* ``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.
|
||||
|
||||
## Returns
|
||||
|
||||
|
@ -20,7 +20,7 @@ degrees -- exactly the opposite direction.
|
||||
```blocks
|
||||
let ball = game.createSprite(4, 2);
|
||||
basic.showNumber(ball.get(LedSpriteProperty.Direction));
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
ball.ifOnEdgeBounce();
|
||||
basic.showNumber(ball.get(LedSpriteProperty.Direction));
|
||||
});
|
||||
|
@ -15,7 +15,7 @@ game.isPaused()
|
||||
Resume the game if it's paused and button **B** is pressed.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, function () {
|
||||
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Down), function () {
|
||||
if (game.isPaused()) {
|
||||
game.resume()
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ game.isRunning()
|
||||
If the game is currently running, end the game if button **B** is pressed.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, function () {
|
||||
input.onButtonEvent(Button.B, input.buttonEventClick(), function () {
|
||||
if (game.isRunning()) {
|
||||
game.gameOver()
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ This program adds one point to your score every time you press button
|
||||
second) and shows your score.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
|
||||
game.addScore(1);
|
||||
basic.pause(500);
|
||||
basic.showNumber(game.score());
|
||||
|
@ -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.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, input.buttonEventClick(), () => {
|
||||
basic.showNumber(game.score())
|
||||
game.setScore(0)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
```
|
||||
|
@ -1,6 +1,6 @@
|
||||
# set (Sprite Property)
|
||||
|
||||
Make a [sprite](/reference/game/create-sprite) store the kind of [number](/types/number) you say.
|
||||
Set a value for a [sprite](/reference/game/create-sprite) property.
|
||||
|
||||
```sig
|
||||
game.createSprite(0,0).set(LedSpriteProperty.X, 0);
|
||||
@ -9,22 +9,39 @@ game.createSprite(0,0).set(LedSpriteProperty.X, 0);
|
||||
## Parameters
|
||||
|
||||
* **property**: the property of the **Sprite** you want to store a value for, like:
|
||||
>* ``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)
|
||||
>* ``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.
|
||||
|
||||
## Example
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
```blocks
|
||||
let ball = game.createSprite(0, 2);
|
||||
basic.pause(2000);
|
||||
ball.set(LedSpriteProperty.X, 4);
|
||||
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)
|
||||
})
|
||||
```
|
||||
|
||||
## See also
|
||||
|
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
game.startCountdown(10000)
|
||||
|
@ -19,14 +19,12 @@ 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),
|
||||
[arrowImage](/reference/images/arrow-image), [iconImage](/reference/images/icon-image), [arrowNumber](/reference/images/arrow-number),
|
||||
[iconImage](/reference/images/icon-image),
|
||||
[pixel](/reference/images/pixel), [set-pixel](/reference/images/set-pixel)
|
||||
|
@ -1,41 +0,0 @@
|
||||
# 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)
|
@ -1,33 +0,0 @@
|
||||
# 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)
|
@ -36,10 +36,10 @@ let arrows = images.createBigImage(`
|
||||
. . # . . . # # # .
|
||||
. . # . . . . # . .
|
||||
`);
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
|
||||
arrows.showImage(0);
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, input.buttonEventClick(), () => {
|
||||
arrows.showImage(5);
|
||||
});
|
||||
```
|
||||
|
@ -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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. # # # .
|
||||
@ -34,7 +34,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
. . # . .
|
||||
`).showImage(0);
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, input.buttonEventClick(), () => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
|
@ -20,14 +20,10 @@ 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.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
|
||||
iamHappy.showImage(0);
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, input.buttonEventClick(), () => {
|
||||
iamSad.showImage(0);
|
||||
});
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[arrow image](/reference/images/arrow-image)
|