Compare commits

...

107 Commits

Author SHA1 Message Date
6937c51549 0.2.93 2016-04-27 15:02:21 -07:00
69e90523e2 Bump pxt-core to 0.2.101 2016-04-27 15:02:19 -07:00
8431243b63 0.2.92 2016-04-27 13:38:07 -07:00
458b4553d2 Bump pxt-core to 0.2.100 2016-04-27 13:38:05 -07:00
0f6e8854d8 Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-04-27 13:13:13 -07:00
5565bb7d24 updated target definition 2016-04-27 13:13:03 -07:00
6c539fb04f Add some debugger hooks 2016-04-27 19:26:55 +01:00
b30a0ced87 removing references to missing files 2016-04-26 17:13:19 -07:00
ac942e198a missed file in previous checkin 2016-04-26 17:09:27 -07:00
cef1f57e30 expose device serial number in javascript 2016-04-26 17:09:15 -07:00
53bfea5752 updated charts 2016-04-26 16:40:55 -07:00
4917bb7e39 update chart 2 2016-04-26 16:38:27 -07:00
139823203e update charting activity 2016-04-26 16:34:10 -07:00
883f4d1a20 update images 2016-04-26 16:13:52 -07:00
0bce69edd0 updating images 2016-04-26 16:13:38 -07:00
efccc921cb Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-04-26 13:43:21 -07:00
55859b1237 support for exposing device name 2016-04-26 13:43:02 -07:00
ec09d40366 update charting 2016-04-26 12:34:58 -07:00
512e40fae3 clearer api name in serial 2016-04-26 12:19:42 -07:00
028dac25f6 updated lesson main 2016-04-26 12:04:05 -07:00
e0d4763974 update acc 2016-04-26 11:03:26 -07:00
3b3e402ffa Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-04-26 10:46:32 -07:00
e37ac1a1d7 0.2.91 2016-04-26 10:43:51 -07:00
17eb36a8dc Bump pxt-core to 0.2.99 2016-04-26 10:43:49 -07:00
10d44b97cc more serial infos 2016-04-26 10:29:05 -07:00
505c750dd0 Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-04-25 16:34:50 -07:00
d0e900606a update chart 2016-04-25 16:19:22 -07:00
dcbb076266 light update 2016-04-25 16:01:57 -07:00
22c852f2d9 udpate lessons 2016-04-25 15:59:28 -07:00
76770bc0e1 acc update 2016-04-25 15:57:02 -07:00
572080bc6d update charting 2016-04-25 15:55:52 -07:00
0b8142ae73 update acc 2016-04-25 15:54:28 -07:00
09a06d9fa9 update acc 2016-04-25 15:44:07 -07:00
80e8c6684d update acc 2016-04-25 15:41:47 -07:00
4cccb36f3d update csv 2016-04-25 15:36:06 -07:00
a427a1e720 update csv 2016-04-25 15:35:26 -07:00
be77c5296b update acc 2016-04-25 15:34:15 -07:00
a0c1b2c580 pic up 2016-04-25 15:32:50 -07:00
fc905c5f8f update acc chart 2016-04-25 15:26:49 -07:00
f1bd84733b acc update 2016-04-25 15:16:01 -07:00
d3080d2e66 acc update 2016-04-25 15:14:01 -07:00
090e530ff0 update lessons 2016-04-25 14:45:09 -07:00
094e9d25cd update lesson 2016-04-25 14:43:30 -07:00
0bcb9c16fa update lessons 2016-04-25 14:42:47 -07:00
269bdb82a6 update acceleration 2016-04-25 14:33:02 -07:00
cba7e02bcd update lesson 2016-04-25 14:29:48 -07:00
8ef834b73b update chrat 2016-04-25 13:58:41 -07:00
ec54622f52 update chart 2016-04-25 13:58:05 -07:00
5d90b70425 update chart 2016-04-25 13:55:03 -07:00
8cef13e517 update chart activity 2016-04-25 13:51:32 -07:00
82986c091b update charting 2016-04-25 12:45:10 -07:00
67f2fdcfec 0.2.90 2016-04-25 12:44:04 -07:00
d11c5a9028 Bump pxt-core to 0.2.98 2016-04-25 12:44:03 -07:00
b7cb7e477e update charting1 2016-04-25 12:42:39 -07:00
0d1059aedf update charting 2016-04-25 12:42:05 -07:00
b92fc783fa updated charting 2016-04-25 12:33:11 -07:00
6d73e5e129 update chartting 2016-04-25 11:51:47 -07:00
6150850729 glowing pend update 2016-04-25 11:32:20 -07:00
76a18fa61b updated glowing pendulum 2016-04-25 11:31:06 -07:00
2bd66ae4ef 0.2.89 2016-04-22 23:14:03 -07:00
f6eefde27c Bump pxt-core to 0.2.96 2016-04-22 23:14:01 -07:00
60c9e4a82f 0.2.88 2016-04-22 14:54:24 -07:00
56713227c5 0.2.87 2016-04-22 14:48:01 -07:00
fd6e110790 Bump pxt-core to 0.2.95 2016-04-22 14:47:59 -07:00
2336521df1 0.2.86 2016-04-22 13:38:45 -07:00
2ce72aeb28 Bump pxt-core to 0.2.93 2016-04-22 13:38:43 -07:00
e746c13212 don't filter or throttle serial, let the user deal with it. 2016-04-22 13:12:43 -07:00
9e073aee36 fixing doc links. fix for #49 2016-04-22 12:37:47 -07:00
3906f06a2f 0.2.85 2016-04-22 00:15:11 -07:00
d89747fa46 typo in default value 2016-04-22 00:14:57 -07:00
c4e6618baa 0.2.84 2016-04-22 00:07:31 -07:00
5232be58ce auto adjusting bar graph + debouncing sending data over serial 2016-04-21 23:44:22 -07:00
5a75483811 updated target definition 2016-04-21 22:46:40 -07:00
4b40585690 0.2.83 2016-04-21 14:26:36 -07:00
dd65efaab6 Bump pxt-core to 0.2.92 2016-04-21 14:26:34 -07:00
890c2566af 0.2.82 2016-04-20 07:13:06 -07:00
cd71fc5d13 Bump pxt-core to 0.2.89 2016-04-20 07:13:04 -07:00
f626dd4bbb 0.2.81 2016-04-19 20:52:09 -07:00
956992e9ab Bump pxt-core to 0.2.88 2016-04-19 20:52:08 -07:00
91ddcef6ce 0.2.80 2016-04-19 16:30:49 -07:00
49fa42473f Bump pxt-core to 0.2.86 2016-04-19 16:30:47 -07:00
564de8863a fix scrollbar 2016-04-19 13:26:00 -07:00
1dd70100d6 Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-04-19 13:25:46 -07:00
a38ff18eaf 0.2.79 2016-04-19 12:58:18 -07:00
d46ef1efca Bump pxt-core to 0.2.83 2016-04-19 12:58:16 -07:00
c54cd21efa Don't go through uBit object if not needed 2016-04-19 11:52:44 -07:00
94f18340ec prevent elastic scroll in simulator 2016-04-19 10:06:36 -07:00
13bdcf762d updated dal definition 2016-04-19 09:43:23 -07:00
6455da6adb 0.2.78 2016-04-18 22:55:03 -07:00
4e88ba4ef2 Bump pxt-core to 0.2.82 2016-04-18 22:55:01 -07:00
0c7d49256d don't use blockStatement anymore 2016-04-18 13:31:05 -07:00
c2883d00ee use registerwithdal in simulator 2016-04-18 10:46:44 -07:00
7da483f258 fixing links 2016-04-18 09:47:34 -07:00
6cbc6a53b2 more missing simulator functions 2016-04-18 09:47:27 -07:00
5e23bc96ca don't expose storage in blocks 2016-04-18 09:21:11 -07:00
4169663a8b fixing broken links 2016-04-18 08:33:09 -07:00
4795c58e97 initial blocks for storage 2016-04-16 07:45:04 -07:00
8fb96934ca panic when radio does not start 2016-04-15 22:41:30 -07:00
cd91504c1f fix help urls 2016-04-15 16:54:44 -07:00
91e8196621 0.2.77 2016-04-15 16:47:36 -07:00
26841de6cf bring back 'write number' 2016-04-15 16:40:51 -07:00
24f2a45310 0.2.76 2016-04-15 16:36:40 -07:00
67c5f0612a added serial docs 2016-04-15 16:36:31 -07:00
d7c3f1b50a various docs fixes 2016-04-15 16:15:08 -07:00
2fb6025848 fixed banana 2016-04-15 16:02:50 -07:00
8da3c5eb84 various docs fixes 2016-04-15 15:53:20 -07:00
4ee1799271 more docs 2016-04-15 15:40:55 -07:00
109 changed files with 901 additions and 328 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@ temp
projects
win10/app/bin
win10/app/bld
win10/*.opendb
*.user
*.sw?

View File

@ -69,7 +69,11 @@ When your micro:bit isnt connected to your computer, tablet or mobile, you wi
The pins labelled 3V and GND are the power supply pins.
You can attach an external device such as a motor to these and power it using the battery or USB.
### Bluetooth Low Energy Antenna
### Serial Communication
The BBC micro:bit can send an receive data via [serial communication](/device/serial). The serial data can be transfered via USB or BlE.
### Bluetooth Low Energy (BLE) Antenna
You will see the label BLE ANNTENA on the back of your micro:bit. It is for a messaging service,
so that devices can talk to each other. The micro:bit is a peripheral

View File

@ -11,9 +11,7 @@ This example displays a random number every time the crocodile clip holds `GND`
### Connecting Crocodile Clips
![](/static/mb/crocodile-clips-1.jpg)
![](/static/mb/crocodile-clips-2.jpg)
### Lessons

View File

@ -2,7 +2,9 @@
The micro:bit LED screen
![](/static/mb/device/screen-0.png)
```sim
basic.showString(" ");
```
The micro:bit LED screen consists of 25 red LED lights arranged in a 5X5 grid (5 LEDs across by 5 LEDs down).
@ -30,11 +32,21 @@ Since the row and column numbers start at 0, an easy way to figure out the x, y
### Turn a LED on/off
Use [plot](/led/plot) and [unplot](/led/unplot) to turn a LED on or off
Use [plot](/reference/led/plot) and [unplot](/reference/led/unplot) to turn a LED on or off
```blocks
led.plot(0,0)
led.unplot(0,0)
```
### Is a LED on/off?
Use the [point](/led/point) function to find out if a LED is on or off.
Use the [point](/reference/led/point) function to find out if a LED is on or off.
```blocks
if(led.point(0,0)) {
}
```
### Display images, strings and numbers
@ -44,14 +56,14 @@ Instead of turning individual LEDs on or off, as above, you can display an [imag
The micro:bit runtime keeps an in-memory representation of the state of all 25 LEDS. This state is known as the "display buffer" and controls which LEDS are on and which are off. The plot/unplot/point functions access the display buffer directly. On the other hand, the functions that show an image, number or string overwrite the buffer completely. To illustrate, first try running this code sequence
```
basic.showString("d", 150)
```blocks
basic.showString("d")
led.plot(0, 0)
```
You will see the letter "d" displayed as well as the LED in position `0,0` lit up. Now try reversing the order of the two statements above:
```
```blocks
led.plot(0, 0)
basic.showString("d", 150)
```

64
docs/device/serial.md Normal file
View File

@ -0,0 +1,64 @@
# Serial
The [serial](/reference/serial) supports [serial communication](https://en.wikipedia.org/wiki/Serial_port) between the BBC micro:bit and another computer. Basically, this allows you to send data from the micro:bit to your own computer. This is very useful for debugging purposes: you can add `write line` statements in your code and see them display on your computer as the program executes.
The code below shows a simple script that sends a line when the BBC micro:bit starts and another line each time the button ``A`` is pressed.
```blocks
serial.writeLine("started...")
input.onButtonPressed(Button.A, () => {
serial.writeLine("A pressed")
})
```
## How to read the micro:bit's serial output from your computer
Unfortunately, using the serial library requires quite a bit of a setup.
### Windows
You must install a device driver (for the computer to recognize the serial interface of the micro:bit); then, you must also install a terminal emulator (which is going to connect to the micro:bit and read its output). Here's how to do it:
* Follow instructions at https://developer.mbed.org/handbook/Windows-serial-configuration in order to install the device driver
* Install a terminal emulator; we recommend [Tera Term](https://ttssh2.osdn.jp/index.html.en). At the time of this writing, the latest version is 4.88 and can be downloaded [from here](http://en.osdn.jp/frs/redir.php?m=jaist&f=%2Fttssh2%2F63767%2Fteraterm-4.88.exe). Follow the instructions from the installer.
Once both the driver and the terminal emulator are installed, plug in the micro:bit and wait until the device is fully setup. Then, open TeraTerm.
* Hit `File` > `New Connection`
* Check "Serial"; in the dropdown menu, pick the COM port that says "mbed Serial Port". Hit `Ok`.
* In the menus, hit `Setup` > `Serial Port` and set the baud rate to `115200`.
You should be good. Feel free to hit `Setup` > `Save Setup` in the menus to erase the default configuration file with a new one so that you don't have to type in the settings again.
Please note that Windows will assign you a different COM port if you plug in another micro:bit. If you're juggling between micro:bits, you'll have to change the COM port every time.
### Alternative Windows setup with Putty
If you prefer another terminal emulator (such as [PuTTY](http://www.putty.org/)), here are some instructions.
* Open Windows's [Device Manager](https://windows.microsoft.com/en-us/windows/open-device-manager); expand the section called "Ports (COM & LPT)"; write down the com number for "mbed Serial Port" (e.g. COM14)
* Open PuTTY; on the main screen, use the following settings: Serial / COM14 / 115200. Replace COM14 with the COM port number you wrote down previously. Feel free to type in a name and hit "Save" to remember this configuration.
![](/static/mb/serial-library-0.png)
* (optional): in the "Terminal" section, check "implicit cr in every lf"
![](/static/mb/serial-library-1.png)
### Linux
(Untested).
* Plug in the micro:bit
* Open a terminal
* `dmesg | tail` will show you which `/dev/` node the micro:bit was assigned (e.g. `/dev/ttyUSB0`)
* Then, do: `screen /dev/ttyUSB0 115200` (install the `screen` program if you don't have it). To exit, run `Ctrl-A` `Ctrl-D`.
Alternative programs include minicom, etc.
### Mac OS
* Plug in the micro:bit
* Open a terminal
* `ls /dev/cu.*` will return to you a list of serial devices; one of them will look like `/dev/cu.usbmodem1422` (the exact number depends on your computer)
* `screen /dev/cu.usbmodem1422 115200` will open up the micro:bit's serial output. To exit, hit `Ctrl-A` `Ctrl-D`.

View File

@ -0,0 +1,25 @@
# Simulator
The JavaScript simulator allows to test and execute most BBC micro:bit programs in the browser.
It allows to emulate sensor data or user interactions.
```sim
input.onButtonPressed(Button.A, () => {
basic.showString("A");
});
input.onButtonPressed(Button.B, () => {
basic.showString("B");
});
input.onPinPressed(TouchPin.P0, () => {
basic.showString("0");
});
input.onPinPressed(TouchPin.P1, () => {
basic.showString("1");
});
input.onPinPressed(TouchPin.P2, () => {
basic.showString("2");
});
input.temperature()
input.compassHeading()
input.lightLevel()
```

View File

@ -31,12 +31,6 @@ Windows
Mac (picture bvabdbco)
WARN: unknown picture: bvabdbco:5x3
### ~hide
If your computer doesn't recognise your micro:bit, please see [troubleshooting USB problems](/diagnosing-usb).
### ~
## Step 2: Compile your script
Next, compile your script:
@ -133,5 +127,5 @@ Or it may appear that there are two hex files on your micro:bit so the micro:bit
### See also
[Run code in a browser](/js/simulator)
[Run code in a browser](/device/simulator)

View File

@ -5,6 +5,9 @@
### ~column
## O365 Integration
* [Science Experiments: Graphing & Charting](/lessons/charting), create an app for simulating and measuring sensor data of acceleration, temperature, light level, and rotation
## Beginner
* [Beautiful Image](/lessons/beautiful-image), show a beautiful image with show LEDs
@ -58,7 +61,6 @@
* [Pogo](/lessons/pogo), create a pogo game to test your jumping abilities
## Advanced
* [Charting](/lessons/charting), create a charting app between 2 BBC micro:bits
* [Prank WiFi](/lessons/prank-wifi), create fake WiFi to trick your friends
* [Speed Button](/lessons/speed-button), code a speed game with running time
* [Headbands](/lessons/headbands), create a charades game with a collection of strings that hold the words

View File

@ -79,7 +79,18 @@ Your banana keyboard is ready!
### Step 10
Connect your micro:bit to your computer using your USB cable and run the [banana keyboard](/lhpkbr) script on it. Tap your banana instrument to play sound against... the fruit!
Connect your micro:bit to your computer using your USB cable and run this script:
```blocks
let sound = music.noteFrequency(Note.C);
input.onPinPressed(TouchPin.P1, () => {
for (let i = 0; i < 5; i++) {
sound = sound + 25;
music.playTone(sound, music.beat(BeatFraction.Sixteenth));
}
});
```
Tap your banana instrument to play sound against... the fruit!
### ~avatar boothing

View File

@ -26,10 +26,10 @@ Learn how to create a catch the egg game game with **plot**, `led->plot` , **unp
* **plot** : [read more...](/reference/led/plot)
* **if** : [read more...](/reference/logic/if)
* **acceleration** : [read more...](/reference/input/acceleration)
* **math minimum number** : [read more...](/js/math)
* **math maximum number** : [read more...](/js/math)
* **math random number** : [read more...](/js/math)
* **math modulus** : [read more...](/js/math)
* **math minimum number** : [read more...](/reference/math)
* **math maximum number** : [read more...](/reference/math)
* **math random number** : [read more...](/reference/math)
* **math modulus** : [read more...](/reference/math)
* **show number** : [read more...](/reference/basic/show-number)
* **pause** : [read more...](/reference/basic/pause)

View File

@ -1,15 +1,14 @@
# charting lesson
Measure the acceleration on the micro:bit in the "z" direction.
Create a charting app for simulating and measuring the acceleration applied to the micro:bit
## Topic
Acceleration
## Quick Links
* [activity](/lessons/charting/activity)
* [Chart Acceleration: Activity](/lessons/charting/acceleration)
* [Chart Acceleration: Challenge](/lessons/charting/acceleration-challenge)
## Prior learning/place of lesson in scheme of work
@ -18,9 +17,9 @@ Learn the functions of **on data received**, **send number** and **receive numbe
## Documentation
```cards
basic.showNumber(0)
input.acceleration(Dimension.X)
led.plotBarGraph(0, 1023)
basic.showNumber(0)
radio.onDataReceived(() => {})
radio.sendNumber(0)
radio.receiveNumber()

View File

@ -0,0 +1,99 @@
# Chart Acceleration: Challenge
### ~avatar avatar
Welcome! The activity will teach you how to use the acceleration of the 1st micro:bit and to visualize the acceleration on the 2nd micro:bit. Let's get started!
### ~
Let's measure `acceleration (mg)` and then `send number`. `Acceleration` is measured in **milli-gravities**, so a value of -1000 is equivalent to -1g or -9.81m/s^2. We will be able to get the acceleration value (g-force), in the specified "x" dimension. `Send number` will broadcast a number data packet to other micro:bits connected via radio.
```blocks
radio.sendNumber(input.acceleration(Dimension.X));
```
### ~
We want to display the acceleration forever. In order to do so, we need a `forever` loop. A forever loop will repeat code in the background forever.
```blocks
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X));
});
```
### ~
We want to register code to run when a packet is received over radio. We can implement this code by adding `on data received`.
```blocks
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X))
})
radio.onDataReceived(() => {
})
```
### ~
Finally, we want to chart the acceleration. So we must first implement `plot bar graph`. `Plot Bar Graph` will display a vertical bar graph based on the value and high value. In order to transfer the receive the number from the 1st micro:bit, we must implement `receive number` to constantly display a vertical bar graph based on the value. Remember, the value will equal to the micro:bit's acceleration in the "x" direction.
```blocks
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X))
})
radio.onDataReceived(() => {
led.plotBarGraph(radio.receiveNumber(), 1023)
})
```
### ~
Notice that moving the micro:bit the farthest direction in the x direction will be -1023 on the charting beneath the simulator. The second observation will be that the LEDs will be full brightness on the 2nd micro:bit. There is a single LED turned on with the 1st micro:bit. Additionally, the graphs will reflect 0 acceleation for the 1st micro:bit. In this scenario, if you are adjusting the acceleration in the simualator, you are also changing your chart that will be produced.
![](/static/mb/acc.png)
### ~
NOTE: The colors of the charts reflect the color of the micro:bit simulator. In this instance, the micro:bits are blue and green. So the colors of the line graphs reflect the colors of the micro:bit
### ~
After running this simulatation several seconds by moving the micro:bit side to side in the x direction, you are ready to graph or chart the accceleration of the micro:bit. We want a printout of our acceleration on Excel. We will graph the fluctuating acceleration of the simulation experiment.
![](/static/mb/acc2.png)
### ~
Finally, you must open the Excel CSV file by clicking on the data.xls file that was downloaded to Downloads Folder.
![](/static/mb/data3.png)
Use the Recommended Charts command on the Insert tab to quickly create a chart thats just right for your data.
* Select the data that you want to include in your chart.
* Click Insert > Recommended Charts.
![](/static/mb/chart1.png)
* On the Recommended Charts tab, scroll through the list of chart types that Excel recommends for your data.
Click any chart type to see how your data will look in that format.
When you find the chart type that you want, click it, and then click OK. We want to select the chart called Line. A line chart is used to display trends over time. We will use the line chart because there are many data points over time.
Tip: If you dont see a chart type that you want, click the All Charts tab to see all of the available chart types.
![](/static/mb/chart_title.png)
* Use the Chart Elements, Chart Styles, and Chart Filters buttons next to the upper-right corner of the chart to add chart elements like axis titles or data labels, to customize the look of your chart
![](/static/mb/elements_styles_filters.png)
### ~
Have fun reviewing your simulation and analyze the acceleration by chart the Excel data using Excel.
* Connect the first micro:bit to your computer using your USB cable and run the charting script on it.
* Connect the second micro:bit to your computer using your USB cable and run the charting script on it.
* The first person and second person take turns tilting the micro:bit in the "x" direction while the other player charts the data on the micro:bit!
* Review and analyze the actual micro:bit device acceleration data on Excel
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/lessons/charting/acceleration)
### ~

View File

@ -0,0 +1,85 @@
# Chart Acceleration: Activity
Measure the acceleration on the micro:bit in the "x" direction.
### ~avatar avatar
Welcome! This activity will teach how to use the micro:bit to chart the acceleration in the "x" direction. Let's get started!
### ~
Let's measure `acceleration (mg)` in the "x" direction. Get the acceleration value (milli g-force), in one of three specified dimensions.
```blocks
input.acceleration(Dimension.X)
```
### ~
Use the plot bar chart to visualize the acceleration on the LED screen of the micro:bit in the specified range. You implement plot Bar Graph to display a vertical bar graph based on the "value" and "high" value. Then you must insert acceleration in the X dimension to measure the acceleration.
```blocks
basic.forever(() => {
led.plotBarGraph(input.acceleration(Dimension.X), 0)
})
```
### ~
Notice that moving the micro:bit in the simulator from left to right (x direction) changes the values beneath the micro:bit in a range from 1023 to -1023 as measured in milli-gravities. By hovering over the micro:bit from left to right, you can observe changing values beneath the micro:bit simulator. Also, the LEDs shown on the Bar Graph fluctates based on the movement of the micro:bit simulator in the x direction. The line underneath the micro:bit simulator reflect the acceleration in the x direction.
NOTE: The colors of the charts reflect the color of the micro:bit simulator. In this instance, the micro:bit is yellow. So the color of the data line reflects the color of the micro:bit
![](/static/mb/data4.png)
### ~
Vigorously move the micro:bit in the micro:bit simulatator by moving the micro:bit image from side to side. Every time the micro:bit moves in the x direction in the simulator, you are generating data points that can be reviewed in Excel. The more attempts to move the micro:bit from side to side, the more data being saved in Excel. After you have vigarously moved the micro:bit simulator from side to side for a sufficient amount of time, you are ready to graph or chart the accceleration of the micro:bit. We want a printout of our acceleration on Excel that can be graphed in Excel.
### ~
Review and write down your observations from the Excel data. Then chart or graph the data collected by using a tool in Excel.
The final part of this experiment is opening and reviewing the data in the Excel CSV file. Simply click on the line beneath the simulator. A CSV file will be generated to display the data points collected by moving the micro:bit in the X direction. Then click or tap on the data Excel file that was downloaded to your local Downloads Folder.
### ~
First, click or tap on the first two columns (A, B) to include the time of the data being collected; b) the results of acceleration data on the micro:bit
![](/static/mb/data7.png)
Use the Recommended Charts command on the Insert tab to quickly create a chart thats just right for your data.
* Select the data that you want to include in your chart.
* Click Insert > Recommended Charts.
![](/static/mb/chart1.png)
* On the Recommended Charts tab, scroll through the list of chart types that Excel recommends for your data.
Click any chart type to see how your data will look in that format.
When you find the chart type that you want, click it, and then click OK. We want to select the chart called Line. A line chart is used to display trends over time. We will use the line chart because there are many data points over time.
Tip: If you dont see a chart type that you want, click the All Charts tab to see all of the available chart types.
![](/static/mb/chart_title.png)
* Use the Chart Elements, Chart Styles, and Chart Filters buttons next to the upper-right corner of the chart to add chart elements like axis titles or data labels, to customize the look of your chart
![](/static/mb/elements_styles_filters.png)
* Connect a micro:bit to your computer using your USB cable; compile; and repeat this experiment by moving the micro:bit in the "x" direction. Then collect and chart the data on Excel.
* Review and analyze the actual micro:bit device data on Excel
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/lessons/charting/acceleration-challenge)
### ~

View File

@ -1,53 +0,0 @@
# charting activity
Measure the acceleration on the micro:bit in the "z" direction.
### ~avatar avatar
### ~
Welcome! This activity will teach how to use the 1st micro:bit to chart the second micro:bit's acceleration in the "x" direction. Let's get started!
Let's measure `acceleration (mg)` and then `send number`. `Acceleration` is measured in **milli-gravities**, so a value of -1000 is equivalent to -1g or -9.81m/s^2. We will be able to get the acceleration value (g-force), in the specified "x" dimension. `Send number` will broadcast a number data packet to other micro:bits connected via radio.
```blocks
radio.sendNumber(input.acceleration(Dimension.X));
```
We want to display the acceleration forever. In order to do so, we need a `forever` loop. A forever loop will repeat code in the background forever.
```blocks
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X));
});
```
We want to register code to run when a packet is received over radio. We can implement this code by adding `on data received`.
```blocks
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X))
})
radio.onDataReceived(() => {
})
```
Finally, we want to chart the acceleration. So we must first implement `plot bar graph`. `Plot Bar Graph` will display a vertical bar graph based on the value and high value. In order to transfer the receive the number from the 1st micro:bit, we must implement `receive number` to constantly display a vertical bar graph based on the value. Remember, the value will equal to the micro:bit's acceleration in the "x" direction.
```blocks
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X))
})
radio.onDataReceived(() => {
led.plotBarGraph(radio.receiveNumber(), 1023)
})
```
* Connect the first micro:bit to your computer using your USB cable and run the charting script on it.
* Connect the second micro:bit to your computer using your USB cable and run the charting script on it.
* The first person and second person take turns tilting the micro:bit in the "x" direction while the other player charts the data on the micro:bit!

View File

@ -0,0 +1,118 @@
# charting light
Measure the light level on the micro:bit from light to dark.
### ~avatar avatar
Welcome! This activity will teach how to use the micro:bit to chart the light level from light to dark. Let's get started!
### ~
Let's measure the light level from dark to light. Get the acceleration value (milli g-force), in one of three specified dimensions.
```blocks
input.lightLevel()
```
### ~
Use the plot bar chart to visualize the acceleration on the LED screen of the micro:bit in the specified range. You implement plot Bar Graph to display a vertical bar graph based on the "value" and "high" value. Then you must insert acceleration in the X dimension to measure the acceleration.
```blocks
basic.forever(() => {
led.plotBarGraph(input.acceleration(Dimension.X), 0)
})
```
### ~
Notice that moving the micro:bit in the simulator from left to right (x direction) changes the values beneath the micro:bit in a range from 1023 to -1023 as measured in milli-gravities. By hovering over the micro:bit from left to right, you can observe changing values beneath the micro:bit simulator. Also, the LEDs shown on the Bar Graph fluctates based on the movement of the micro:bit simulator in the x direction. The line underneath the micro:bit simulator reflect the acceleration in the x direction.
NOTE: The colors of the charts reflect the color of the micro:bit simulator. In this instance, the micro:bit is yellow. So the color of the data line reflects the color of the micro:bit
![](/static/mb/data4.png)
### ~
Vigorously move the micro:bit in the micro:bit simulatator by moving the micro:bit image from side to side. Every time the micro:bit moves in the x direction in the simulator, you are generating data points that can be reviewed in Excel. The more attempts to move the micro:bit from side to side, the more data being saved in Excel. After you have vigarously moved the micro:bit simulator from side to side for a sufficient amount of time, you are ready to graph or chart the accceleration of the micro:bit. We want a printout of our acceleration on Excel that can be graphed in Excel.
### ~
The final part of this experiment is opening and reviewing the data in the Excel CSV file. Simply click on the line beneath the simulator. A CSV file will be generated to display the data points collected by moving the micro:bit in the X direction. Then click or tap on the data Excel file that was downloaded to your local Downloads Folder.
![](/static/mb/data3.png)
### ~
* Review and write down your observations from the Excel data.
* Chart the data collected by using a graph in Excel
* Connect a micro:bit to your computer using your USB cable; compile; and move the micro:bit in the "x" direction.
* Review and analyze the actual micro:bit device data on Excel
### ~avatar avatar
Welcome! The activity will teach you how to use the acceleration of the 1st micro:bit and to visualize the acceleration on the 2nd micro:bit. Let's get started!
### ~
Let's measure `acceleration (mg)` and then `send number`. `Acceleration` is measured in **milli-gravities**, so a value of -1000 is equivalent to -1g or -9.81m/s^2. We will be able to get the acceleration value (g-force), in the specified "x" dimension. `Send number` will broadcast a number data packet to other micro:bits connected via radio.
```blocks
radio.sendNumber(input.acceleration(Dimension.X));
```
### ~
We want to display the acceleration forever. In order to do so, we need a `forever` loop. A forever loop will repeat code in the background forever.
```blocks
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X));
});
```
### ~
We want to register code to run when a packet is received over radio. We can implement this code by adding `on data received`.
```blocks
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X))
})
radio.onDataReceived(() => {
})
```
### ~
Finally, we want to chart the acceleration. So we must first implement `plot bar graph`. `Plot Bar Graph` will display a vertical bar graph based on the value and high value. In order to transfer the receive the number from the 1st micro:bit, we must implement `receive number` to constantly display a vertical bar graph based on the value. Remember, the value will equal to the micro:bit's acceleration in the "x" direction.
```blocks
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X))
})
radio.onDataReceived(() => {
led.plotBarGraph(radio.receiveNumber(), 1023)
})
```
### ~
Notice that moving the micro:bit the farthest direction in the x direction will be -1023 on the charting beneath the simulator. The second observation will be that the LEDs will be full brightness on the 2nd micro:bit. There is a single LED turned on with the 1st micro:bit. Additionally, the graphs will reflect 0 acceleation for the 1st micro:bit. In this scenario, if you are adjusting the acceleration in the simualator, you are also changing your chart that will be produced.
![](/static/mb/acc.png)
### ~
NOTE: The colors of the charts reflect the color of the micro:bit simulator. In this instance, the micro:bits are blue and green. So the colors of the line graphs reflect the colors of the micro:bit
### ~
After running this simulatation several seconds by moving the micro:bit side to side in the x direction, you are ready to graph or chart the accceleration of the micro:bit. We want a printout of our acceleration on Excel. We will graph the fluctuating acceleration of the simulation experiment.
![](/static/mb/acc2.png)
### ~
Finally, you must open the Excel CSV file by clicking on the data.xls file that was downloaded to Downloads Folder.
![](/static/mb/data3.png)
### ~
Have fun reviewing your simulation and analyze the acceleration by chart the Excel data using Excel.
* Connect the first micro:bit to your computer using your USB cable and run the charting script on it.
* Connect the second micro:bit to your computer using your USB cable and run the charting script on it.
* The first person and second person take turns tilting the micro:bit in the "x" direction while the other player charts the data on the micro:bit!
* Review and analyze the actual micro:bit device acceleration data on Excel

View File

@ -1,41 +0,0 @@
# crocodile clip activity
Use the crocodile clips
# micro:bit crocodile clip
![](/static/mb/blocks/lessons/crocodile-clip-0.jpg)
In this project, you will build a circuit with the micro:bit from crocodile clips. Project duration: 15 minutes.
## Materials
* micro:bit, battery holder and 2 AAA batteries
* Crocodile clips
## Steps
### Step 1
![](/static/mb/lessons/banana-keyboard-1.png)
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
### Step 2
![](/static/mb/crocodile-clips-2.jpg)
Using the 1st crocodile clip, connect the unattached end of the crocodile clip onto the 0 pin on the micro:bit.
### Step 3
![](/static/mb/blocks/lessons/crocodile-clip-0.jpg)
Disconnect the end of the crocodile clip from the 0 pin of the micro:bit.
Your circuit is complete!
### Step 10
Connect your micro:bit to your computer using your USB cable and run the [guess the number](/lhpkbr) script on it.

View File

@ -15,8 +15,6 @@ basic.forever(() => {
Now let's measure the acceleration on the `y` axis and store that value in a variable. The `acceleration(y)` function will provide the value.
![](/static/mb/blocks/lessons/glowing-pendulum-1.png)
```blocks
basic.forever(() => {
let acceleration = input.acceleration(Dimension.Y);
@ -25,7 +23,6 @@ basic.forever(() => {
Since the micro:bit will be swinging back and forth, the acceleration will only be positive half of the time. Thus, to always get a positive value, we want to take the absolute value of the acceleration.
![](/static/mb/blocks/lessons/glowing-pendulum-2.png)
```blocks
let acceleration = 0;
@ -37,15 +34,50 @@ basic.forever(() => {
The function `acceleration(y)` returns a number between 0 and 1024. We want to use this value for the brightness of the micro:bit, but the `set brightness()` only accepts a value between 0 and 256. Thus, we need to divide the acceleration by 4 to ensure we will be in the appropriate range.
![](/static/mb/blocks/lessons/glowing-pendulum-3.png)
```blocks
basic.forever(() => {
let acceleration = input.acceleration(Dimension.Y);
acceleration = Math.abs(acceleration);
acceleration = acceleration / 4;
});
```
Now let's use our acceleration value to set the brightness on the micro:bit.
![](/static/mb/blocks/lessons/glowing-pendulum-4.png)
```blocks
basic.forever(() => {
let acceleration = input.acceleration(Dimension.Y);
acceleration = Math.abs(acceleration);
acceleration = acceleration / 4;
led.setBrightness(acceleration)
});
```
Let's show what the brightness of the micro:bit is by turning all the LEDs on!
![](/static/mb/blocks/lessons/glowing-pendulum-5.png)
```blocks
basic.forever(() => {
let acceleration = input.acceleration(Dimension.Y);
acceleration = Math.abs(acceleration);
acceleration = acceleration / 4;
led.setBrightness(acceleration)
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
});
```
### ~avatar avatar

View File

@ -6,7 +6,23 @@ Coding challenges for the glowing pendulum tutorial.
Complete the following [glowing pendulum activity](/lessons/glowing-pendulum/activity) and your code should look like this:
![](/static/mb/blocks/lessons/glowing-pendulum-5.png)
```blocks
basic.forever(() => {
let acceleration = input.acceleration(Dimension.Y);
acceleration = Math.abs(acceleration);
acceleration = acceleration / 4;
led.setBrightness(acceleration)
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
});
```
**Challenge 1**

View File

@ -44,13 +44,3 @@ let accelerationDivided = accelerationX / 4
led.setBrightness(accelerationX)
```
## 5. Write the code that tuns all the LEDs on (as the image displays below)
![](/static/mb/lessons/glowing-pendulum-1.png)
<br/>
```
led.plotAll()
```

View File

@ -24,11 +24,4 @@ Answer the questions while completing the tutorial. Pay attention to the dialogu
## 4. Write the code to include acceleration value question 3 to set the brightness on the BBC micro:bit.
<br/>
## 5. Write the code that tuns all the LEDs on (as the image displays below)
![](/static/mb/lessons/glowing-pendulum-1.png)
<br/>

View File

@ -42,13 +42,13 @@ Learn how to create a charades game with **collections**, ` create -> Collection
## Documentation
* **collection**
* **global variables** : [read more...](/js/data)
* **global variables** : [read more...](/reference/variables/globals.md)
* **Boolean** : [read more...](/reference/types/boolean)
* **on logo up** [read more...](/functions/on-logo-up)
* **on screen down** [read more...](/functions/on-screen-down)
* **on screen up** [read more...](/functions/on-screen-up)
* **show string** : [read more...](/reference/basic/show-string)
* **game library** : [read more...](/js/game-library)
* **game library** : [read more...](/reference/game-library)
## Resources

View File

@ -22,7 +22,7 @@ Learn how to declare a **Boolean** variable, `var t:= true` `var f:=false` for o
## Documentation
* **running time** : [read more...](/reference/input/running-time)
* **global variable** : [read more...](/js/data)
* **global variable** : [read more...](/reference/variables/globals)
* **Boolean** : [read more...](/reference/types/boolean)
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
* **if** : [read more...](/reference/logic/if)

View File

@ -42,7 +42,7 @@ Overview of Blocks lessons for the BBC micro:bit.
* [Truth or dare](/lessons/truth-or-dare), a game that forces each player to reveal a secret or do something funny with if statement
* [Spinner](/lessons/spinner), spin the arrow with multiple if statements
* [Die roll](/lessons/die-roll), spin with more if statements
* [Beatbox](/lessons/beatbox), make a beatbox music player with variables
* [Beatbox](/lessons/classic-beatbox), make a beatbox music player with variables
* [Temperature](/lessons/temperature), get the ambient temperature (degree Celsius °C)
### ~

View File

@ -57,9 +57,9 @@ input.onButtonPressed(Button.A, () => {
### Lessons
[blink](/lessons/blink), [bounce-image](/lessons/bounce-image), [snowflake-fall](/lessons/snowflake-fall), [flashing-heart](/lessons/flashing-heart)
[blink](/lessons/blink), [snowflake-fall](/lessons/snowflake-fall), [flashing-heart](/lessons/flashing-heart)
### See also
[while](/js/while), [on button pressed](/reference/input/on-button-pressed), [in background](/reference/control/in-background)
[while](/reference/loops/while), [on button pressed](/reference/input/on-button-pressed), [in background](/reference/control/in-background)

View File

@ -27,5 +27,5 @@ for (let i = 0; i < 5; i++) {
### See also
[while](/js/while), [running time](/reference/input/running-time), [for](/reference/loops/for)
[while](/reference/loops/while), [running time](/reference/input/running-time), [for](/reference/loops/for)

View File

@ -57,5 +57,5 @@ Use [forever](/reference/basic/forever) to continually repeat an animation
### Lessons
[smiley](/lessons/smiley), [bounce image](/lessons/bounce-image), [snowflake fall](/lessons/snowflake-fall), [rotation animation](/lessons/rotation-animation)
[smiley](/lessons/smiley), [snowflake fall](/lessons/snowflake-fall), [rotation animation](/lessons/rotation-animation)

View File

@ -41,5 +41,5 @@ In JavaScript, the led off is represented by a `.` and the led on by a `#` chara
### See also
[plot leds](/reference/led/plot-leds), [show animation](/reference/led/show-animation)
[plot leds](/reference/led/plot-leds), [show animation](/reference/basic/show-animation)

View File

@ -48,5 +48,5 @@ for (let i = 0; i < 5; i++) {
### See also
[show string](/reference/basic/show-string), [show animation](/reference/basic/show-animation), [Number](/reference/types/number), [math library](/js/math)
[show string](/reference/basic/show-string), [show animation](/reference/basic/show-animation), [Number](/reference/types/number), [math library](/reference/math)

View File

@ -33,9 +33,9 @@ basic.showString(s)
### Lessons
[answering machine](/lessons/answering-machine), [rock paper scissors](/lessons/rock-paper-scissors), [love meter](/lessons/love-meter), [digital pet](/lessons/digital-pet)
[answering machine](/lessons/answering-machine), [rock paper scissors](/lessons/rock-paper-scissors), [love meter](/lessons/love-meter)
### See also
[String](/reference/types/string), [string functions](/reference/types/string-functions), [show number](/reference/basic/show-number), [show animation](/reference/basic/show-animation)
[String](/reference/types/string), [show number](/reference/basic/show-number), [show animation](/reference/basic/show-animation)

View File

@ -8,14 +8,9 @@ The functions in the ``devices`` namespace allow the BBC micro:bit to communicat
The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device.
### Block Editor
![](/static/mb/on-gamepad-button-0.png)
### KindScript
```
export function onGamepadButton(name: string, body:td.Action)
```sig
devices.onGamepadButton(MesDpadButtonInfo.ADown, () => {})
```
### Parameters
@ -24,5 +19,4 @@ export function onGamepadButton(name: string, body:td.Action)
### See Also
[tell remote control to](/reference/devices/tell-remote-control-to), [raise alert to](/reference/devices/raise-alert-to), [on notified](/reference/devices/on-notified), [signal strength](/reference/devices/signal-strength), [on signal strength changed](/reference/devices/on-signal-strength-changed)
[tell remote control to](/reference/devices/tell-remote-control-to), [raise alert to](/reference/devices/raise-alert-to), [signal strength](/reference/devices/signal-strength), [on signal strength changed](/reference/devices/on-signal-strength-changed)

View File

@ -10,14 +10,8 @@ The functions in the ``devices`` namespace allow the BBC micro:bit to communicat
The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device.
### Block Editor
![](/static/mb/on-signal-strength-changed-0.png)
### KindScript
```
export function onSignalStrengthChanged(body:td.Action)
```sig
devices.onSignalStrengthChanged(() => {})
```
### Parameters

View File

@ -4,19 +4,14 @@ The raise alert to function.
Raise an alert on a remote device.
##
## Bluetooth required
The functions in the ``devices`` namespace allow the BBC micro:bit to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart).
The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device.
### KindScript
![](/static/mb/raise-alert-to-0.png)
### KindScript
```
```sig
export function raiseAlertTo(event: string)
```

View File

@ -12,14 +12,8 @@ This API does not contain any form of encryption, authentication or authorizatio
For serious applications, BLE should be considered a substantially more secure alternative.
### Block Editor
![](/static/mb/receive-number-0.png)
### KindScript
```
export function receiveNumber() : number
```sig
radio.receiveNumber();
```
### Returns

View File

@ -4,20 +4,14 @@ The `signal strength` function.
Returns the signal strength reported by the paired device from ``0`` (no signal) to ``4`` (full strength).
## Bluetooth required
## Important Security Consideration
The functions in the ``devices`` namespace allow the BBC micro:bit to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart).
The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device.
### Block Editor
![](/static/mb/signal-strength-0.png)
### KindScript
```
export function signalStrength() : number
devices.signalStrength() : number
```
### Returns

View File

@ -14,7 +14,7 @@ The set of supported events will depend on the remote device and the BBC micro:b
![](/static/mb/tell-camera-to-0.png)
### KindScript
### JavaScript
```
export function tellCameraTo(event: string)

View File

@ -10,7 +10,7 @@ The functions in the antenna namespace allow the BBC micro:bit to communicate wi
![](/static/mb/tell-microphone-to-0.png)
### KindScript
### JavaScript
```
export function tellMicrophoneTo(event: string)
@ -37,13 +37,13 @@ export function tellMicrophoneTo(event: string)
To tell the connected device to start recording audio
```
antenna.tellMicrophoneTo("start capture")
devices.tellMicrophoneTo("start capture")
```
To tell the connected device to stop recording audio
```
antenna.tellMicrophoneTo("stop capture")
devices.tellMicrophoneTo("stop capture")
```
### Other show functions
@ -54,5 +54,5 @@ antenna.tellMicrophoneTo("stop capture")
### See also
[Antenna](/js/antenna)
[Devices](/reference/devices)

View File

@ -14,7 +14,7 @@ The set of supported events will depend on the remote device and the BBC micro:b
![](/static/mb/tell-remote-control-to-0.png)
### KindScript
### JavaScript
```
export function tellRemoteControlTo(event: string)

View File

@ -55,5 +55,5 @@ To learn more about how the BBC micro:bit queues up and schedules event handlers
### see also
[on button pressed](/reference/input/on-button-pressed), [on logo up](/functions/on-logo-up), [on logo down](/functions/on-logo-down), [on screen up](/functions/on-screen-up), [on screen down](/functions/on-screen-down), [on shake](/reference/input/on-gesture), [on pin pressed](/reference/input/on-pin-pressed)
[on button pressed](/reference/input/on-button-pressed), [on pin up](/reference/input/on-pin-pressed), [on shake](/reference/input/on-gesture)

View File

@ -1,20 +1,8 @@
# Change Score By
The game library
The game library supports simple single-player time-based games. The player will ** add points to score**.
## Block Editor
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible and the score will display on the screen.
![](/static/mb/change-score-by-0.png)
## KindScript
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
```
```blocks
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
@ -39,5 +27,5 @@ export function score() : number
### Lessons
[bop it](/lessons/bop-it) | [game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter)
[game of chance](/lessons/game-of-chance), [game counter](/lessons/game-counter)

View File

@ -1,16 +1,12 @@
# Change
The game library
### Change
Sprite will change the x position by this number
## Block Editor
### Block Editor
![](/static/mb/change-0.png)
## KindScript
### JavaScript
Sprite will change the x position by this number

View File

@ -4,7 +4,7 @@ The clear function for images.
Turn off all the pixels in an [Image](/reference/images/image).
### KindScript
### JavaScript
```
export function clear(img: micro_bit.Image)

View File

@ -55,5 +55,5 @@ export function startCountdown(ms: number)
### Lessons
[bop it](/lessons/bop-it) | [game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter)
[game of chance](/lessons/game-of-chance), [game counter](/lessons/game-counter)

View File

@ -4,7 +4,7 @@ The pixel function.
Get the state of a pixel in an [Image](/reference/images/image).
### KindScript
### JavaScript
```
export function pixel(_this: micro_bit.Image, x: number, y: number) : boolean

View File

@ -4,7 +4,7 @@ The plot frame function.
Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](/device/screen)
### KindScript
### JavaScript
```
export function plotFrame(_this: micro_bit.Image, index: number)

View File

@ -4,7 +4,7 @@ The plot image function.
Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](/device/screen)
### KindScript
### JavaScript
```
export function plotImage(_this: micro_bit.Image, xOffset: number)

View File

@ -8,7 +8,7 @@ Scrolls the frames within an [Image](/reference/images/image) on the [LED screen
![](/static/mb/scroll-image-0.png)
### KindScript
### JavaScript
```
export function scrollImage(_this: micro_bit.Image, xOffsetPerStep: number, interval: number)

View File

@ -4,7 +4,7 @@ The set pixel function. #set pixel.
Set the on/off state of pixel in an [Image](/reference/images/image).
### KindScript
### JavaScript
```
export function setPixel(_this: micro_bit.Image, x: number, y: number, value: boolean)

View File

@ -4,7 +4,7 @@ The show frame function.
Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](/device/screen)
### KindScript
### JavaScript
```
export function showFrame(img: micro_bit.Image, frame: number)

View File

@ -4,12 +4,6 @@ The show image function.
Show an [Image](/reference/images/image) on the [LED screen](/device/screen), followed by a 400ms pause.
### Block Editor
![](/static/mb/show-image-0.png)
### KindScript
```
export function showImage(_this: micro_bit.Image, xOffset: number)
```
@ -20,7 +14,7 @@ export function showImage(_this: micro_bit.Image, xOffset: number)
### Create image and show image
Use the [image editor](/reference/images/image) to create images using the [create image](/reference/image/create-image) function, and then use `show image` like this:
Use the [image editor](/reference/images/image) to create images using the [create image](/reference/images/create-image) function, and then use `show image` like this:
```
let img = images.createImage(`

View File

@ -4,10 +4,8 @@ The width function.
Get the width of an [Image](/reference/images/image) in columns.
### KindScript
```
export function width(_this: micro_bit.Image) : number
```sig
images.createImage().width();
```
### Parameters

View File

@ -45,5 +45,5 @@ basic.forever(() => {
### See also
[compass-heading](/input/compass-heading), [lightlevel](/input/lightlevel)
[compass-heading](/reference/input/compass-heading), [lightlevel](/reference/input/lightlevel)

View File

@ -37,5 +37,5 @@ basic.forever(() => {
### See also
[on button pressed](/input/on-button-pressed), [if](/reference/logic/if), [forever](/basic/forever)
[on button pressed](/reference/input/on-button-pressed), [if](/reference/logic/if), [forever](/reference/basic/forever)

View File

@ -26,5 +26,5 @@ basic.forever(() => {
### See also
[acceleration](/reference/input/acceleration), [compass-heading](/input/compass-heading)
[acceleration](/reference/input/acceleration), [compass-heading](/reference/input/compass-heading)

View File

@ -28,5 +28,5 @@ basic.forever(() => {
### See also
[compass heading](/input/compass-heading)
[compass heading](/reference/input/compass-heading)

View File

@ -1,6 +1,6 @@
# On Button Pressed
Register an [event handler](/reference/event-handler) that will execute whenever an input button (A, B, or A and B together) is pressed during program execution. When [running code](/js/simulator) with this function in a web browser, click an on-screen input button - labelled A or B.
Register an [event handler](/reference/event-handler) that will execute whenever an input button (A, B, or A and B together) is pressed during program execution. When [running code](/device/simulator) with this function in a web browser, click an on-screen input button - labelled A or B.
```sig
input.onButtonPressed(Button.A, () => {})

View File

@ -28,5 +28,5 @@ input.onPinPressed(TouchPin.P0, () => {
### See also
[BBC micro:bit pins](/device/pins), [pin is pressed](/input/pin-is-pressed), [analog read pin](/pins/analog-read-pin), [analog write pin](/pins/analog-write-pin), [digital read pin](/pins/digital-read-pin), [digital write pin](/pins/digital-write-pin)
[BBC micro:bit pins](/device/pins), [pin is pressed](/reference/input/pin-is-pressed), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin)

View File

@ -32,5 +32,5 @@ basic.forever(() => {
### See also
[BBC micro:bit pins](/device/pins), [on pin pressed](/input/on-pin-pressed), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin)
[BBC micro:bit pins](/device/pins), [on pin pressed](/reference/input/on-pin-pressed), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin)

View File

@ -2,8 +2,6 @@
Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](/device/screen). NOTE: `basic -> plot image` has been replaced by `basic -> show leds`.
### KindScript syntax
```sig
basic.plotLeds(`
. . . . .

View File

@ -24,5 +24,5 @@ for (let k = 0; k < 4; k++) {
### See also
[while](/reference/loops/while), [if](/blocks/if)
[while](/reference/loops/while), [if](/reference/logic/if)

View File

@ -39,5 +39,5 @@ The following example uses a while loop to make a diagonal line on the LED scree
### See also
[on button pressed](/reference/input/on-button-pressed), [for](/reference/loops/for), [if](/blocks/if), [forever](/reference/basic/forever)
[on button pressed](/reference/input/on-button-pressed), [for](/reference/loops/for), [if](/reference/logic/if), [forever](/reference/basic/forever)

View File

@ -2,17 +2,9 @@
The micro:bit pins.
## We listened to your feedback!
Following the feedback from teachers, the following improvements were made:
* compile without signing in
* compile offline
* save and load code using files
## How to work offline
If you have loaded the web app at some time in the past (by clicking on "my scripts" from the home page), then if you later open the same browser (whether you are online or offline) and type in the URL KINDSCRIPTWEBSITE, you will be able to access all the features of the web app. Note that it is important to end the URL with "/".
If you have loaded the web app at some time in the past (by clicking on "my scripts" from the home page), then if you later open the same browser (whether you are online or offline) and type in [https://codemicrobit.com/](https://codemicrobit.com/), you will be able to access all the features of the web app. Note that it is important to end the URL with "/".
## Save and load code using files
@ -24,7 +16,7 @@ The micro:bit automatically saves and synchronises scripts for signed-in users t
## The new in-browser compiler
The compilation from a script to ARM machine code is now done entirely in the browser (read the [in depth story](https://www.touchdevelop.com/docs/touch-develop-in-208-bits) about building the compiler). The new compiler is used by the Block Editor, Touch Develop and Code Kingdoms to create a .hex file solely within the confines of your web browser (no Internet connection is needed). The micro:bit compilation process (see page 10 in the [Quick Start Guide](/js/quick-start)) has been updated below to reflect the new compiler architecture, as shown below:
The compilation from a script to ARM machine code is now done entirely in the browser (read the [in depth story](https://www.touchdevelop.com/docs/touch-develop-in-208-bits) about building the compiler). The new compiler is used by the Block Editor, Touch Develop and Code Kingdoms to create a .hex file solely within the confines of your web browser (no Internet connection is needed). The micro:bit compilation process is shown below:
![](/static/mb/offline-2.png)

View File

@ -8,8 +8,8 @@ For example, the [plot](/reference/led/plot) function has two parameters:
### syntax
```
export function plot(x: number, y: number)
```sig
led.plot(0,0)
```
### parameters
@ -21,7 +21,7 @@ export function plot(x: number, y: number)
here's an example of code with an out of bounds parameter (the *x* and *y* parameters are outside the expected range of 0-4):
```
```blocks
led.plot(9, -21)
```
@ -33,11 +33,8 @@ Typically, when a parameter supplied to a function is out of bounds that functio
If you call the `point` function with an out of bounds parameter, the function returns `false`:
```
```blocks
let on = led.point(5, -5)
```
### see also
For more information on the out-of-bounds behavior of a function, see the documentation for that [function](/js/contents).

View File

@ -31,5 +31,5 @@ radio.onDataReceived(() => {
### See also
[receive number](/reference/radio/receive-number), [send number](/radio/send-number), [set group](/reference/radio/set-group)
[receive number](/reference/radio/receive-number), [send number](/reference/radio/send-number), [set group](/reference/radio/set-group)

View File

@ -30,5 +30,5 @@ radio.onDataReceived(() => {
### See also
[receive number](/input/receive-number), [on data received](/reference/radio/on-data-received)
[receive number](/reference/input/receive-number), [on data received](/reference/radio/on-data-received)

8
docs/reference/serial.md Normal file
View File

@ -0,0 +1,8 @@
# Serial
[Serial communication](/device/serial) between the BBC micro:bit and another computer.
```cards
serial.writeLine("");
serial.writeValue("x", 0);
```

View File

@ -0,0 +1,33 @@
# Write Line
Writes a string and a new line character (`\r\n`) to [serial](/device/serial).
```sig
serial.writeLine("");
```
### Example: streaming data
The following example constantly checks the [compass heading](/reference/input/compass-heading) and sends the direction to serial.
```blocks
basic.forever(() => {
let heading = input.compassHeading()
if (heading < 45) {
serial.writeLine("N");
} else if (heading < 135) {
serial.writeLine("E");
}
else if (heading < 225) {
serial.writeLine("S");
}
else {
serial.writeLine("W");
}
})
```
### See also
[serial](/device/serial), [write value](/reference/serial/write-value)

View File

@ -0,0 +1,36 @@
# Write Value
Writes name/value pair and a new line character (`\r\n`) to [serial](/device/serial).
```sig
serial.writeValue("x", 0);
```
### Example: streaming data
The sample below sends the temperature and light level every 10 seconds.
```blocks
basic.forever(() => {
serial.writeValue("temp", input.temperature())
serial.writeValue("light", input.lightLevel())
basic.pause(10000);
})
```
### Plot bar graph does serial!
If you use the `led.plotBarGraph` function, it automatically writes the value to the serial as well.
```blocks
basic.forever(() => {
led.plotBarGraph(input.lightLevel(), 255)
basic.pause(10000);
})
```
### See also
[serial](/device/serial), [write line](/reference/serial/write-line)

View File

@ -32,7 +32,7 @@ The next six blocks represent comparison operators that yield a Boolean value. M
42 >= 0;
```
Boolean values and operators are often used with an [if](/blocks/if) or [while](/reference/loops/while) statement to determine which code will execute next. For example:
Boolean values and operators are often used with an [if](/reference/logic/if) or [while](/reference/loops/while) statement to determine which code will execute next. For example:
### Functions that return a Boolean
@ -104,5 +104,5 @@ See the documentation on [Numbers](/reference/types/number) for more information
### See also
[if](/blocks/if), [while](/reference/loops/while), [number](/reference/types/number)
[if](/reference/logic/if), [while](/reference/loops/while), [number](/reference/types/number)

View File

@ -20,7 +20,7 @@ The following arithmetic operators work on numbers and return a [Number](/refere
* subtraction: `1 - 3 `
* multiplication: `3 * 2`
* integer division: `7 / 3`
* modulo is available through the [math library](/blocks/math)
* modulo is available through the [math library](/reference/math)
### Relational operators
@ -47,7 +47,7 @@ Some functions return a number, which you can store in a variable. For example t
### Math functions
The [math library](/blocks/math) includes math related functions. In the [Block Editor](/blocks/editor), click `math` on the Code Keyboard to see the math functions. For example, the `absolute` function returns the returns the absolute value of input parameter `x`:
The [math library](/reference/math) includes math related functions. In the [Block Editor](/blocks/editor), click `math` on the Code Keyboard to see the math functions. For example, the `absolute` function returns the returns the absolute value of input parameter `x`:
![](/static/mb/blocks/number-3.png)
@ -57,5 +57,5 @@ The [math library](/blocks/math) includes math related functions. In the [Block
### See also
[math library](/blocks/math), [var](/reference/variables/var), [Boolean](/reference/types/boolean), [show number](/reference/basic/show-number)
[math library](/reference/math), [var](/reference/variables/var), [Boolean](/reference/types/boolean), [show number](/reference/basic/show-number)

View File

@ -28,7 +28,7 @@ let num1 = 42
````
### Notes
* You can use the assignment operator with variables of each of the supported [types](/blocks/types).
* You can use the assignment operator with variables of each of the supported [types](/reference/types).
### Lessons
@ -36,5 +36,5 @@ let num1 = 42
### See also
[variable](/reference/variables/var), [types](/blocks/types)
[variable](/reference/variables/var), [types](/reference/types)

View File

@ -32,9 +32,9 @@ basic.showNumber(x);
### Notes
* You can use the assignment operator with variables of each of the supported [types](/blocks/types).
* You can use the assignment operator with variables of each of the supported [types](/reference/types).
### See also
[variable](/reference/variables/var), [types](/blocks/types)
[variable](/reference/variables/var), [types](/reference/types)

BIN
docs/static/mb/acc.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

BIN
docs/static/mb/acc2.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

BIN
docs/static/mb/chart1.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
docs/static/mb/chart_title.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 302 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 277 KiB

BIN
docs/static/mb/csv.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

BIN
docs/static/mb/data2.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
docs/static/mb/data3.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
docs/static/mb/data4.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
docs/static/mb/data7.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
docs/static/mb/lessons/data3.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@ -11,9 +11,13 @@
"dependencies": {
"microbit": "file:../microbit"
},
"microbit": {
"yotta": {
"config": {
"MICROBIT_BLE_ENABLED": "1"
"microbit-dal": {
"bluetooth": {
"enabled": 1
}
}
}
},
"installedVersion": "zakvul"

View File

@ -12,10 +12,14 @@
"dependencies": {
"microbit": "file:../microbit"
},
"microbit": {
"yotta": {
"config": {
"MICROBIT_BLE_ENABLED": "0"
"microbit-dal": {
"bluetooth": {
"enabled": 0
}
}
}
},
"installedVersion": "rlfgis"
}
}

View File

@ -13,7 +13,10 @@ namespace radio {
int radioEnable() {
int r = uBit.radio.enable();
if (r != MICROBIT_OK) return r;
if (r != MICROBIT_OK) {
uBit.panic(43);
return r;
}
if (!radioEnabled) {
uBit.radio.setGroup(pxt::programHash());
radioEnabled = true;

View File

@ -58,7 +58,7 @@ namespace basic {
int l = s.length();
if (l == 0) {
uBit.display.clear();
uBit.sleep(interval * 5);
fiber_sleep(interval * 5);
} else if (l > 1) {
uBit.display.scroll(s, interval);
} else {
@ -98,7 +98,7 @@ namespace basic {
void forever_stub(void *a) {
while (true) {
runAction0((Action)a);
uBit.sleep(20);
fiber_sleep(20);
}
}
@ -123,6 +123,6 @@ namespace basic {
//% async block="pause (ms) %pause"
//% blockId=device_pause icon="\uf110"
void pause(int ms) {
uBit.sleep(ms);
fiber_sleep(ms);
}
}

View File

@ -132,7 +132,7 @@ namespace control {
//% weight=30 async help=control/reset
//% blockId="control_reset" block="reset"
void reset() {
uBit.reset();
microbit_reset();
}
/**
@ -151,8 +151,24 @@ namespace control {
* Raises an event in the event bus.
*/
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source|with value %value=control_event_value"
//% blockExternalInputs=1 blockStatement=1
//% blockExternalInputs=1
void onEvent(int src, int value, Action handler) {
registerWithDal(src, value, handler);
}
/**
* Gets a friendly name for the device derived from the its serial number
*/
//% blockId="control_device_name" block="device name" weight=10
StringData* deviceName() {
return ManagedString(microbit_friendly_name()).leakData();
}
/**
* Derive a unique, consistent serial number of this device from internal data.
*/
//%
int deviceSerialNumber() {
return microbit_serial_number();
}
}

View File

@ -1,6 +1,7 @@
#include "ksbit.h"
#include <limits.h>
namespace String_ {
//%
StringData *charAt(StringData *s, int pos) {
@ -127,13 +128,13 @@ namespace Math_ {
//%
int random(int max) {
if (max == INT_MIN)
return -uBit.random(INT_MAX);
return -microbit_random(INT_MAX);
else if (max < 0)
return -uBit.random(-max);
return -microbit_random(-max);
else if (max == 0)
return 0;
else
return uBit.random(max);
return microbit_random(max);
}
//%
@ -298,6 +299,20 @@ namespace pxtrt {
//%
void panic(int code)
{
uBit.panic(code);
microbit_panic(code);
}
//
// Debugger
//
//%
uint32_t getNumGlobals() {
return numGlobals;
}
//%
void* getGlobalsPtr() {
return globals;
}
}

View File

@ -2,7 +2,9 @@
declare const enum DAL {
// built/yt/yotta_modules/microbit-dal/inc//bluetooth/ExternalEvents.h
MICROBIT_ID_BLE = 1000,
MICROBIT_ID_BLE_UART = 1001,
MICROBIT_ID_BLE_UART = 1200,
MICROBIT_BLE_EVT_CONNECTED = 1,
MICROBIT_BLE_EVT_DISCONNECTED = 2,
// built/yt/yotta_modules/microbit-dal/inc//bluetooth/MESEvents.h
MES_REMOTE_CONTROL_ID = 1001,
MES_REMOTE_CONTROL_EVT_PLAY = 1,
@ -294,6 +296,7 @@ declare const enum DAL {
// built/yt/yotta_modules/microbit-dal/inc//drivers/MicroBitDisplay.h
MICROBIT_DISPLAY_EVT_ANIMATION_COMPLETE = 1,
MICROBIT_DISPLAY_EVT_LIGHT_SENSE = 2,
MICROBIT_DISPLAY_DEFAULT_AUTOCLEAR = 1,
MICROBIT_DISPLAY_SPACING = 1,
MICROBIT_DISPLAY_GREYSCALE_BIT_DEPTH = 8,
MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS = -255,
@ -303,7 +306,8 @@ declare const enum DAL {
ANIMATION_MODE_PRINT_TEXT = 3,
ANIMATION_MODE_SCROLL_IMAGE = 4,
ANIMATION_MODE_ANIMATE_IMAGE = 5,
ANIMATION_MODE_PRINT_CHARACTER = 6,
ANIMATION_MODE_ANIMATE_IMAGE_WITH_CLEAR = 6,
ANIMATION_MODE_PRINT_CHARACTER = 7,
DISPLAY_MODE_BLACK_AND_WHITE = 0,
DISPLAY_MODE_GREYSCALE = 1,
DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE = 2,
@ -384,6 +388,7 @@ declare const enum DAL {
MICROBIT_THERMOMETER_PERIOD = 1000,
MICROBIT_THERMOMETER_EVT_UPDATE = 1,
MICROBIT_THERMOMETER_ADDED_TO_IDLE = 2,
// built/yt/yotta_modules/microbit-dal/inc//platform/yotta_cfg_mappings.h
// built/yt/yotta_modules/microbit-dal/inc//types/ManagedString.h
// built/yt/yotta_modules/microbit-dal/inc//types/ManagedType.h
// built/yt/yotta_modules/microbit-dal/inc//types/Matrix4.h

View File

@ -281,5 +281,7 @@ declare namespace serial {
Int32BE = 10,
// UInt32,
}
declare namespace storage {
}
// Auto-generated. Do not edit. Really.

View File

@ -247,7 +247,7 @@ namespace input {
//% help=input/running-time weight=50
//% blockId=device_get_running_time block="running time (ms)" icon="\uf017"
int runningTime() {
return uBit.systemTime();
return system_timer_current_time();
}
/**

View File

@ -4,18 +4,33 @@
//% color=3 weight=35
namespace led {
// what's the current high value
let barGraphHigh = 0;
// when was the current high value recorded
let barGraphHighLast = 0;
/**
* Displays a vertical bar graph based on the ``value`` and ``high`` value.
* Displays a vertical bar graph based on the `value` and `high` value.
* If `high` is 0, the chart gets adjusted automatically.
* @param value current value to plot
* @param high maximum value, eg: 1023, 255
* @param high maximum value. If 0, maximum value adjusted automatically, eg: 0
*/
//% 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
export function plotBarGraph(value: number, high: number): void {
export function plotBarGraph(value: number, high: number): void {
let now = input.runningTime();
serial.writeString(value.toString() + "\r\n");
value = Math.abs(value);
let v = Math.abs((value * 15) / high);
if (high != 0) barGraphHigh = high;
else if (value > barGraphHigh || now - barGraphHighLast > 5000) {
barGraphHigh = value;
barGraphHighLast = now;
}
barGraphHigh = Math.max(barGraphHigh, 16);
let v = (value * 15) / barGraphHigh;
let k = 0;
for(let y = 4; y >= 0; --y) {
for (let x = 0; x < 3; ++x) {

View File

@ -180,8 +180,9 @@ namespace pins {
}
if (ms > 0) {
uBit.sleep(ms);
fiber_sleep(ms);
pitchPin->setAnalogValue(0);
// TODO why do we use wait_ms() here? it's a busy wait I think
wait_ms(5);
}
}

View File

@ -26,13 +26,18 @@
"pins.ts",
"serial.cpp",
"serial.ts",
"buffer.cpp"
"buffer.cpp",
"storage.cpp"
],
"public": true,
"dependencies": {},
"microbit": {
"yotta": {
"config": {
"MESSAGE_BUS_LISTENER_DEFAULT_FLAGS": "MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY"
"microbit-dal": {
"bluetooth": {
"enabled": 0
}
}
}
}
}

View File

@ -15,7 +15,7 @@ namespace serial {
/**
* Sends a piece of text through Serial connection.
*/
//%
//% blockId=serial_writestring block="serial write %text"
void writeString(StringData *text) {
uBit.serial.send(ManagedString(text));
}

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