easy-scratch/doc/scratch-vm/Scratch3MicroBitBlocks.html

2809 lines
92 KiB
HTML
Raw Normal View History

2025-02-12 12:27:32 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Scratch3MicroBitBlocks - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<script src="scripts/nav.js" defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav >
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="-_StackFrame.html">_StackFrame</a><ul class='methods'><li data-type='method'><a href="-_StackFrame.html#.create">create</a></li><li data-type='method'><a href="-_StackFrame.html#.release">release</a></li><li data-type='method'><a href="-_StackFrame.html#reset">reset</a></li><li data-type='method'><a href="-_StackFrame.html#reuse">reuse</a></li></ul></li><li><a href="BLE.html">BLE</a><ul class='methods'><li data-type='method'><a href="BLE.html#connectPeripheral">connectPeripheral</a></li><li data-type='method'><a href="BLE.html#didReceiveCall">didReceiveCall</a></li><li data-type='method'><a href="BLE.html#disconnect">disconnect</a></li><li data-type='method'><a href="BLE.html#handleDisconnectError">handleDisconnectError</a></li><li data-type='method'><a href="BLE.html#isConnected">isConnected</a></li><li data-type='method'><a href="BLE.html#read">read</a></li><li data-type='method'><a href="BLE.html#requestPeripheral">requestPeripheral</a></li><li data-type='method'><a href="BLE.html#startNotifications">startNotifications</a></li><li data-type='method'><a href="BLE.html#write">write</a></li></ul></li><li><a href="BlockCached.html">BlockCached</a></li><li><a href="Blocks.html">Blocks</a><ul class='methods'><li data-type='method'><a href="Blocks.html#_addScript">_addScript</a></li><li data-type='method'><a href="Blocks.html#_deleteScript">_deleteScript</a></li><li data-type='method'><a href="Blocks.html#_getBackdropField">_getBackdropField</a></li><li data-type='method'><a href="Blocks.html#_getBlockParams">_getBlockParams</a></li><li data-type='method'><a href="Blocks.html#_getCostumeField">_getCostumeField</a></li><li data-type='method'><a href="Blocks.html#_getCustomBlockInternal">_getCustomBlockInternal</a></li><li data-type='method'><a href="Blocks.html#_getSoundField">_getSoundField</a></li><li data-type='method'><a href="Blocks.html#_getSpriteField">_getSpriteField</a></li><li data-type='method'><a href="Blocks.html#blocklyListen">blocklyListen</a></li><li data-type='method'><a href="Blocks.html#blockToXML">blockToXML</a></li><li data-type='method'><a href="Blocks.html#changeBlock">changeBlock</a></li><li data-type='method'><a href="Blocks.html#createBlock">createBlock</a></li><li data-type='method'><a href="Blocks.html#deleteBlock">deleteBlock</a></li><li data-type='method'><a href="Blocks.html#emitProjectChanged">emitProjectChanged</a></li><li data-type='method'><a href="Blocks.html#getAllVariableAndListReferences">getAllVariableAndListReferences</a></li><li data-type='method'><a href="Blocks.html#getBlock">getBlock</a></li><li data-type='method'><a href="Blocks.html#getBranch">getBranch</a></li><li data-type='method'><a href="Blocks.html#getFields">getFields</a></li><li data-type='method'><a href="Blocks.html#getInputs">getInputs</a></li><li data-type='method'><a href="Blocks.html#getMutation">getMutation</a></li><li data-type='method'><a href="Blocks.html#getNextBlock">getNextBlock</a></li><li data-type='method'><a href="Blocks.html#getOpcode">getOpcode</a></li><li data-type='method'><a href="Blocks.html#getProcedureDefinition">getProcedureDefinition</a></li><li data-type='method'><a href="Blocks.html#getProcedureParamNamesAndIds">getProcedureParamNamesAndIds</a></li><li data-type='method'><a href="Blocks.html#getProcedureParamNamesIdsAndDefaults">getProcedureParamNamesIdsAndDefaults</a></li><li data-type='method'><a href="Blocks.html#getScripts">getScripts</a></li><li data-type='method'><a href="Blocks.html#getTopLevelScript">getTopLevelScript</a></li><li data-type='method'><a href="Blocks.html#moveBlock">moveBlock</a></li><li data-type='method'><a href="Blocks.html#mutationToXML">mutationToXML</a></li><li data-type='method'><a href="Blocks.html#resetCache">resetCache</a></li><li data-type='method'><a href="Blocks.html#runAllMonitored">runAllMonitored</a></li><li data-type='method'><a href="Blocks.html#toXML">toXML</a></li><li data-type='method'><a href="Blocks.html#updateAssetName">updateAssetName</a></li><li data-type='method'><a href
</nav>
<div id="main">
<h1 class="page-title">Scratch3MicroBitBlocks</h1>
<section>
<header>
<h2>
Scratch3MicroBitBlocks
</h2>
<div class="class-description"><p>Scratch 3.0 blocks to interact with a MicroBit peripheral.</p></div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="Scratch3MicroBitBlocks"><span class="type-signature"></span>new Scratch3MicroBitBlocks<span class="signature">(runtime)</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Construct a set of MicroBit blocks.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>runtime</code></td>
<td class="type">
<span class="param-type"><a href="Runtime.html">Runtime</a></span>
</td>
<td class="description last"><p>the Scratch 3.0 runtime.</p></td>
</tr>
</tbody>
</table>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id=".EXTENSION_ID"><span class="type-signature">(static) </span>EXTENSION_ID<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id=".EXTENSION_NAME"><span class="type-signature">(static) </span>EXTENSION_NAME<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id=".TILT_THRESHOLD"><span class="type-signature">(static) </span>TILT_THRESHOLD<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="BUTTONS_MENU"><span class="type-signature"></span>BUTTONS_MENU<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="GESTURES_MENU"><span class="type-signature"></span>GESTURES_MENU<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="PIN_STATE_MENU"><span class="type-signature"></span>PIN_STATE_MENU<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="runtime"><span class="type-signature"></span>runtime<span class="type-signature"> :<a href="Runtime.html">Runtime</a></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The Scratch 3.0 runtime.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><a href="Runtime.html">Runtime</a></span>
</li>
</ul>
<h4 class="name" id="TILT_DIRECTION_ANY_MENU"><span class="type-signature"></span>TILT_DIRECTION_ANY_MENU<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="TILT_DIRECTION_MENU"><span class="type-signature"></span>TILT_DIRECTION_MENU<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="_getTiltAngle"><span class="type-signature">(private) </span>_getTiltAngle<span class="signature">(direction)</span><span class="type-signature"> &rarr; {number}</span></h4>
<dl class="details">
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>direction</code></td>
<td class="type">
<span class="param-type">TiltDirection</span>
</td>
<td class="description last"><p>the direction (front, back, left, right) to check.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>the tilt sensor's angle in the specified direction.
Note that getTiltAngle(front) = -getTiltAngle(back) and getTiltAngle(left) = -getTiltAngle(right).</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">number</span>
</dd>
</dl>
<h4 class="name" id="_isTilted"><span class="type-signature">(private) </span>_isTilted<span class="signature">(direction)</span><span class="type-signature"> &rarr; {boolean}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Test whether the tilt sensor is currently tilted.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>direction</code></td>
<td class="type">
<span class="param-type">TiltDirection</span>
</td>
<td class="description last"><p>the tilt direction to test (front, back, left, right, or any).</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>true if the tilt sensor is tilted past a threshold in the specified direction.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id="displayClear"><span class="type-signature"></span>displayClear<span class="signature">()</span><span class="type-signature"> &rarr; {Promise}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Turn all 5x5 matrix LEDs off.</p>
</div>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>a Promise that resolves after a tick.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise</span>
</dd>
</dl>
<h4 class="name" id="displaySymbol"><span class="type-signature"></span>displaySymbol<span class="signature">(args)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Display a predefined symbol on the 5x5 LED matrix.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>the block's arguments.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>a Promise that resolves after a tick.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise</span>
</dd>
</dl>
<h4 class="name" id="displayText"><span class="type-signature"></span>displayText<span class="signature">(args)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Display text on the 5x5 LED matrix.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>the block's arguments.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>a Promise that resolves after the text is done printing.
Note the limit is 19 characters
The print time is calculated by multiplying the number of horizontal pixels
by the default scroll delay of 120ms.
The number of horizontal pixels = 6px for each character in the string,
1px before the string, and 5px after the string.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise</span>
</dd>
</dl>
<h4 class="name" id="getInfo"><span class="type-signature"></span>getInfo<span class="signature">()</span><span class="type-signature"> &rarr; {object}</span></h4>
<dl class="details">
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>metadata for this extension and its blocks.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">object</span>
</dd>
</dl>
<h4 class="name" id="getTiltAngle"><span class="type-signature"></span>getTiltAngle<span class="signature">(args)</span><span class="type-signature"> &rarr; {number}</span></h4>
<dl class="details">
</dl>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>DIRECTION</code></td>
<td class="type">
<span class="param-type">TiltDirection</span>
</td>
<td class="description last"><p>the direction (front, back, left, right) to check.</p></td>
</tr>
</tbody>
</table>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>the block's arguments.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>the tilt sensor's angle in the specified direction.
Note that getTiltAngle(front) = -getTiltAngle(back) and getTiltAngle(left) = -getTiltAngle(right).</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">number</span>
</dd>
</dl>
<h4 class="name" id="isButtonPressed"><span class="type-signature"></span>isButtonPressed<span class="signature">(args)</span><span class="type-signature"> &rarr; {boolean}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Test whether the A or B button is pressed</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>the block's arguments.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>true if the button is pressed.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id="isTilted"><span class="type-signature"></span>isTilted<span class="signature">(args)</span><span class="type-signature"> &rarr; {boolean}</span></h4>
<dl class="details">
</dl>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>DIRECTION</code></td>
<td class="type">
<span class="param-type">TiltDirection</span>
</td>
<td class="description last"><p>the tilt direction to test (front, back, left, right, or any).</p></td>
</tr>
</tbody>
</table>
<div class="description">
<p>Test whether the tilt sensor is currently tilted.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>the block's arguments.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>true if the tilt sensor is tilted past a threshold in the specified direction.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id="whenButtonPressed"><span class="type-signature"></span>whenButtonPressed<span class="signature">(args)</span><span class="type-signature"> &rarr; {boolean}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Test whether the A or B button is pressed</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>the block's arguments.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>true if the button is pressed.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id="whenGesture"><span class="type-signature"></span>whenGesture<span class="signature">(args)</span><span class="type-signature"> &rarr; {boolean}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Test whether the micro:bit is moving</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>the block's arguments.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>true if the micro:bit is moving.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id="whenPinConnected"><span class="type-signature">(private) </span>whenPinConnected<span class="signature">(args)</span><span class="type-signature"> &rarr; {boolean}</span></h4>
<dl class="details">
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>the block's arguments.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>the touch pin state.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id="whenTilted"><span class="type-signature"></span>whenTilted<span class="signature">(args)</span><span class="type-signature"> &rarr; {boolean}</span></h4>
<dl class="details">
</dl>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>DIRECTION</code></td>
<td class="type">
<span class="param-type">TiltDirection</span>
</td>
<td class="description last"><p>the tilt direction to test (front, back, left, right, or any).</p></td>
</tr>
</tbody>
</table>
<div class="description">
<p>Test whether the tilt sensor is currently tilted.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>the block's arguments.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>true if the tilt sensor is tilted past a threshold in the specified direction.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>
</body>
</html>