Compare commits

...

97 Commits

Author SHA1 Message Date
5dbbc2266f 0.3.51 2016-08-26 12:17:42 -07:00
2a22001e02 0.3.50 2016-08-26 12:12:32 -07:00
214ff25995 Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-08-26 12:01:14 -07:00
f4768d99ff Merge pull request #220 from Microsoft/parts
adds "parts" annotations
2016-08-26 12:00:59 -07:00
8792f9fe36 0.3.49 2016-08-26 11:56:22 -07:00
3d45bef910 Bump pxt-core to 0.3.56 2016-08-26 11:56:20 -07:00
3de6b33163 added README.md in default blocks target 2016-08-26 09:58:13 -07:00
3f1c03ea51 added search / watch excludes 2016-08-26 09:31:06 -07:00
a4063d636d merging changes 2016-08-26 08:36:49 -07:00
92b5b76171 Add target-specific favicon; see https://github.com/Microsoft/pxt/issues/54 2016-08-26 16:35:13 +02:00
51d285b0b0 Set target-specific avatar; fixes https://github.com/Microsoft/pxt/issues/97 2016-08-26 16:15:58 +02:00
4d8afdd3ae Format 2016-08-26 16:12:22 +02:00
13b21ad275 0.3.48 2016-08-26 15:24:48 +02:00
d90a43a6d8 Bump pxt-core to 0.3.55 2016-08-26 15:24:48 +02:00
6fd14e718d Use the new pxtc namespace 2016-08-26 15:19:04 +02:00
c79f043529 0.3.47 2016-08-26 13:18:35 +02:00
3a676c7151 Bump pxt-core to 0.3.53 2016-08-26 13:18:34 +02:00
0023710209 String/ptr -> boolean helpers added 2016-08-26 13:14:48 +02:00
0756091e8c Remove st/ldglb (no longer used) 2016-08-26 11:09:18 +02:00
8144df0023 0.3.47 2016-08-25 22:19:12 -07:00
b2137e2622 Bump pxt-core to 0.3.52 2016-08-25 22:19:11 -07:00
39b30c8ae1 0.3.46 2016-08-25 16:02:54 -07:00
1c5d6316cc Bump pxt-core to 0.3.51 2016-08-25 16:02:53 -07:00
6d4d681898 Link to pxt package docs 2016-08-25 17:44:53 +02:00
7053fd1490 Ref-counting fix 2016-08-25 15:45:43 +02:00
e7a49acac0 0.3.45 2016-08-24 15:03:29 +03:00
d76cfb6e2e Bump pxt-core to 0.3.49 2016-08-24 15:03:28 +03:00
538f08052d Make Image ref-counted; fixes #171 2016-08-24 15:02:55 +03:00
b6fed71c58 0.3.44 2016-08-24 14:38:50 +03:00
6c86f98b66 Bump pxt-core to 0.3.48 2016-08-24 14:38:50 +03:00
26797545c6 0.3.43 2016-08-24 14:28:20 +03:00
3ce8aa1f47 Bump pxt-core to 0.3.47 2016-08-24 14:28:20 +03:00
8b46698f50 adds "parts" annotations...
...to libs/microbit and libs/microbit-bluetooth
2016-08-22 08:48:48 -07:00
47401e947c Missing a reference to the "Compile" button, changed to Download. 2016-08-19 11:09:12 -07:00
718cc9d530 Add script for running tests as in travis 2016-08-19 13:46:30 +03:00
b83d777144 0.3.42 2016-08-18 16:11:54 -07:00
cfb9acea34 Bump pxt-core to 0.3.46 2016-08-18 16:11:52 -07:00
53189830a1 Merge pull request #207 from Microsoft/microsoftsam/compiletodownload
Converting the term "Compile" to "Download" in the docs
2016-08-18 14:39:29 -07:00
67da22c135 Converting the term "Compile" to "Download" in the docs microsoft/pxt#236 2016-08-18 13:17:05 -07:00
7c7014a25f 0.3.41 2016-08-18 11:57:52 -07:00
851f395ec9 Bump pxt-core to 0.3.45 2016-08-18 11:57:51 -07:00
a343cbd065 0.3.40 2016-08-18 11:24:39 -07:00
a2c042f715 Bump pxt-core to 0.3.43 2016-08-18 11:24:33 -07:00
a4a97f31cb 0.3.39 2016-08-18 18:33:59 +03:00
5bd6a384ae Bump pxt-core to 0.3.42 2016-08-18 18:33:58 +03:00
943393dfa3 updated solution of uploader app 2016-08-18 08:32:36 -07:00
7089aa9c54 Merge pull request #206 from sgk/music-changeTempo-fix
Fix changeTempo() calculation
2016-08-18 07:45:49 -07:00
bd9e456bc5 Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-08-18 07:43:39 -07:00
ea82d066c9 cleaning out old images 2016-08-18 07:23:26 -07:00
bb8338a0f0 launch editor with #uploader tag to notify client that uploader is available 2016-08-18 07:02:19 -07:00
b24b65abcd Call init() before using beatsPerMinute. 2016-08-18 22:19:03 +09:00
2cc0523f9a Fix changeTempo() calculation 2016-08-18 22:13:12 +09:00
a78f7f9601 0.3.38 2016-08-18 15:55:34 +03:00
b1cf3246ae Revert "Use embedded version of microbit to avoid yotta build"
This reverts commit 8eb3376cf5.
2016-08-18 15:55:23 +03:00
24eb6f64db 0.3.37 2016-08-18 15:31:31 +03:00
0c99eaf7bf Bump pxt-core to 0.3.40 2016-08-18 15:31:31 +03:00
8eb3376cf5 Use embedded version of microbit to avoid yotta build 2016-08-18 14:26:56 +03:00
b863d5663d Add buffer shift rotate tests (moved from pxt) 2016-08-18 10:52:19 +03:00
aeb4cb6a17 0.3.36 2016-08-17 23:27:03 -07:00
fd88e0b7f0 Bump pxt-core to 0.3.39 2016-08-17 23:27:00 -07:00
ea0d2d4d02 add i2c fram to package list 2016-08-17 18:23:08 -07:00
adff537013 0.3.35 2016-08-17 17:06:44 -07:00
19fc284884 Bump pxt-core to 0.3.38 2016-08-17 17:06:42 -07:00
5d9f85828d updated blocks template 2016-08-17 17:05:10 -07:00
9f31637000 support for max-duration in pulse-in 2016-08-17 11:35:54 -07:00
8e811b913e adding pins.pulseIn API 2016-08-17 11:18:15 -07:00
269254796d add descriptions 2016-08-17 09:44:15 -07:00
46995cbd54 Adding max6675 package in built-in list 2016-08-17 09:44:08 -07:00
380488528f Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-08-17 08:40:45 -07:00
aca863f436 adding translation docs 2016-08-17 08:39:50 -07:00
a1ec25fd79 0.3.34 2016-08-17 18:09:20 +03:00
3e9d6d5895 Bump pxt-core to 0.3.37 2016-08-17 18:09:19 +03:00
719370f6b0 Use the new lambdas 2016-08-17 18:08:46 +03:00
2780497d4f 0.3.33 2016-08-17 17:15:09 +03:00
3eeaf2eddc Bump pxt-core to 0.3.36 2016-08-17 17:15:09 +03:00
eb3e91420c 0.3.32 2016-08-17 15:09:56 +03:00
38cd913020 Bump pxt-core to 0.3.35 2016-08-17 15:08:24 +03:00
9159c297a5 added wait-micros function 2016-08-16 17:04:21 -07:00
851687dba8 0.3.31 2016-08-16 13:44:38 -07:00
28b8006ec5 removing spurious logging 2016-08-16 10:11:55 -07:00
271128c075 answering questions about saving 2016-08-16 09:21:41 -07:00
a04ca0d715 0.3.30 2016-08-16 07:46:43 -07:00
8b89fe721d Bump pxt-core to 0.3.34 2016-08-16 07:46:39 -07:00
1baf04b1fd added links to packages 2016-08-15 23:16:10 -07:00
6c7f0f911c 0.3.29 2016-08-15 15:44:05 -07:00
f2008f9263 Bump pxt-core to 0.3.33 2016-08-15 15:44:03 -07:00
62127f7269 Updated VS code instructions 2016-08-15 11:03:03 -07:00
740cedd978 added docs 2016-08-12 16:15:41 -07:00
4278ff2b37 0.3.28 2016-08-12 08:36:34 -07:00
e7bea34d95 Bump pxt-core to 0.3.32 2016-08-12 08:36:33 -07:00
825409b697 0.3.27 2016-08-12 04:03:06 -07:00
8f72ac0094 Bump pxt-core to 0.3.31 2016-08-12 04:03:03 -07:00
8a6bb610e3 updated description 2016-08-12 03:37:27 -07:00
94dc141062 0.3.26 2016-08-11 16:33:03 -07:00
286dd1e50b Bump pxt-core to 0.3.29 2016-08-11 16:33:00 -07:00
6451d9add9 0.3.25 2016-08-11 16:24:34 -07:00
fd1dcde86b Bump pxt-core to 0.3.28 2016-08-11 16:24:30 -07:00
66 changed files with 709 additions and 184 deletions

15
.vscode/settings.json vendored
View File

@ -1,5 +1,20 @@
// Place your settings in this file to overwrite default and user settings.
{
"file.autoSave": "afterDelay",
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/built/**": true,
"**/node_modules/**": true,
"**/yotta_modules/**": true,
"**/yotta_targets": true,
"**/pxt_modules/**": true
},
"search.exclude": {
"**/node_modules": true,
"**/yotta_modules/**": true,
"**/yotta_targets": true,
"**/pxt_modules/**": true
},
"tslint.enable": true,
"tslint.rulesDirectory": "node_modules/tslint-microsoft-contrib"
}

View File

@ -5,8 +5,6 @@ VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeTheMicrobit", "Microbit.Uploader\CodeTheMicrobit.csproj", "{7DC6CA45-FD75-44BC-805E-708C812CD4BF}"
EndProject
Project("{262852C6-CD72-467D-83FE-5EEB1973A190}") = "codethemicrobitapp", "..\win10\app\codethemicrobitapp.jsproj", "{39122940-AB16-4CD4-A0CE-79A3EB863ECF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -35,30 +33,6 @@ Global
{7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Release|x64.Build.0 = Release|Any CPU
{7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Release|x86.ActiveCfg = Release|Any CPU
{7DC6CA45-FD75-44BC-805E-708C812CD4BF}.Release|x86.Build.0 = Release|Any CPU
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|ARM.ActiveCfg = Debug|ARM
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|ARM.Build.0 = Debug|ARM
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|ARM.Deploy.0 = Debug|ARM
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|x64.ActiveCfg = Debug|x64
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|x64.Build.0 = Debug|x64
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|x64.Deploy.0 = Debug|x64
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|x86.ActiveCfg = Debug|x86
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|x86.Build.0 = Debug|x86
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Debug|x86.Deploy.0 = Debug|x86
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|Any CPU.Build.0 = Release|Any CPU
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|Any CPU.Deploy.0 = Release|Any CPU
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|ARM.ActiveCfg = Release|ARM
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|ARM.Build.0 = Release|ARM
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|ARM.Deploy.0 = Release|ARM
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|x64.ActiveCfg = Release|x64
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|x64.Build.0 = Release|x64
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|x64.Deploy.0 = Release|x64
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|x86.ActiveCfg = Release|x86
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|x86.Build.0 = Release|x86
{39122940-AB16-4CD4-A0CE-79A3EB863ECF}.Release|x86.Deploy.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -14,7 +14,7 @@ namespace Microsoft.MicroBit
public LicenseDialog()
{
InitializeComponent();
this.textBox.Rtf = Resources.MSR_LA___2576;
this.textBox.Text = Resources.MSR_LA___2576;
}
private void acceptButton_Click(object sender, EventArgs e)

View File

@ -32,7 +32,7 @@ namespace Microsoft.MicroBit
private void openEditor()
{
// lanch editor
try { Process.Start("https://codethemicrobit.com"); } catch (Exception) { }
try { Process.Start("https://codethemicrobit.com#uploader"); } catch (Exception) { }
}
private void initializeFileWatch()

View File

@ -34,7 +34,7 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.0.0")]
[assembly: AssemblyFileVersion("0.9.0.0")]
[assembly: AssemblyVersion("0.10.0.0")]
[assembly: AssemblyFileVersion("0.10.0.0")]
[assembly: CLSCompliant(true)]
[assembly: NeutralResourcesLanguage("en-US")]

View File

@ -81,8 +81,7 @@ namespace Microsoft.MicroBit.Properties {
}
/// <summary>
/// Looks up a localized string similar to {\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff0\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f1\fbidi \fswiss\fcharset0\fprq2{\*\panose 020b0604020202020204}Arial;}
///{\f2\fbidi \fmodern\fcharset0\fprq1{\*\panose 02070309020205020404}Courier New;}{\f3\fbidi \froman\fcharset2\fprq2{\*\panose 05050102010706020507}Symbol;}{\f10\fbidi \fnil\fcharset2\fp [rest of string was truncated]&quot;;.
/// Looks up a localized string similar to TBD.
/// </summary>
internal static string MSR_LA___2576 {
get {

View File

@ -118,13 +118,13 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="MSR_LA___2576" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\MSR-LA - 2576.rtf;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<data name="microbit_red" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\microbit.red.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="MSFT_logo_png" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\MSFT_logo_png.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="microbit_red" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\microbit.red.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="MSR_LA___2576" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\MSR-LA - 2576.rtf;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
</root>

View File

@ -9,16 +9,16 @@ let execAsync: (cmd: string, options?: { cwd?: string }) => Promise<Buffer> = Pr
let readDirAsync = Promise.promisify(fs.readdir)
export function deployCoreAsync(res: ts.pxt.CompileResult) {
export function deployCoreAsync(res: pxtc.CompileResult) {
return getBitDrivesAsync()
.then(drives => {
if (drives.length == 0) {
console.log("cannot find any drives to deploy to")
} else {
console.log(`copy ${ts.pxt.BINARY_HEX} to ` + drives.join(", "))
console.log(`copy ${pxtc.BINARY_HEX} to ` + drives.join(", "))
}
return Promise.map(drives, d =>
writeFileAsync(d + ts.pxt.BINARY_HEX, res.outfiles[ts.pxt.BINARY_HEX])
writeFileAsync(d + pxtc.BINARY_HEX, res.outfiles[pxtc.BINARY_HEX])
.then(() => {
console.log("wrote hex file to " + d)
}))

View File

@ -23,6 +23,8 @@ input.onButtonPressed(Button.B, () => {
```
# About
### @description A Blocks / Javascript code editor for the micro:bit, a pocket-size computer with 5x5 display, sensors and Bluetooth.
The [BBC micro:bit](https://www.microbit.co.uk) is a [pocket-size computer](/device) with a 5x5 display of 25 LEDs, Bluetooth and sensors that can be programmed by anyone.
The BBC micro:bit was made possible by many [partners](https://www.microbit.co.uk/partners).

View File

@ -1,5 +1,7 @@
# Blocks language
### @description Langugage constructs for the Block editor.
```namespaces
for (let i = 0;i<5;++i) {}
if (true){}

54
docs/code.md Normal file
View File

@ -0,0 +1,54 @@
# Visual Studio Code
Visual Studio Code is a Free Open Source code editor that you can use to edit your programs.
Working from Visual Studio code allows you to benefit from all the features
of a professional IDE while working with PXT: working with files,
git integration (or source control of your choice), hundreds of extensions.
![](https://code.visualstudio.com/home/home-screenshot-win-lg.png)
## Setup
Follow these instructions to setup your machine and edit your programs in Visual Studio Code.
* install [Visual Studio Code](https://code.visualstudio.com/)
* install [Node.JS](https://nodejs.org/en/)
* install the PXT Tools (on Mac or Linux, you might have to add ``sudo`` to the command).
```
pxt install -g pxt
```
* create a folder for your projects
```
mkdir microbit
```
* install the microbit target
```
pxt target microbit
```
That's it! You are ready to create new projects in code or open existing projects.
## Creating a new project
Open a shell to your ``microbit`` folder.
```
# create a new subfolder for your project
mkdir myproject
cd myproject
# start the project set
pxt init
# open code
code .
```
## Opening an existing project
You can extract a project from the embedded URL or .hex file. Open a shell to your projects folder
```
# extract the project from the URL
pxt extract EMBEDURL
```
where ``EMBEDURL`` is the published project URL.

View File

@ -9,7 +9,15 @@ Below is a list of error numbers and what they mean:
* **10** (`MICROBIT_I2C_LOCKUP`): the micro:bit's I2C bus is not working
* **20** (`MICROBIT_OOM`): there is no free memory on the micro:bit
![](/static/mb/device/error-codes-0.png)
```sim
basic.showLeds(`
# . . . #
# # . # #
. . . . .
. # # # .
# . . . #
`)
```
### See also

View File

@ -40,7 +40,7 @@ Next, compile your script:
2. Open your script (find the script in **My Scripts** and click `Edit`).
3. Click `compile`. Your script is converted into a hex file that you can transfer and run on your micro:bit.
3. Click **Download**. Your script is converted into a hex file that you can transfer and run on your micro:bit.
4. When prompted, choose to save the compiled file on your computer (or anywhere other than the micro:bit). Depending on which browser you are using, the download will adopt the download behaviour of that particular browser.
@ -66,13 +66,13 @@ A dialogue box will appear, asking whether you would like to open or save your h
**IE10**
Click on compile. You will see a message “Do you want to save this .hex file.” Select **Save**.
Click on **Download**. You will see a message “Do you want to save this .hex file.” Select **Save**.
### Mac
** Safari**
When you select **compile** in Safari on Mac, your file will be downloaded to your downloads folder. Go to your downloads folder and open the file. In Safari the file will appear as unknown.txt rather than a named .hex file. Drag and drop it onto your MICROBIT drive.
When you select **Download** in Safari on Mac, your file will be downloaded to your downloads folder. Go to your downloads folder and open the file. In Safari the file will appear as unknown.txt rather than a named .hex file. Drag and drop it onto your MICROBIT drive.
![](/static/mb/device/usb-4.jpg)
@ -86,7 +86,7 @@ A dialogue box will appear, asking whether you would like to open or save your h
**Chrome**
When you select **compile** in Chrome, the file will be downloaded to the bottom of the browser in .hex format. Click on the small arrow and select **Show in Finder**. This will show the file in your download folder. Drag and drop the file onto your MICROBIT drive.
When you select **Download** in Chrome, the file will be downloaded to the bottom of the browser in .hex format. Click on the small arrow and select **Show in Finder**. This will show the file in your download folder. Drag and drop the file onto your MICROBIT drive.
![](/static/mb/device/usb-7.jpg)

View File

@ -1,5 +1,7 @@
# Documentation
### @description Links to the documentation, reference and projects.
### Things to do
* **[Getting Started](/getting-started)**
@ -19,6 +21,7 @@
### More questions?
* [Frequently Asked Question](/faq)
* [Help Translate](/translate)
* [Release notes](/release-notes)
### Developers

View File

@ -1,9 +1,30 @@
# Frequently Asked Questions
### @description Frequently asked questions and answers from our users.
### Where can I get a BBC micro:bit?
More information at [http://uk.farnell.com/bbc-microbit](http://uk.farnell.com/bbc-microbit).
### How do I send feedback?
Find the small bubble icon on the bottom of the editor and
post your feedback from there!
### How do I save my code?
The web editor automatically saves your code in the browser cache. Simply reopen the browser and navigate to the web editor
to reopen your latest project. You can also open previous project stored locally through **More -> Open Project**.
The project source is also stored in each compiled ``.hex`` file. Drag and drop the ``.hex`` file into the web editor to load the project.
To share your project with others, you can use the **Embed** feature. It stores your project in the cloud and creates a URL that you can share with others.
If you are using [Visual Studio Code](/code), all your programs are stored as files on your computer and you can use your favorite source control system as needed.
## Is the web site available in other languages?
You can [help us translate](/translate) the web site, documentation and blocks via our crowd-source translations!
## Troubleshooting

BIN
docs/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1,5 +1,7 @@
# Getting started
### @description An activity for beginners to get started with the micro:bit
## ~avatar
Here are some challenges for you. Arrange the blocks in the editor
@ -33,7 +35,7 @@ When this program runs, you will see a smiley face, then a blank
screen, then a smiley again -- it never stops! (That's because of the
``forever`` block.)
Click **Compile** to move your program to the BBC micro:bit!
Click **Download** to move your program to the BBC micro:bit!
Make sure to follow the instructions.
### ~button /getting-started/screen

View File

@ -37,7 +37,7 @@ You can find the letter `B` by clicking the letter `A` on the
#### ~
Click **Compile** to move your program to the BBC micro:bit!
Click **Download** to move your program to the BBC micro:bit!
#### Your turn!
@ -65,7 +65,7 @@ input.onPinPressed(TouchPin.P0, () => {
. . # . .`);
});
```
Click **Compile** to move your program to the BBC micro:bit!
Click **Download** to move your program to the BBC micro:bit!
## ~hint

View File

@ -152,7 +152,7 @@ That's why you can use an ``else`` instead of an ``else if``.
Your game is ready!
Click **Compile** to move your program to the BBC micro:bit!
Click **Download** to move your program to the BBC micro:bit!
Have fun!
@ -198,7 +198,7 @@ input.onButtonPressed(Button.B, () => {
basic.showNumber(game.score())
})
```
Click **Compile** to move your program to the BBC micro:bit!
Click **Download** to move your program to the BBC micro:bit!
### ~button /projects
NEXT: PROJECTS!

View File

@ -32,7 +32,7 @@ basic.forever(() => {
`)
});
```
Click **Compile** to move your program to the BBC micro:bit!
Click **Download** to move your program to the BBC micro:bit!
### Your turn!
@ -85,7 +85,7 @@ basic.forever(() => {
`)
});
```
Click **Compile** to move your program to the BBC micro:bit!
Click **Download** to move your program to the BBC micro:bit!
#### ~hint

View File

@ -17,7 +17,7 @@ input.onGesture(Gesture.Shake, () => {
# . . . #`);
});
```
Click **Compile** to move your program to the BBC micro:bit!
Click **Download** to move your program to the BBC micro:bit!
### ~button /getting-started/coin-flipper
NEXT: COIN FLIPPER GAME

View File

@ -1,4 +1,4 @@
# JavaScript and TypeScript
# JavaScript
Visit the cards below to starting programming JavaScript and TypeScript with the micro:bit:

View File

@ -1,5 +1,7 @@
# Lessons
### @description Lessons to teach computer science and coding.
### @short Lessons
### ~column

View File

@ -42,7 +42,7 @@ We want the message "Press A!" to scroll across the BBC micro:bit, so right-clic
![](/static/mb/blocks/lessons/blocks-conditions-2.png)
So, to recap: the `forever` block makes sure our code runs forever. The BBC micro:bit checks if the user is pressing the left button, if the user is not then the “Press the button!” message will scroll across the LEDs. If the user is pressing the button then the “hello, world!” message will scroll across the screen. Check this in the simulator or attach the BBC micro:bit to the computer then click **compile** to send the code onto the BBC micro:bit.
So, to recap: the `forever` block makes sure our code runs forever. The BBC micro:bit checks if the user is pressing the left button, if the user is not then the “Press the button!” message will scroll across the LEDs. If the user is pressing the button then the “hello, world!” message will scroll across the screen. Check this in the simulator or attach the BBC micro:bit to the computer then click **Download** to send the code onto the BBC micro:bit.
## What is a condition?

View File

@ -92,7 +92,7 @@ Connect a micro:bit to your computer using your USB cable
![](/static/mb/lessons/seismograph33.png)
Click or tap the compile button for the seismograph program to run the program on the micro:bit.
Click or tap the **Download** button for the seismograph program to run the program on the micro:bit.
![](/static/mb/lessons/seismograph22.png)

View File

@ -116,7 +116,7 @@ Connect the 2nd micro:bit to your computer using your USB cable. We should have
## 8.
Click or tap the compile button for the seismograph program to run the program on the 1st micro:bit and 2nd micro:bit.
Click or tap the **Download** button for the seismograph program to run the program on the 1st micro:bit and 2nd micro:bit.
## 9.

View File

@ -2,7 +2,7 @@
The editor is open source on GitHub under the MIT license. Contributions are welcome, please check our GitHub repos.
### Source Code
## Source Code
* [microsoft/pxt-microbit](https://github.com/Microsoft/pxt-microbit), PXT target for BBC micro:bit, also includes the documentation.
* [microbit/pxt](https://github.com/Microsoft/pxt), programming experience toolkit (PXT)
@ -12,3 +12,8 @@ The editor is open source on GitHub under the MIT license. Contributions are wel
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).
## Packages
* [microsoft/pxt-neopixel](https://github.com/microsoft/pxt-neopixel), package for neopixel strips
* [microsoft/pxt-max6675](https://github.com/microsoft/pxt-max6675), package for Temperature Probe (MAX6675)

View File

@ -1,14 +1,19 @@
# Extensions
# Packages
You can publish libraries (also known as packages or extensions)
that users can then add to their scripts. These typically
provide a driver for a particular hardware device you can connect
to a microbit.
* [pxt-max6675](https://github.com/Microsoft/pxt-max6675) -- TypeScript
* [pxt-neopixel](https://github.com/Microsoft/pxt-neopixel) -- TypeScript + ARM Thumb assembly package
* [pxt-sonar](https://github.com/microsoft/pxt-sonar) -- TypeScript
* [pxt-i2c-fram](https://github.com/microsoft/pxt-i2c-fram) -- TypeScript
* [Sample C++ extension](https://github.com/Microsoft/pxt-microbit-cppsample)
* [Sample TypeScript extension](https://github.com/Microsoft/pxt-microbit/tree/master/libs/i2c-fram)
## Finding libraries
## Finding packages
From the editor, the user clicks on **More** then **Add Package** and searches for the package.
@ -16,11 +21,11 @@ To see the list of packages, click on **More** then **Show Files** to see the pr
To remove a package, click on the garbage button in the file list next to the package.
## Publishing libraries
## Publishing packages
Packages can be published from the pxt command line. We are still sorting out the details.
Packages can be published from the pxt command line. Check out [the docs](https://www.pxt.io/packages).
## Localizing libraries
## Localizing packages
It is possible to package localization strings for the **jsDoc** description associated to the API in the package.

View File

@ -69,7 +69,7 @@ input.onButtonPressed(Button.A, () => {
});
```
* click *compile* and run your code on the micro:bit.
* click **Download** and run your code on the micro:bit.
### ~button /projects/banana-keyboard
NEXT: Banana Keyboard

View File

@ -29,7 +29,7 @@ radio.onDataReceived(() => {
})
```
Compile the program and **upload the same .hex file to 2 devices!**
Download the program and **upload the same .hex file to 2 devices!**
## Step 3

View File

@ -1,5 +1,7 @@
# Reference
### @description List of API categories available in the editors
```namespaces
basic.showNumber(0);
input.onButtonPressed(Button.A, () => {

View File

@ -7,8 +7,9 @@ control.inBackground(() => {
});
control.reset();
control.waitMicros(4);
```
### See Also
[inBackground](/reference/control/in-background), [reset](/reference/control/reset)
[inBackground](/reference/control/in-background), [reset](/reference/control/reset), [wait-micros](/reference/control/wait-micros)

View File

@ -0,0 +1,32 @@
# WaitMicros
Blocks the current fiber for the given amount of micro-seconds.
```sig
control.waitMicros(4)
```
### Example
This program sends a 10 micro-second HIGH pulse through pin ``P0``.
```blocks
// ensure pin is low to send a clean pulse
pins.digitalWritePin(DigitalPin.P0, 0)
control.waitMicros(2)
// set pin to 1 and wait 10 micros
pins.digitalWritePin(DigitalPin.P0, 1)
control.waitMicros(10)
// finish pulse
pins.digitalWritePin(DigitalPin.P0, 0)
```
#### ~hint
This function is not supported in the simulator.
#### ~
### See Also
[pause](/reference/basic/pause)

View File

@ -13,6 +13,7 @@ pins.onPulsed(DigitalPin.P0, PulseValue.High, () => {
});
pins.pulseDuration();
pins.pulseIn(DigitalPin.P0, PulseValue.High);
pins.servoWritePin(AnalogPin.P0, 180);
pins.servoSetPulse(AnalogPin.P0, 1500);
pins.i2cReadNumber(0, NumberFormat.Int8LE);
@ -25,4 +26,4 @@ pins.analogSetPitchPin(AnalogPin.P0);
### See Also
[digitalReadPin](/reference/pins/digital-read-pin), [digitalWritePin](/reference/pins/digital-write-pin), [analogReadPin](/reference/pins/analog-read-pin), [analogWritePin](/reference/pins/analog-write-pin), [analogSetPeriod](/reference/pins/analog-set-period), [map](/reference/pins/map), [onPulsed](/reference/pins/on-pulsed), [pulseDuration](/reference/pins/pulse-duration), [servoWritePin](/reference/pins/servo-write-pin), [servoSetPulse](/reference/pins/servo-set-pulse), [i2cReadNumber](/reference/pins/i2c-read-number), [i2cWriteNumber](/reference/pins/i2c-write-number), [setPull](/reference/pins/set-pull), [analogPitch](/reference/pins/analog-pitch), [analogSetPitchPin](/reference/pins/analog-set-pitch), [spiWrite](/reference/pins/spi-write)
[digitalReadPin](/reference/pins/digital-read-pin), [digitalWritePin](/reference/pins/digital-write-pin), [analogReadPin](/reference/pins/analog-read-pin), [analogWritePin](/reference/pins/analog-write-pin), [analogSetPeriod](/reference/pins/analog-set-period), [map](/reference/pins/map), [onPulsed](/reference/pins/on-pulsed), [pulseDuration](/reference/pins/pulse-duration), [pulseIn](/reference/pins/pulse-in), [servoWritePin](/reference/pins/servo-write-pin), [servoSetPulse](/reference/pins/servo-set-pulse), [i2cReadNumber](/reference/pins/i2c-read-number), [i2cWriteNumber](/reference/pins/i2c-write-number), [setPull](/reference/pins/set-pull), [analogPitch](/reference/pins/analog-pitch), [analogSetPitchPin](/reference/pins/analog-set-pitch), [spiWrite](/reference/pins/spi-write)

View File

@ -27,6 +27,12 @@ format from the 7-bit I2C address `32`.
pins.i2cReadNumber(32, NumberFormat.UInt16BE);
```
#### ~hint
This function is not supported in the simulator.
#### ~
### See also
[I2C](https://en.wikipedia.org/wiki/I%C2%B2C)

View File

@ -27,6 +27,13 @@ address `32` in big-endian 32-bit integer format.
```blocks
pins.i2cWriteNumber(32, 2055, NumberFormat.Int32BE);
```
#### ~hint
This function is not supported in the simulator.
#### ~
### See also
[I2C](https://en.wikipedia.org/wiki/I%C2%B2C)

View File

@ -0,0 +1,54 @@
# Pulse In
Returns the duration of a pulse (high or low) from a [pin](/device/pins) on
the micro:bit board in microseconds.
```sig
pins.pulseIn(DigitalPin.P0, PulseValue.High)
```
### ~avatar
Some pins are also used by the [LED screen](/device/screen).
Please read the [page about pins](/device/pins) carefully.
### ~
### Parameters
* ``name`` is a [string](/reference/types/string) that stores the name of the pin (``P0``, ``P1``, or ``P2``, up through ``P20``)
* ``value`` is the value of the pulse, ``high`` or ``low``
* ``maxDuration``, maximum duration in micro-seconds. If no pulse is received
### Returns
* a [number](/reference/types/number) that represents the pulse duration in micro-seconds
### Example: Measuring distance with a sonar
The following script sends a pulse on ``P0`` and reads the pulse returned by a HC-SR04 sonar to determine the distance of the object in front of the sensor.
```blocks
basic.forever(() => {
// send pulse
pins.digitalWritePin(DigitalPin.P0, 0)
control.waitMicros(2)
pins.digitalWritePin(DigitalPin.P0, 1)
control.waitMicros(10)
pins.digitalWritePin(DigitalPin.P0, 0)
// read pulse
led.plotBarGraph(pins.pulseIn(DigitalPin.P1, PulseValue.High) / 58, 0)
basic.pause(100)
})
```
#### ~hint
This function is not supported in the simulator.
#### ~
### See also
[digital write pin](/reference/pins/digital-write-pin),

View File

@ -1,9 +1,16 @@
# Release notes
### @description Editor release notes
```sim
basic.forever(() => { basic.showString("RELEASE NOTES"); });
```
## August 2016
* The JavaScript editor is using Monaco
* New [package system](/packages) based on GitHub
## June 2016
* It is now possible to stream data into the cloud (Azure) from the PXT editor. Simply click on the log view to get started.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 284 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

View File

@ -1,3 +1,5 @@
# Support
Please use the [GitHub issue tracker](https://github.com/microsoft/pxt-microbit) to report bugs.
Send us your feedback and ideas on our [User Voice Forum](https://touchdevelop.uservoice.com/forums/402381-code-the-micro-bit/).
You can also use our [GitHub issue tracker](https://github.com/microsoft/pxt-microbit) to report bugs.

28
docs/translate.md Normal file
View File

@ -0,0 +1,28 @@
# Help translate
Our translations are managed via Crowdin, a translation management platform. It is free to join
and you can volunteer to translate parts of the web site.
## Translating the editor interface
The project below contains the resources from https://www.pxt.io and the menu items of https://codethemicrobit.com.
* [https://crowdin.com/project/kindscript](https://crowdin.com/project/kindscript)
You will find two files in that project:
* ``string.json``: text contained in the menu items of https://codethemicrobit.com
* ``website.json``: text contained in the pages served by https://www.pxt.io
## Translating the blocks and reference documentation
The project below contains the resources from the blocks and functions using in the https://codethemicrobit.com.
* [https://crowdin.com/project/pxt-microbit](https://crowdin.com/project/pxt-microbit)
You will find two files for each package available in the micro:bit, one for the block definition and one for the descriptions:
* ``microbit-strings.json``: contains the block definitions
* ``microbit-jsdoc-strings.json``: contains the descriptions
The block definition should be carefully translated using the [block definition syntax](https://www.pxt.io/defining-blocks).

View File

@ -1,5 +1,7 @@
# Uploader
### @description A Windows application that automatically deploys .hex files to connected micro:bit boards
### ~avatar avatar
The Uploader **automatically** deploys .hex files to all micro:bits connected to your computer.

View File

@ -1,21 +1,28 @@
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@codethemicrobit" />
<meta name="twitter:title" content="@name@" />
<meta name="twitter:description" content="@description@" />
<meta name="twitter:image" content="@cardLogo@" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@codethemicrobit" />
<meta name="twitter:title" content="@name@" />
<meta name="twitter:description" content="@description@" />
<meta name="twitter:image" content="@cardLogo@" />
<meta property="og:title" content="@name@" />
<meta property="og:site_name" content="code the micro:bit" />
<meta property="og:description" content="@description@" />
<meta property="og:image" content="@cardLogo@" />
<!--
<meta property="og:title" content="@name@" />
<meta property="og:site_name" content="code the micro:bit" />
<meta property="og:description" content="@description@" />
<meta property="og:image" content="@cardLogo@" />
<!--
<meta property="og:type" content="website" />
<meta property="fb:app_id" content="" />
-->
<link rel="apple-touch-icon" href="@appLogo@">
<link rel="icon" type="image/png" href="@appLogo@">
<link rel="mask-icon" href="https://az851932.vo.msecnd.net/pub/zwxazere/safari-pinned-tab.svg" color="#000000">
<link rel="shortcut icon" href="@appLogo@">
<meta name="theme-color" content="@accentColor@">
<link rel="apple-touch-icon" href="@appLogo@">
<link rel="icon" type="image/png" href="@appLogo@">
<link rel="mask-icon" href="https://az851932.vo.msecnd.net/pub/zwxazere/safari-pinned-tab.svg" color="#000000">
<link rel="shortcut icon" href="@appLogo@">
<meta name="theme-color" content="@accentColor@">
<style>
#root .avatar .avatar-image {
background-image: url(https://az851932.vo.msecnd.net/pub/jovrytni/microbit.simplified.svg);
background-size: contain;
background-repeat: no-repeat;
}
</style>

View File

@ -22,6 +22,7 @@ console.log("Starting...")
basic.showNumber(0);
testBuffer()
testBufferShiftRotate()
basic.showNumber(2);
console.log("ALL TESTS OK")
@ -75,3 +76,63 @@ function testBuffer() {
b.shift(-1)
bufferIs(b, [0, 4, 13]);
}
function testBufferShiftRotate() {
let b = pins.createBuffer(5);
function initb() {
for (let i = 0; i < b.length; ++i) {
b[i] = i;
}
}
function assertb(ex: number[]) {
bufferIs(b, ex)
}
initb()
assertb([0, 1, 2, 3, 4])
//shifting
initb()
b.shift(-1);
assertb([0, 0, 1, 2, 3])
initb()
b.shift(-1, 0, 3);
assertb([0, 0, 1, 3, 4])
initb()
b.shift(-1, 1, 3);
assertb([0, 0, 1, 2, 4])
initb()
b.shift(1)
assertb([1, 2, 3, 4, 0])
initb()
b.shift(1, 1, 3)
assertb([0, 2, 3, 0, 4])
//rotating
initb()
b.rotate(-1);
assertb([4, 0, 1, 2, 3])
initb()
b.rotate(-1, 0, 3);
assertb([2, 0, 1, 3, 4])
initb()
b.rotate(-1, 1, 3);
assertb([0, 3, 1, 2, 4])
initb()
b.rotate(2)
assertb([2, 3, 4, 0, 1])
initb()
b.rotate(1, 1, 3)
assertb([0, 2, 3, 1, 4])
}

View File

@ -32,6 +32,7 @@ namespace bluetooth {
*/
//% help=bluetooth/start-io-pin-service
//% blockId=bluetooth_start_io_pin_service block="bluetooth io pin service" blockGap=8
//% parts="bluetooth"
void startIOPinService() {
new MicroBitIOPinService(*uBit.ble, uBit.io);
}
@ -41,6 +42,7 @@ namespace bluetooth {
*/
//% help=bluetooth/start-led-service
//% blockId=bluetooth_start_led_service block="bluetooth led service" blockGap=8
//% parts="bluetooth"
void startLEDService() {
new MicroBitLEDService(*uBit.ble, uBit.display);
}
@ -50,6 +52,7 @@ namespace bluetooth {
*/
//% help=bluetooth/start-temperature-service
//% blockId=bluetooth_start_temperature_service block="bluetooth temperature service" blockGap=8
//% parts="bluetooth"
void startTemperatureService() {
new MicroBitTemperatureService(*uBit.ble, uBit.thermometer);
}
@ -59,6 +62,7 @@ namespace bluetooth {
*/
//% help=bluetooth/start-magnetometer-service
//% blockId=bluetooth_start_magnetometer_service block="bluetooth magnetometer service" blockGap=8
//% parts="bluetooth"
void startMagnetometerService() {
new MicroBitMagnetometerService(*uBit.ble, uBit.compass);
}
@ -68,6 +72,7 @@ namespace bluetooth {
*/
//% help=bluetooth/start-accelerometer-service
//% blockId=bluetooth_start_accelerometer_service block="bluetooth accelerometer service" blockGap=8
//% parts="bluetooth"
void startAccelerometerService() {
new MicroBitAccelerometerService(*uBit.ble, uBit.accelerometer);
}
@ -77,6 +82,7 @@ namespace bluetooth {
*/
//% help=bluetooth/start-button-service
//% blockId=bluetooth_start_button_service block="bluetooth button service" blockGap=8
//% parts="bluetooth"
void startButtonService() {
new MicroBitButtonService(*uBit.ble);
}
@ -86,6 +92,7 @@ namespace bluetooth {
*/
//% help=bluetooth/start-uart-service
//% blockId=bluetooth_start_uart_service block="bluetooth uart service" blockGap=8
//% parts="bluetooth"
void startUartService() {
if (uart) return;
// 61 octet buffer size is 3 x (MTU - 3) + 1
@ -99,6 +106,7 @@ namespace bluetooth {
*/
//% help=bluetooth/uart-write
//% blockId=bluetooth_uart_write block="bluetooth uart write %data" blockGap=8
//% parts="bluetooth"
void uartWrite(StringData *data) {
startUartService();
uart->send(ManagedString(data));
@ -109,6 +117,7 @@ namespace bluetooth {
*/
//% help=bluetooth/uart-read
//% blockId=bluetooth_uart_read block="bluetooth uart read %del=bluetooth_uart_delimiter_conv" blockGap=8
//% parts="bluetooth"
StringData* uartRead(StringData *del) {
startUartService();
return uart->readUntil(ManagedString(del)).leakData();
@ -119,6 +128,7 @@ namespace bluetooth {
*/
//% blockId="bluetooth_uart_delimiter_conv" block="%del"
//% weight=1
//% parts="bluetooth"
StringData* delimiters(Delimiters del) {
ManagedString c("\n\n,$:.#"[max(0, min(6, (int)del))]);
return c.leakData();
@ -129,6 +139,7 @@ namespace bluetooth {
*/
//% help=bluetooth/on-bluetooth-connected weight=20
//% blockId=bluetooth_on_connected block="on bluetooth connected" blockGap=8
//% parts="bluetooth"
void onBluetoothConnected(Action body) {
registerWithDal(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, body);
}
@ -139,6 +150,7 @@ namespace bluetooth {
*/
//% help=bluetooth/on-bluetooth-disconnected weight=19
//% blockId=bluetooth_on_disconnected block="on bluetooth disconnected"
//% parts="bluetooth"
void onBluetoothDisconnected(Action body) {
registerWithDal(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, body);
}

View File

@ -11,70 +11,80 @@ declare namespace bluetooth {
* Starts the Bluetooth IO pin service.
*/
//% help=bluetooth/start-io-pin-service
//% blockId=bluetooth_start_io_pin_service block="bluetooth io pin service" blockGap=8 shim=bluetooth::startIOPinService
//% blockId=bluetooth_start_io_pin_service block="bluetooth io pin service" blockGap=8
//% parts="bluetooth" shim=bluetooth::startIOPinService
function startIOPinService(): void;
/**
* Starts the Bluetooth LED service
*/
//% help=bluetooth/start-led-service
//% blockId=bluetooth_start_led_service block="bluetooth led service" blockGap=8 shim=bluetooth::startLEDService
//% blockId=bluetooth_start_led_service block="bluetooth led service" blockGap=8
//% parts="bluetooth" shim=bluetooth::startLEDService
function startLEDService(): void;
/**
* Starts the Bluetooth temperature service
*/
//% help=bluetooth/start-temperature-service
//% blockId=bluetooth_start_temperature_service block="bluetooth temperature service" blockGap=8 shim=bluetooth::startTemperatureService
//% blockId=bluetooth_start_temperature_service block="bluetooth temperature service" blockGap=8
//% parts="bluetooth" shim=bluetooth::startTemperatureService
function startTemperatureService(): void;
/**
* Starts the Bluetooth magnetometer service
*/
//% help=bluetooth/start-magnetometer-service
//% blockId=bluetooth_start_magnetometer_service block="bluetooth magnetometer service" blockGap=8 shim=bluetooth::startMagnetometerService
//% blockId=bluetooth_start_magnetometer_service block="bluetooth magnetometer service" blockGap=8
//% parts="bluetooth" shim=bluetooth::startMagnetometerService
function startMagnetometerService(): void;
/**
* Starts the Bluetooth accelerometer service
*/
//% help=bluetooth/start-accelerometer-service
//% blockId=bluetooth_start_accelerometer_service block="bluetooth accelerometer service" blockGap=8 shim=bluetooth::startAccelerometerService
//% blockId=bluetooth_start_accelerometer_service block="bluetooth accelerometer service" blockGap=8
//% parts="bluetooth" shim=bluetooth::startAccelerometerService
function startAccelerometerService(): void;
/**
* Starts the Bluetooth button service
*/
//% help=bluetooth/start-button-service
//% blockId=bluetooth_start_button_service block="bluetooth button service" blockGap=8 shim=bluetooth::startButtonService
//% blockId=bluetooth_start_button_service block="bluetooth button service" blockGap=8
//% parts="bluetooth" shim=bluetooth::startButtonService
function startButtonService(): void;
/**
* Starts the Bluetooth UART service
*/
//% help=bluetooth/start-uart-service
//% blockId=bluetooth_start_uart_service block="bluetooth uart service" blockGap=8 shim=bluetooth::startUartService
//% blockId=bluetooth_start_uart_service block="bluetooth uart service" blockGap=8
//% parts="bluetooth" shim=bluetooth::startUartService
function startUartService(): void;
/**
* Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device.
*/
//% help=bluetooth/uart-write
//% blockId=bluetooth_uart_write block="bluetooth uart write %data" blockGap=8 shim=bluetooth::uartWrite
//% blockId=bluetooth_uart_write block="bluetooth uart write %data" blockGap=8
//% parts="bluetooth" shim=bluetooth::uartWrite
function uartWrite(data: string): void;
/**
* Reads from the Bluetooth UART service buffer, returning its contents when the specified delimiter character is encountered.
*/
//% help=bluetooth/uart-read
//% blockId=bluetooth_uart_read block="bluetooth uart read %del=bluetooth_uart_delimiter_conv" blockGap=8 shim=bluetooth::uartRead
//% blockId=bluetooth_uart_read block="bluetooth uart read %del=bluetooth_uart_delimiter_conv" blockGap=8
//% parts="bluetooth" shim=bluetooth::uartRead
function uartRead(del: string): string;
/**
* Returns the delimiter corresponding string
*/
//% blockId="bluetooth_uart_delimiter_conv" block="%del"
//% weight=1 shim=bluetooth::delimiters
//% weight=1
//% parts="bluetooth" shim=bluetooth::delimiters
function delimiters(del: Delimiters): string;
/**
@ -82,7 +92,8 @@ declare namespace bluetooth {
* @param body Code to run when a Bluetooth connection is established
*/
//% help=bluetooth/on-bluetooth-connected weight=20
//% blockId=bluetooth_on_connected block="on bluetooth connected" blockGap=8 shim=bluetooth::onBluetoothConnected
//% blockId=bluetooth_on_connected block="on bluetooth connected" blockGap=8
//% parts="bluetooth" shim=bluetooth::onBluetoothConnected
function onBluetoothConnected(body: () => void): void;
/**
@ -90,7 +101,8 @@ declare namespace bluetooth {
* @param body Code to run when a Bluetooth connection is lost
*/
//% help=bluetooth/on-bluetooth-disconnected weight=19
//% blockId=bluetooth_on_disconnected block="on bluetooth disconnected" shim=bluetooth::onBluetoothDisconnected
//% blockId=bluetooth_on_disconnected block="on bluetooth disconnected"
//% parts="bluetooth" shim=bluetooth::onBluetoothDisconnected
function onBluetoothDisconnected(body: () => void): void;
}

View File

@ -15,6 +15,7 @@ namespace basic {
//% weight=96
//% blockId=device_show_number block="show|number %number" blockGap=8 icon="\uf1ec"
//% async
//% parts="ledmatrix"
void showNumber(int value, int interval = 150) {
if (interval < 0)
return;
@ -37,6 +38,7 @@ namespace basic {
//% imageLiteral=1 async
//% blockId=device_show_leds
//% block="show leds" icon="\uf00a"
//% parts="ledmatrix"
void showLeds(ImageLiteral leds, int interval = 400) {
uBit.display.print(MicroBitImage(imageBytes(leds)), 0, 0, 0, interval);
}
@ -51,6 +53,7 @@ namespace basic {
//% block="show|string %text" icon="\uf031"
//% async
//% blockId=device_print_message
//% parts="ledmatrix"
void showString(StringData *text, int interval = 150) {
if (interval < 0)
return;
@ -71,6 +74,7 @@ namespace basic {
*/
//% help=basic/clear-screen weight=79
//% blockId=device_clear_display block="clear screen" icon="\uf12d"
//% parts="ledmatrix"
void clearScreen() {
uBit.display.image.clear();
}
@ -81,6 +85,7 @@ namespace basic {
* @param interval time in milliseconds between each redraw
*/
//% help=basic/show-animation imageLiteral=1 async
//% parts="ledmatrix"
void showAnimation(ImageLiteral leds, int interval = 400) {
uBit.display.animate(MicroBitImage(imageBytes(leds)), interval, 5, 0);
}
@ -90,6 +95,7 @@ namespace basic {
* @param leds pattern of LEDs to turn on/off
*/
//% help=basic/plot-leds weight=80
//% parts="ledmatrix"
void plotLeds(ImageLiteral leds) {
MicroBitImage i(imageBytes(leds));
uBit.display.print(i, 0, 0, 0, 0);

View File

@ -129,12 +129,22 @@ namespace control {
/**
* Resets the BBC micro:bit.
*/
//% weight=30 async help=control/reset
//% weight=30 async help=control/reset blockGap=8
//% blockId="control_reset" block="reset"
void reset() {
microbit_reset();
}
/**
* Blocks the current fiber for the given microseconds
* @param micros number of micro-seconds to wait. eg: 4
*/
//% help=control/wait-micros weight=29
//% blockId="control_wait_us" block="wait (µs)%micros"
void waitMicros(int micros) {
wait_us(micros);
}
/**
* Raises an event in the event bus.
* @param src ID of the MicroBit Component that generated the event e.g. MICROBIT_ID_BUTTON_A.

View File

@ -171,9 +171,13 @@ namespace pxt {
//%
void registerWithDal(int id, int event, Action a);
//%
void runAction0(Action a);
uint32_t runAction3(Action a, int arg0, int arg1, int arg2);
//%
void runAction1(Action a, int arg);
uint32_t runAction2(Action a, int arg0, int arg1);
//%
uint32_t runAction1(Action a, int arg0);
//%
uint32_t runAction0(Action a);
//%
Action mkAction(int reflen, int totallen, int startptr);
//%
@ -257,36 +261,6 @@ namespace pxtrt {
r->unref();
}
//%
uint32_t ldglb(int idx) {
check(0 <= idx && idx < numGlobals, ERR_OUT_OF_BOUNDS, 7);
return globals[idx];
}
//%
uint32_t ldglbRef(int idx) {
check(0 <= idx && idx < numGlobals, ERR_OUT_OF_BOUNDS, 7);
uint32_t tmp = globals[idx];
incr(tmp);
return tmp;
}
// note the idx comes last - it's more convenient that way in the emitter
//%
void stglb(uint32_t v, int idx)
{
check(0 <= idx && idx < numGlobals, ERR_OUT_OF_BOUNDS, 7);
globals[idx] = v;
}
//%
void stglbRef(uint32_t v, int idx)
{
check(0 <= idx && idx < numGlobals, ERR_OUT_OF_BOUNDS, 7);
decr(globals[idx]);
globals[idx] = v;
}
// Store a captured local in a closure. It returns the action, so it can be chained.
//%
RefAction *stclo(RefAction *a, int idx, uint32_t v)
@ -302,6 +276,34 @@ namespace pxtrt {
microbit_panic(code);
}
//%
int stringToBool(StringData *s) {
if (s == NULL) return 0;
if (s->len == 0) {
s->decr();
return 0;
}
s->decr();
return 1;
}
//%
StringData* emptyToNull(StringData *s) {
if (!s || s->len == 0)
return NULL;
return s;
}
//%
int ptrToBool(uint32_t p) {
if (p) {
decr(p);
return 1;
} else {
return 0;
}
}
//
// Debugger
//

View File

@ -41,6 +41,7 @@ namespace game {
*/
//% weight=60
//% blockId=game_create_sprite block="create sprite at|x: %x|y: %y"
//% parts="ledmatrix"
export function createSprite(x: number, y: number): LedSprite {
init();
let p = new LedSprite(x, y);
@ -64,6 +65,7 @@ namespace game {
*/
//% weight=10 help=game/add-score
//% blockId=game_add_score block="change score by|%points" blockGap=8
//% parts="ledmatrix"
export function addScore(points: number): void {
setScore(_score + points);
control.inBackground(() => {
@ -82,6 +84,7 @@ namespace game {
*/
//% weight=9 help=game/start-countdown
//% blockId=game_start_countdown block="start countdown|(ms) %duration" blockGap=8
//% parts="ledmatrix"
export function startCountdown(ms: number): void {
if (checkStart()) {
basic.showAnimation(`1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0
@ -104,6 +107,7 @@ namespace game {
*/
//% weight=8 help=game/game-over
//% blockId=game_game_over block="game over"
//% parts="ledmatrix"
export function gameOver(): void {
if (!_isGameOver) {
_isGameOver = true;
@ -194,6 +198,7 @@ namespace game {
* @param life TODO
*/
//% weight=10
//% parts="ledmatrix"
export function removeLife(life: number): void {
setLife(_life - life);
control.inBackground(() => {
@ -210,6 +215,7 @@ namespace game {
* Increments the level and display a message.
*/
//% weight=10
//% parts="ledmatrix"
export function levelUp(): void {
_level = _level + 1;
basic.showString("LEVEL:", 150);
@ -246,6 +252,7 @@ namespace game {
* Displays the score on the screen.
*/
//% weight=60
//% parts="ledmatrix"
export function showScore(): void {
basic.showString(" SCORE ", 100);
basic.showNumber(_score, 150);
@ -303,6 +310,7 @@ namespace game {
*/
//% weight=50
//% blockId=game_move_sprite block="%sprite|move by %leds" blockGap=8
//% parts="ledmatrix"
public move(leds: number): void {
if (this._dir == 0) {
this._y = this._y - leds;
@ -336,6 +344,7 @@ namespace game {
* @param x TODO
* @param y TODO
*/
//% parts="ledmatrix"
public goTo(x: number, y: number): void {
this._x = x;
this._y = y;
@ -350,6 +359,7 @@ namespace game {
*/
//% weight=18
//% blockId=game_sprite_bounce block="%sprite|if on edge, bounce"
//% parts="ledmatrix"
public ifOnEdgeBounce(): void {
if (this._dir == 0 && this._y == 0) {
this._dir = 180;
@ -484,6 +494,7 @@ namespace game {
* @param this TODO
* @param degrees TODO
*/
//% parts="ledmatrix"
public setDirection(degrees: number): void {
this._dir = ((degrees / 45) % 8) * 45;
if (this._dir <= -180) {
@ -596,6 +607,7 @@ namespace game {
* @param this TODO
* @param brightness TODO
*/
//% parts="ledmatrix"
public setBrightness(brightness: number): void {
this._brightness = Math.clamp(0, 255, brightness);
plot();
@ -664,6 +676,7 @@ namespace game {
}
//% weight=-1
//% parts="ledmatrix"
public _plot(now: number) {
let ps = this
if (ps._brightness > 0) {
@ -701,6 +714,7 @@ namespace game {
/**
* Plots the current sprites on the screen
*/
//% parts="ledmatrix"
function plot(): void {
if (game.isGameOver()) {
return;

View File

@ -10,6 +10,7 @@ namespace images {
*/
//% weight=75 help=images/create-image
//% blockId=device_build_image block="create image"
//% parts="ledmatrix"
Image createImage(ImageLiteral leds) {
return MicroBitImage(imageBytes(leds)).clone().leakData();
}
@ -19,6 +20,7 @@ namespace images {
*/
//% weight=74 help=images/create-big-image
//% blockId=device_build_big_image block="create big image" imageLiteral=2
//% parts="ledmatrix"
Image createBigImage(ImageLiteral leds) {
return createImage(leds);
}
@ -29,6 +31,7 @@ namespace ImageMethods {
* Plots the image at a given column to the screen
*/
//% help=images/plot-image
//% parts="ledmatrix"
void plotImage(Image i, int xOffset = 0) {
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0, 0);
}
@ -39,6 +42,7 @@ namespace ImageMethods {
*/
//% help=images/show-image weight=80 blockNamespace=images
//% blockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8
//% parts="ledmatrix"
void showImage(Image sprite, int xOffset) {
uBit.display.print(MicroBitImage(sprite), -xOffset, 0, 0);
}
@ -48,6 +52,7 @@ namespace ImageMethods {
* @param xOffset column index to start displaying the image
*/
//% help=images/plot-frame weight=80
//% parts="ledmatrix"
void plotFrame(Image i, int xOffset) {
// TODO showImage() used in original implementation
plotImage(i, xOffset * 5);
@ -60,6 +65,7 @@ namespace ImageMethods {
*/
//% help=images/show-image weight=79 async blockNamespace=images
//% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8
//% parts="ledmatrix"
void scrollImage(Image id, int frameOffset, int interval) {
MicroBitImage i(id);
if (i.getWidth() <= 5)
@ -73,6 +79,7 @@ namespace ImageMethods {
* Sets all pixels off.
*/
//% help=images/clear
//% parts="ledmatrix"
void clear(Image i) {
MicroBitImage(i).clear();
}
@ -81,6 +88,7 @@ namespace ImageMethods {
* Sets a specific pixel brightness at a given position
*/
//%
//% parts="ledmatrix"
void setPixelBrightness(Image i, int x, int y, int value) {
MicroBitImage(i).setPixelValue(x, y, value);
}
@ -90,6 +98,7 @@ namespace ImageMethods {
* Gets the pixel brightness ([0..255]) at a given position
*/
//%
//% parts="ledmatrix"
int pixelBrightness(Image i, int x, int y) {
int pix = MicroBitImage(i).getPixelValue(x, y);
if (pix < 0) return 0;
@ -120,6 +129,7 @@ namespace ImageMethods {
* @param value TODO
*/
//% help=images/set-pixel
//% parts="ledmatrix"
void setPixel(Image i, int x, int y, bool value) {
setPixelBrightness(i, x, y, value ? 255 : 0);
}
@ -130,6 +140,7 @@ namespace ImageMethods {
* @param y TODO
*/
//% help=images/pixel
//% parts="ledmatrix"
bool pixel(Image i, int x, int y) {
return pixelBrightness(i, x, y) > 0;
}
@ -140,6 +151,7 @@ namespace ImageMethods {
* @param frame TODO
*/
//% weight=70 help=images/show-frame
//% parts="ledmatrix"
void showFrame(Image i, int frame) {
showImage(i, frame * 5);
}

View File

@ -116,6 +116,7 @@ namespace input {
*/
//% help=input/on-button-pressed weight=85 blockGap=8
//% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192"
//% parts="buttonpair"
void onButtonPressed(Button button, Action body) {
registerWithDal((int)button, MICROBIT_BUTTON_EVT_CLICK, body);
}
@ -126,6 +127,7 @@ namespace input {
*/
//% help=input/on-gesture weight=84 blockGap=8
//% blockId=device_gesture_event block="on |%NAME" icon="\uf135"
//% parts="accelerometer"
void onGesture(Gesture gesture, Action body) {
if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3)
uBit.accelerometer.setRange(4);
@ -134,7 +136,7 @@ namespace input {
registerWithDal(MICROBIT_ID_GESTURE, (int)gesture, body);
}
/**
/**
* Do something when a pin is pressed.
* @param name the pin that needs to be pressed
* @param body the code to run when the pin is pressed
@ -173,6 +175,7 @@ namespace input {
//% block="button|%NAME|is pressed"
//% blockId=device_get_button2
//% icon="\uf192" blockGap=8
//% parts="buttonpair"
bool buttonIsPressed(Button button) {
if (button == Button::A)
return uBit.buttonA.isPressed();
@ -201,6 +204,7 @@ namespace input {
//% help=input/compass-heading
//% weight=56 icon="\uf14e"
//% blockId=device_heading block="compass heading (°)" blockGap=8
//% parts="compass"
int compassHeading() {
return uBit.compass.heading();
}
@ -212,6 +216,7 @@ namespace input {
//% weight=55 icon="\uf06d"
//% help=input/temperature
//% blockId=device_temperature block="temperature (°C)" blockGap=8
//% parts="thermometer"
int temperature() {
return uBit.thermometer.getTemperature();
}
@ -229,6 +234,7 @@ namespace input {
*/
//% help=input/acceleration weight=54 icon="\uf135"
//% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8
//% parts="accelerometer"
int acceleration(Dimension dimension) {
switch (dimension) {
case Dimension::X: return uBit.accelerometer.getX();
@ -245,6 +251,7 @@ namespace input {
*/
//% help=input/light-level weight=53
//% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185"
//% parts="ledmatrix"
int lightLevel() {
return uBit.display.readLightLevel();
}
@ -255,6 +262,7 @@ namespace input {
*/
//% help=input/rotation weight=52
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197"
//% parts="accelerometer"
int rotation(Rotation kind) {
switch (kind) {
case Rotation::Pitch: return uBit.accelerometer.getPitch();
@ -269,6 +277,7 @@ namespace input {
*/
//% help=input/magnetic-force weight=51
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076"
//% parts="compass"
int magneticForce(Dimension dimension) {
if (!uBit.compass.isCalibrated())
uBit.compass.calibrate();
@ -304,6 +313,7 @@ namespace input {
//% help=input/set-accelerometer-range
//% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135"
//% weight=5
//% parts="accelerometer"
void setAccelerometerRange(AcceleratorRange range) {
uBit.accelerometer.setRange((int)range);
}

View File

@ -18,6 +18,7 @@ namespace led {
*/
//% help=led/plot weight=78
//% blockId=device_plot block="plot|x %x|y %y" icon="\uf205" blockGap=8
//% parts="ledmatrix"
void plot(int x, int y) {
uBit.display.image.setPixelValue(x, y, 1);
}
@ -29,6 +30,7 @@ namespace led {
*/
//% help=led/unplot weight=77
//% blockId=device_unplot block="unplot|x %x|y %y" icon="\uf204" blockGap=8
//% parts="ledmatrix"
void unplot(int x, int y) {
uBit.display.image.setPixelValue(x, y, 0);
}
@ -40,6 +42,7 @@ namespace led {
*/
//% help=led/point weight=76
//% blockId=device_point block="point|x %x|y %y" icon="\uf10c"
//% parts="ledmatrix"
bool point(int x, int y) {
int pix = uBit.display.image.getPixelValue(x, y);
return pix > 0;
@ -50,6 +53,7 @@ namespace led {
*/
//% help=led/brightness weight=60
//% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8
//% parts="ledmatrix"
int brightness() {
return uBit.display.getBrightness();
}
@ -60,6 +64,7 @@ namespace led {
*/
//% help=led/set-brightness weight=59
//% blockId=device_set_brightness block="set brightness %value" icon="\uf042"
//% parts="ledmatrix"
void setBrightness(int value) {
uBit.display.setBrightness(value);
}
@ -69,6 +74,7 @@ namespace led {
*/
//% weight=50 help=led/stop-animation
//% blockId=device_stop_animation block="stop animation" icon="\uf04d"
//% parts="ledmatrix"
void stopAnimation() {
uBit.display.stopAnimation();
}
@ -78,6 +84,7 @@ namespace led {
* @param mode TODO
*/
//% weight=1 help=led/set-display-mode
//% parts="ledmatrix"
void setDisplayMode(DisplayMode_ mode) {
uBit.display.setDisplayMode((DisplayMode)mode);
}
@ -86,6 +93,7 @@ namespace led {
* Takes a screenshot of the LED screen and returns an image.
*/
//% help=led/screenshot
//% parts="ledmatrix"
Image screenshot() {
return uBit.display.screenShot().leakData();
/*

View File

@ -17,6 +17,7 @@
*/
//% help=led/plot-bar-graph weight=20
//% blockId=device_plot_bar_graph block="plot bar graph of %value |up to %high" icon="\uf080" blockExternalInputs=true
//% parts="ledmatrix"
export function plotBarGraph(value: number, high: number): void {
let now = input.runningTime();
serial.writeString(value.toString() + "\r\n");
@ -53,6 +54,7 @@
*/
//% help=led/toggle weight=77
//% blockId=device_led_toggle block="toggle|x %x|y %y" icon="\uf204" blockGap=8
//% parts="ledmatrix"
export function toggle(x: number, y: number): void {
if (led.point(x, y)) {
led.unplot(x, y);
@ -65,6 +67,7 @@
* Turns all LEDS on
*/
//% help=led/plot-all
//% parts="ledmatrix"
export function plotAll(): void {
for (let i = 0; i < 5; i++) {
for (let j = 0; j < 5; j++) {
@ -77,6 +80,7 @@
* Inverts the current LED display
*/
//% help=led/toggle-all
//% parts="ledmatrix"
export function toggleAll(): void {
for (let i = 0; i < 5; i++) {
for (let j = 0; j < 5; j++) {
@ -90,6 +94,7 @@
* @param ms TODO
*/
//% help=led/fade-in
//% parts="ledmatrix"
export function fadeIn(ms: number = 700): void {
if (ms < 20) {
led.setBrightness(255);
@ -112,6 +117,7 @@
* @param ms TODO
*/
//% help=led/fade-out
//% parts="ledmatrix"
export function fadeOut(ms: number = 700): void {
if (ms < 20) {
led.setBrightness(0);

View File

@ -162,7 +162,8 @@ namespace music {
//% help=music/change-tempo weight=39
//% blockId=device_change_tempo block="change tempo by (bpm)|%value" blockGap=8
export function changeTempoBy(bpm: number): void {
setTempo(beat(BeatFraction.Whole) + bpm);
init();
setTempo(beatsPerMinute + bpm);
}
/**

View File

@ -160,11 +160,40 @@ namespace pins {
*/
//% help=pins/pulse-duration
//% blockId=pins_pulse_duration block="pulse duration (µs)"
//% weight=21
//% weight=21 blockGap=8
int pulseDuration() {
return pxt::lastEvent.timestamp;
}
/**
* Returns the duration of a pulse in microseconds
* @param name the pin which measures the pulse
* @param value the value of the pulse (default high)
* @param maximum duration in micro-seconds
*/
//% blockId="pins_pulse_in" block="pulse in (µs)|pin %name|pulsed %value"
//% weight=20
int pulseIn(DigitalPin name, PulseValue value, int maxDuration = 2000000) {
MicroBitPin* pin = getPin((int)name);
if (!pin) return 0;
int pulse = value == PulseValue::High ? 1 : 0;
uint64_t tick = system_timer_current_time_us();
uint64_t maxd = (uint64_t)maxDuration;
while(pin->getDigitalValue() != pulse) {
if(system_timer_current_time_us() - tick > maxd)
return 0;
}
uint64_t start = system_timer_current_time_us();
while(pin->getDigitalValue() == pulse) {
if(system_timer_current_time_us() - tick > maxd)
return 0;
}
uint64_t end = system_timer_current_time_us();
return end - start;
}
/**
* Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).
* @param name pin to write to

View File

@ -11,7 +11,7 @@ namespace pins {
* @param toLow the lower bound of the value's target range
* @param toHigh the upper bound of the value's target range, eg: 4
*/
//% help=pins/map weight=22
//% help=pins/map weight=23
//% blockId=math_map block="map %value|from low %fromLow|from high %fromHigh|to low %toLow|to high %toHigh"
export function map(value: number, fromLow: number, fromHigh: number, toLow: number, toHigh: number): number {
return ((value - fromLow) * (toHigh - toLow)) / (fromHigh - fromLow) + toLow;

View File

@ -11,14 +11,16 @@ declare namespace images {
* Creates an image that fits on the LED screen.
*/
//% weight=75 help=images/create-image
//% blockId=device_build_image block="create image" imageLiteral=1 shim=images::createImage
//% blockId=device_build_image block="create image"
//% parts="ledmatrix" imageLiteral=1 shim=images::createImage
function createImage(leds: string): Image;
/**
* Creates an image with 2 frames.
*/
//% weight=74 help=images/create-big-image
//% blockId=device_build_big_image block="create big image" imageLiteral=2 shim=images::createBigImage
//% blockId=device_build_big_image block="create big image" imageLiteral=2
//% parts="ledmatrix" shim=images::createBigImage
function createBigImage(leds: string): Image;
}
@ -27,7 +29,8 @@ declare interface Image {
/**
* Plots the image at a given column to the screen
*/
//% help=images/plot-image xOffset.defl=0 shim=ImageMethods::plotImage
//% help=images/plot-image
//% parts="ledmatrix" xOffset.defl=0 shim=ImageMethods::plotImage
plotImage(xOffset?: number): void;
/**
@ -35,14 +38,16 @@ declare interface Image {
* @param xOffset column index to start displaying the image
*/
//% help=images/show-image weight=80 blockNamespace=images
//% blockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8 shim=ImageMethods::showImage
//% blockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8
//% parts="ledmatrix" shim=ImageMethods::showImage
showImage(xOffset: number): void;
/**
* Draws the ``index``-th frame of the image on the screen.
* @param xOffset column index to start displaying the image
*/
//% help=images/plot-frame weight=80 shim=ImageMethods::plotFrame
//% help=images/plot-frame weight=80
//% parts="ledmatrix" shim=ImageMethods::plotFrame
plotFrame(xOffset: number): void;
/**
@ -51,25 +56,29 @@ declare interface Image {
* @param interval time between each animation step in milli seconds, eg: 200
*/
//% help=images/show-image weight=79 async blockNamespace=images
//% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8 shim=ImageMethods::scrollImage
//% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8
//% parts="ledmatrix" shim=ImageMethods::scrollImage
scrollImage(frameOffset: number, interval: number): void;
/**
* Sets all pixels off.
*/
//% help=images/clear shim=ImageMethods::clear
//% help=images/clear
//% parts="ledmatrix" shim=ImageMethods::clear
clear(): void;
/**
* Sets a specific pixel brightness at a given position
*/
//% shim=ImageMethods::setPixelBrightness
//%
//% parts="ledmatrix" shim=ImageMethods::setPixelBrightness
setPixelBrightness(x: number, y: number, value: number): void;
/**
* Gets the pixel brightness ([0..255]) at a given position
*/
//% shim=ImageMethods::pixelBrightness
//%
//% parts="ledmatrix" shim=ImageMethods::pixelBrightness
pixelBrightness(x: number, y: number): number;
/**
@ -90,7 +99,8 @@ declare interface Image {
* @param y TODO
* @param value TODO
*/
//% help=images/set-pixel shim=ImageMethods::setPixel
//% help=images/set-pixel
//% parts="ledmatrix" shim=ImageMethods::setPixel
setPixel(x: number, y: number, value: boolean): void;
/**
@ -98,14 +108,16 @@ declare interface Image {
* @param x TODO
* @param y TODO
*/
//% help=images/pixel shim=ImageMethods::pixel
//% help=images/pixel
//% parts="ledmatrix" shim=ImageMethods::pixel
pixel(x: number, y: number): boolean;
/**
* Shows a particular frame of the image strip.
* @param frame TODO
*/
//% weight=70 help=images/show-frame shim=ImageMethods::showFrame
//% weight=70 help=images/show-frame
//% parts="ledmatrix" shim=ImageMethods::showFrame
showFrame(frame: number): void;
}
@ -123,7 +135,8 @@ declare namespace basic {
//% help=basic/show-number
//% weight=96
//% blockId=device_show_number block="show|number %number" blockGap=8 icon="\uf1ec"
//% async interval.defl=150 shim=basic::showNumber
//% async
//% parts="ledmatrix" interval.defl=150 shim=basic::showNumber
function showNumber(value: number, interval?: number): void;
/**
@ -135,7 +148,8 @@ declare namespace basic {
//% weight=95 blockGap=8
//% imageLiteral=1 async
//% blockId=device_show_leds
//% block="show leds" icon="\uf00a" interval.defl=400 shim=basic::showLeds
//% block="show leds" icon="\uf00a"
//% parts="ledmatrix" interval.defl=400 shim=basic::showLeds
function showLeds(leds: string, interval?: number): void;
/**
@ -147,14 +161,16 @@ declare namespace basic {
//% weight=87 blockGap=8
//% block="show|string %text" icon="\uf031"
//% async
//% blockId=device_print_message interval.defl=150 shim=basic::showString
//% blockId=device_print_message
//% parts="ledmatrix" interval.defl=150 shim=basic::showString
function showString(text: string, interval?: number): void;
/**
* Turn off all LEDs
*/
//% help=basic/clear-screen weight=79
//% blockId=device_clear_display block="clear screen" icon="\uf12d" shim=basic::clearScreen
//% blockId=device_clear_display block="clear screen" icon="\uf12d"
//% parts="ledmatrix" shim=basic::clearScreen
function clearScreen(): void;
/**
@ -162,14 +178,16 @@ declare namespace basic {
* @param leds pattern of LEDs to turn on/off
* @param interval time in milliseconds between each redraw
*/
//% help=basic/show-animation imageLiteral=1 async interval.defl=400 shim=basic::showAnimation
//% help=basic/show-animation imageLiteral=1 async
//% parts="ledmatrix" interval.defl=400 shim=basic::showAnimation
function showAnimation(leds: string, interval?: number): void;
/**
* Draws an image on the LED screen.
* @param leds pattern of LEDs to turn on/off
*/
//% help=basic/plot-leds weight=80 imageLiteral=1 shim=basic::plotLeds
//% help=basic/plot-leds weight=80
//% parts="ledmatrix" imageLiteral=1 shim=basic::plotLeds
function plotLeds(leds: string): void;
/**
@ -201,7 +219,8 @@ declare namespace input {
* @param body TODO
*/
//% help=input/on-button-pressed weight=85 blockGap=8
//% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192" shim=input::onButtonPressed
//% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192"
//% parts="buttonpair" shim=input::onButtonPressed
function onButtonPressed(button: Button, body: () => void): void;
/**
@ -209,7 +228,8 @@ declare namespace input {
* @param body TODO
*/
//% help=input/on-gesture weight=84 blockGap=8
//% blockId=device_gesture_event block="on |%NAME" icon="\uf135" shim=input::onGesture
//% blockId=device_gesture_event block="on |%NAME" icon="\uf135"
//% parts="accelerometer" shim=input::onGesture
function onGesture(gesture: Gesture, body: () => void): void;
/**
@ -236,7 +256,8 @@ declare namespace input {
//% help=input/button-is-pressed weight=57
//% block="button|%NAME|is pressed"
//% blockId=device_get_button2
//% icon="\uf192" blockGap=8 shim=input::buttonIsPressed
//% icon="\uf192" blockGap=8
//% parts="buttonpair" shim=input::buttonIsPressed
function buttonIsPressed(button: Button): boolean;
/**
@ -253,7 +274,8 @@ declare namespace input {
*/
//% help=input/compass-heading
//% weight=56 icon="\uf14e"
//% blockId=device_heading block="compass heading (°)" blockGap=8 shim=input::compassHeading
//% blockId=device_heading block="compass heading (°)" blockGap=8
//% parts="compass" shim=input::compassHeading
function compassHeading(): number;
/**
@ -261,7 +283,8 @@ declare namespace input {
*/
//% weight=55 icon="\uf06d"
//% help=input/temperature
//% blockId=device_temperature block="temperature (°C)" blockGap=8 shim=input::temperature
//% blockId=device_temperature block="temperature (°C)" blockGap=8
//% parts="thermometer" shim=input::temperature
function temperature(): number;
/**
@ -269,14 +292,16 @@ declare namespace input {
* @param dimension TODO
*/
//% help=input/acceleration weight=54 icon="\uf135"
//% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8 shim=input::acceleration
//% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8
//% parts="accelerometer" shim=input::acceleration
function acceleration(dimension: Dimension): number;
/**
* Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.
*/
//% help=input/light-level weight=53
//% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185" shim=input::lightLevel
//% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185"
//% parts="ledmatrix" shim=input::lightLevel
function lightLevel(): number;
/**
@ -284,7 +309,8 @@ declare namespace input {
* @param kind TODO
*/
//% help=input/rotation weight=52
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197" shim=input::rotation
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197"
//% parts="accelerometer" shim=input::rotation
function rotation(kind: Rotation): number;
/**
@ -292,7 +318,8 @@ declare namespace input {
* @param dimension TODO
*/
//% help=input/magnetic-force weight=51
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076" shim=input::magneticForce
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076"
//% parts="compass" shim=input::magneticForce
function magneticForce(dimension: Dimension): number;
/**
@ -314,7 +341,8 @@ declare namespace input {
*/
//% help=input/set-accelerometer-range
//% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135"
//% weight=5 shim=input::setAccelerometerRange
//% weight=5
//% parts="accelerometer" shim=input::setAccelerometerRange
function setAccelerometerRange(range: AcceleratorRange): void;
}
@ -333,10 +361,18 @@ declare namespace control {
/**
* Resets the BBC micro:bit.
*/
//% weight=30 async help=control/reset
//% weight=30 async help=control/reset blockGap=8
//% blockId="control_reset" block="reset" shim=control::reset
function reset(): void;
/**
* Blocks the current fiber for the given microseconds
* @param micros number of micro-seconds to wait. eg: 4
*/
//% help=control/wait-micros weight=29
//% blockId="control_wait_us" block="wait (µs)%micros" shim=control::waitMicros
function waitMicros(micros: number): void;
/**
* Raises an event in the event bus.
* @param src ID of the MicroBit Component that generated the event e.g. MICROBIT_ID_BUTTON_A.
@ -392,7 +428,8 @@ declare namespace led {
* @param y TODO
*/
//% help=led/plot weight=78
//% blockId=device_plot block="plot|x %x|y %y" icon="\uf205" blockGap=8 shim=led::plot
//% blockId=device_plot block="plot|x %x|y %y" icon="\uf205" blockGap=8
//% parts="ledmatrix" shim=led::plot
function plot(x: number, y: number): void;
/**
@ -401,7 +438,8 @@ declare namespace led {
* @param y TODO
*/
//% help=led/unplot weight=77
//% blockId=device_unplot block="unplot|x %x|y %y" icon="\uf204" blockGap=8 shim=led::unplot
//% blockId=device_unplot block="unplot|x %x|y %y" icon="\uf204" blockGap=8
//% parts="ledmatrix" shim=led::unplot
function unplot(x: number, y: number): void;
/**
@ -410,14 +448,16 @@ declare namespace led {
* @param y TODO
*/
//% help=led/point weight=76
//% blockId=device_point block="point|x %x|y %y" icon="\uf10c" shim=led::point
//% blockId=device_point block="point|x %x|y %y" icon="\uf10c"
//% parts="ledmatrix" shim=led::point
function point(x: number, y: number): boolean;
/**
* Get the screen brightness from 0 (off) to 255 (full bright).
*/
//% help=led/brightness weight=60
//% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8 shim=led::brightness
//% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8
//% parts="ledmatrix" shim=led::brightness
function brightness(): number;
/**
@ -425,27 +465,31 @@ declare namespace led {
* @param value the brightness value, eg:255, 127, 0
*/
//% help=led/set-brightness weight=59
//% blockId=device_set_brightness block="set brightness %value" icon="\uf042" shim=led::setBrightness
//% blockId=device_set_brightness block="set brightness %value" icon="\uf042"
//% parts="ledmatrix" shim=led::setBrightness
function setBrightness(value: number): void;
/**
* Cancels the current animation and clears other pending animations.
*/
//% weight=50 help=led/stop-animation
//% blockId=device_stop_animation block="stop animation" icon="\uf04d" shim=led::stopAnimation
//% blockId=device_stop_animation block="stop animation" icon="\uf04d"
//% parts="ledmatrix" shim=led::stopAnimation
function stopAnimation(): void;
/**
* Sets the display mode between black and white and greyscale for rendering LEDs.
* @param mode TODO
*/
//% weight=1 help=led/set-display-mode shim=led::setDisplayMode
//% weight=1 help=led/set-display-mode
//% parts="ledmatrix" shim=led::setDisplayMode
function setDisplayMode(mode: DisplayMode): void;
/**
* Takes a screenshot of the LED screen and returns an image.
*/
//% help=led/screenshot shim=led::screenshot
//% help=led/screenshot
//% parts="ledmatrix" shim=led::screenshot
function screenshot(): Image;
}
declare namespace pins {
@ -506,9 +550,19 @@ declare namespace pins {
*/
//% help=pins/pulse-duration
//% blockId=pins_pulse_duration block="pulse duration (µs)"
//% weight=21 shim=pins::pulseDuration
//% weight=21 blockGap=8 shim=pins::pulseDuration
function pulseDuration(): number;
/**
* Returns the duration of a pulse in microseconds
* @param name the pin which measures the pulse
* @param value the value of the pulse (default high)
* @param maximum duration in micro-seconds
*/
//% blockId="pins_pulse_in" block="pulse in (µs)|pin %name|pulsed %value"
//% weight=20 maxDuration.defl=2000000 shim=pins::pulseIn
function pulseIn(name: DigitalPin, value: PulseValue, maxDuration?: number): number;
/**
* Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).
* @param name pin to write to

View File

@ -1,7 +1,7 @@
{
"name": "pxt-microbit",
"version": "0.3.24",
"description": "BBC micro:bit target for PXT",
"version": "0.3.51",
"description": "micro:bit target for PXT",
"keywords": [
"JavaScript",
"education",
@ -29,6 +29,6 @@
"typescript": "^1.8.7"
},
"dependencies": {
"pxt-core": "0.3.27"
"pxt-core": "0.3.56"
}
}

View File

@ -2,6 +2,7 @@
"id": "microbit",
"name": "code the micro:bit",
"title": "code the micro:bit - Blocks / Javascript editor",
"description": "A Blocks / JavaScript code editor for the micro:bit.",
"corepkg": "microbit",
"bundleddirs": [
"libs/microbit",
@ -13,7 +14,10 @@
"workspace": false,
"packages": true,
"preferredPackages": [
"Microsoft/pxt-neopixel"
"Microsoft/pxt-neopixel",
"Microsoft/pxt-sonar",
"Microsoft/pxt-max6675",
"Microsoft/pxt-i2c-fram"
]
},
"blocksprj": {
@ -27,12 +31,14 @@
"description": "",
"files": [
"main.blocks",
"main.ts"
"main.ts",
"README.md"
]
},
"files": {
"main.blocks": "<xml xmlns=\"http://www.w3.org/1999/xhtml\">\n<block type=\"device_forever\">\n<statement name=\"HANDLER\">\n<block type=\"device_show_leds\">\n<field name=\"LED00\">FALSE</field>\n<field name=\"LED10\">FALSE</field>\n<field name=\"LED20\">FALSE</field>\n<field name=\"LED30\">FALSE</field>\n<field name=\"LED40\">FALSE</field>\n<field name=\"LED01\">FALSE</field>\n<field name=\"LED11\">TRUE</field>\n<field name=\"LED21\">FALSE</field>\n<field name=\"LED31\">TRUE</field>\n<field name=\"LED41\">FALSE</field>\n<field name=\"LED02\">FALSE</field>\n<field name=\"LED12\">FALSE</field>\n<field name=\"LED22\">FALSE</field>\n<field name=\"LED32\">FALSE</field>\n<field name=\"LED42\">FALSE</field>\n<field name=\"LED03\">TRUE</field>\n<field name=\"LED13\">FALSE</field>\n<field name=\"LED23\">FALSE</field>\n<field name=\"LED33\">FALSE</field>\n<field name=\"LED43\">TRUE</field>\n<field name=\"LED04\">FALSE</field>\n<field name=\"LED14\">TRUE</field>\n<field name=\"LED24\">TRUE</field>\n<field name=\"LED34\">TRUE</field>\n<field name=\"LED44\">FALSE</field>\n<next>\n<block type=\"device_show_leds\">\n<field name=\"LED00\">FALSE</field>\n<field name=\"LED10\">FALSE</field>\n<field name=\"LED20\">FALSE</field>\n<field name=\"LED30\">FALSE</field>\n<field name=\"LED40\">FALSE</field>\n<field name=\"LED01\">FALSE</field>\n<field name=\"LED11\">FALSE</field>\n<field name=\"LED21\">FALSE</field>\n<field name=\"LED31\">FALSE</field>\n<field name=\"LED41\">FALSE</field>\n<field name=\"LED02\">FALSE</field>\n<field name=\"LED12\">FALSE</field>\n<field name=\"LED22\">FALSE</field>\n<field name=\"LED32\">FALSE</field>\n<field name=\"LED42\">FALSE</field>\n<field name=\"LED03\">FALSE</field>\n<field name=\"LED13\">FALSE</field>\n<field name=\"LED23\">FALSE</field>\n<field name=\"LED33\">FALSE</field>\n<field name=\"LED43\">FALSE</field>\n<field name=\"LED04\">FALSE</field>\n<field name=\"LED14\">FALSE</field>\n<field name=\"LED24\">FALSE</field>\n<field name=\"LED34\">FALSE</field>\n<field name=\"LED44\">FALSE</field>\n</block>\n</next>\n</block>\n</statement>\n</block>\n</xml>",
"main.ts": "\r\n"
"main.ts": "basic.forever(() => {\r\n basic.showLeds(`\r\n . # . # .\r\n # . # . #\r\n # . . . #\r\n . # . # .\r\n . . # . .\r\n `)\r\n basic.showLeds(`\r\n . . . . .\r\n . . . . .\r\n . . . . .\r\n . . . . .\r\n . . . . .\r\n `)\r\n})\r\n",
"README.md": ""
}
},
"tsprj": {
@ -45,11 +51,13 @@
},
"description": "",
"files": [
"main.ts"
"main.ts",
"README.md"
]
},
"files": {
"main.ts": "basic.showLeds(`\r\n . . . . .\r\n . # . # .\r\n . . . . .\r\n # . . . #\r\n . # # # .\r\n `);"
"main.ts": "basic.showLeds(`\r\n . . . . .\r\n . # . # .\r\n . . . . .\r\n # . . . #\r\n . # # # .\r\n `);",
"README.md": ""
}
},
"compile": {
@ -73,7 +81,7 @@
"yottaTarget": "bbc-microbit-classic-gcc",
"yottaCorePackage": "pxt-microbit-core",
"githubCorePackage": "microsoft/pxt-microbit-core",
"gittag": "v0.2.2",
"gittag": "v0.3.1",
"serviceId": "ws"
},
"serial": {

View File

@ -227,6 +227,10 @@ namespace pxsim.control {
U.userError("reset not implemented in simulator yet")
}
export function waitMicros(micros: number) {
// TODO
}
export function deviceName(): string {
let b = board();
return b && b.id
@ -588,6 +592,13 @@ namespace pxsim.pins {
// TODO
}
export function pulseIn(name: number, value: number, maxDuration: number): number {
let pin = getPin(name);
if (!pin) return 0;
return 5000;
}
export function spiWrite(value: number): number {
// TODO
return 0;

View File

@ -470,7 +470,7 @@ namespace pxsim {
radio: RadioBus;
// display
image = createImage(5);
image = createInternalImage(5);
brigthness = 255;
displayMode = DisplayMode.bw;
font: Image = createFont();
@ -551,7 +551,6 @@ namespace pxsim {
default: theme = pxsim.micro_bit.randomTheme();
}
console.log("setting up microbit simulator")
let view = new pxsim.micro_bit.MicrobitBoardSvg({
theme: theme,
runtime: runtime
@ -609,14 +608,19 @@ namespace pxsim {
}
}
export class Image {
export class Image extends RefObject {
public static height: number = 5;
public width: number;
public data: number[];
constructor(width: number, data: number[]) {
super()
this.width = width;
this.data = data;
}
public print() {
console.log(`Image id:${this.id} refs:${this.refcnt} size:${this.width}x${Image.height}`)
}
public get(x: number, y: number): number {
if (x < 0 || x >= this.width || y < 0 || y >= 5) return 0;
return this.data[y * this.width + x];
@ -651,6 +655,12 @@ namespace pxsim {
}
}
export function createInternalImage(width: number): Image {
let img = createImage(width)
pxsim.noLeakTracking(img)
return img
}
export function createImage(width: number): Image {
return new Image(width, new Array(width * 5));
}
@ -662,7 +672,7 @@ namespace pxsim {
export function createImageFromString(text: string): Image {
let font = board().font;
let w = font.width;
let sprite = createImage(6 * text.length - 1);
let sprite = createInternalImage(6 * text.length - 1);
let k = 0;
for (let i = 0; i < text.length; i++) {
let charCode = text.charCodeAt(i);
@ -686,7 +696,7 @@ namespace pxsim {
let nb = data.length;
let n = nb / 5;
let font = createImage(nb);
let font = createInternalImage(nb);
for (let c = 0; c < n; c++) {
for (let row = 0; row < 5; row++) {
let char = data[c * 5 + row];

8
tests/base/tsconfig.json Normal file
View File

@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"noImplicitAny": true,
"outDir": "built",
"rootDir": "."
}
}

10
travis-tests.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
set -e
set -x
export KS_FORCE_CLOUD=yes
(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 https://az851932.vo.msecnd.net/files/td-converter-tests-v0.json)