Compare commits
107 Commits
Author | SHA1 | Date | |
---|---|---|---|
6937c51549 | |||
69e90523e2 | |||
8431243b63 | |||
458b4553d2 | |||
0f6e8854d8 | |||
5565bb7d24 | |||
6c539fb04f | |||
b30a0ced87 | |||
ac942e198a | |||
cef1f57e30 | |||
53bfea5752 | |||
4917bb7e39 | |||
139823203e | |||
883f4d1a20 | |||
0bce69edd0 | |||
efccc921cb | |||
55859b1237 | |||
ec09d40366 | |||
512e40fae3 | |||
028dac25f6 | |||
e0d4763974 | |||
3b3e402ffa | |||
e37ac1a1d7 | |||
17eb36a8dc | |||
10d44b97cc | |||
505c750dd0 | |||
d0e900606a | |||
dcbb076266 | |||
22c852f2d9 | |||
76770bc0e1 | |||
572080bc6d | |||
0b8142ae73 | |||
09a06d9fa9 | |||
80e8c6684d | |||
4cccb36f3d | |||
a427a1e720 | |||
be77c5296b | |||
a0c1b2c580 | |||
fc905c5f8f | |||
f1bd84733b | |||
d3080d2e66 | |||
090e530ff0 | |||
094e9d25cd | |||
0bcb9c16fa | |||
269bdb82a6 | |||
cba7e02bcd | |||
8ef834b73b | |||
ec54622f52 | |||
5d90b70425 | |||
8cef13e517 | |||
82986c091b | |||
67f2fdcfec | |||
d11c5a9028 | |||
b7cb7e477e | |||
0d1059aedf | |||
b92fc783fa | |||
6d73e5e129 | |||
6150850729 | |||
76a18fa61b | |||
2bd66ae4ef | |||
f6eefde27c | |||
60c9e4a82f | |||
56713227c5 | |||
fd6e110790 | |||
2336521df1 | |||
2ce72aeb28 | |||
e746c13212 | |||
9e073aee36 | |||
3906f06a2f | |||
d89747fa46 | |||
c4e6618baa | |||
5232be58ce | |||
5a75483811 | |||
4b40585690 | |||
dd65efaab6 | |||
890c2566af | |||
cd71fc5d13 | |||
f626dd4bbb | |||
956992e9ab | |||
91ddcef6ce | |||
49fa42473f | |||
564de8863a | |||
1dd70100d6 | |||
a38ff18eaf | |||
d46ef1efca | |||
c54cd21efa | |||
94f18340ec | |||
13bdcf762d | |||
6455da6adb | |||
4e88ba4ef2 | |||
0c7d49256d | |||
c2883d00ee | |||
7da483f258 | |||
6cbc6a53b2 | |||
5e23bc96ca | |||
4169663a8b | |||
4795c58e97 | |||
8fb96934ca | |||
cd91504c1f | |||
91e8196621 | |||
26841de6cf | |||
24f2a45310 | |||
67c5f0612a | |||
d7c3f1b50a | |||
2fb6025848 | |||
8da3c5eb84 | |||
4ee1799271 |
1
.gitignore
vendored
@ -6,6 +6,7 @@ temp
|
||||
projects
|
||||
win10/app/bin
|
||||
win10/app/bld
|
||||
win10/*.opendb
|
||||
|
||||
*.user
|
||||
*.sw?
|
||||
|
@ -69,7 +69,11 @@ When your micro:bit isn’t 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
|
||||
|
@ -11,9 +11,7 @@ This example displays a random number every time the crocodile clip holds `GND`
|
||||
|
||||
### Connecting Crocodile Clips
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
### Lessons
|
||||
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
The micro:bit LED screen
|
||||
|
||||

|
||||
```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
@ -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.
|
||||
|
||||

|
||||
|
||||
* (optional): in the "Terminal" section, check "implicit cr in every lf"
|
||||
|
||||

|
||||
|
||||
### 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`.
|
@ -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()
|
||||
```
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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()
|
||||
|
99
docs/lessons/charting/acceleration-challenge.md
Normal 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.
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
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.
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
Finally, you must open the Excel CSV file by clicking on the data.xls file that was downloaded to Downloads Folder.
|
||||
|
||||

|
||||
|
||||
Use the Recommended Charts command on the Insert tab to quickly create a chart that’s just right for your data.
|
||||
|
||||
* Select the data that you want to include in your chart.
|
||||
|
||||
* Click Insert > Recommended Charts.
|
||||
|
||||

|
||||
|
||||
* 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 don’t see a chart type that you want, click the All Charts tab to see all of the available chart types.
|
||||
|
||||

|
||||
|
||||
* 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
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
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)
|
||||
|
||||
### ~
|
85
docs/lessons/charting/acceleration.md
Normal 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
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
|
||||
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
|
||||
|
||||

|
||||
|
||||
Use the Recommended Charts command on the Insert tab to quickly create a chart that’s just right for your data.
|
||||
|
||||
* Select the data that you want to include in your chart.
|
||||
|
||||
|
||||
* Click Insert > Recommended Charts.
|
||||
|
||||

|
||||
|
||||
* 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 don’t see a chart type that you want, click the All Charts tab to see all of the available chart types.
|
||||
|
||||

|
||||
|
||||
* 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
|
||||
|
||||

|
||||
|
||||
* 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)
|
||||
|
||||
### ~
|
||||
|
@ -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!
|
118
docs/lessons/charting/light-level.md
Normal 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
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
|
||||
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.
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
|
||||
* 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.
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
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.
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
Finally, you must open the Excel CSV file by clicking on the data.xls file that was downloaded to Downloads Folder.
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
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
|
@ -1,41 +0,0 @@
|
||||
# crocodile clip activity
|
||||
|
||||
Use the crocodile clips
|
||||
|
||||
# micro:bit crocodile clip
|
||||
|
||||

|
||||
|
||||
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
|
||||
|
||||

|
||||
|
||||
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
|
||||
|
||||
### Step 2
|
||||
|
||||

|
||||
|
||||
Using the 1st crocodile clip, connect the unattached end of the crocodile clip onto the 0 pin on the micro:bit.
|
||||
|
||||
### Step 3
|
||||
|
||||

|
||||
|
||||
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.
|
||||
|
@ -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.
|
||||
|
||||

|
||||
|
||||
```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.
|
||||
|
||||

|
||||
|
||||
```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.
|
||||
|
||||

|
||||
```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.
|
||||
|
||||

|
||||
```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!
|
||||
|
||||

|
||||
```blocks
|
||||
|
||||
basic.forever(() => {
|
||||
let acceleration = input.acceleration(Dimension.Y);
|
||||
acceleration = Math.abs(acceleration);
|
||||
acceleration = acceleration / 4;
|
||||
led.setBrightness(acceleration)
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
});
|
||||
|
||||
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
|
@ -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:
|
||||
|
||||

|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let acceleration = input.acceleration(Dimension.Y);
|
||||
acceleration = Math.abs(acceleration);
|
||||
acceleration = acceleration / 4;
|
||||
led.setBrightness(acceleration)
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
});
|
||||
|
||||
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
|
@ -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)
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
led.plotAll()
|
||||
```
|
||||
|
||||
|
@ -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)
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
### ~
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
||||

|
||||
|
||||
### 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)
|
||||
|
@ -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
|
||||
|
||||

|
||||
|
||||
### KindScript
|
||||
|
||||
```
|
||||
export function onSignalStrengthChanged(body:td.Action)
|
||||
```sig
|
||||
devices.onSignalStrengthChanged(() => {})
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
@ -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
|
||||
|
||||

|
||||
|
||||
### KindScript
|
||||
|
||||
```
|
||||
```sig
|
||||
export function raiseAlertTo(event: string)
|
||||
```
|
||||
|
||||
|
@ -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
|
||||
|
||||

|
||||
|
||||
### KindScript
|
||||
|
||||
```
|
||||
export function receiveNumber() : number
|
||||
```sig
|
||||
radio.receiveNumber();
|
||||
```
|
||||
|
||||
### Returns
|
||||
|
@ -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
|
||||
|
||||

|
||||
|
||||
### KindScript
|
||||
|
||||
```
|
||||
export function signalStrength() : number
|
||||
devices.signalStrength() : number
|
||||
```
|
||||
|
||||
### Returns
|
||||
|
@ -14,7 +14,7 @@ The set of supported events will depend on the remote device and the BBC micro:b
|
||||
|
||||

|
||||
|
||||
### KindScript
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
export function tellCameraTo(event: string)
|
||||
|
@ -10,7 +10,7 @@ The functions in the antenna namespace allow the BBC micro:bit to communicate wi
|
||||
|
||||

|
||||
|
||||
### 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)
|
||||
|
||||
|
@ -14,7 +14,7 @@ The set of supported events will depend on the remote device and the BBC micro:b
|
||||
|
||||

|
||||
|
||||
### KindScript
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
export function tellRemoteControlTo(event: string)
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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.
|
||||
|
||||

|
||||
|
||||
## 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)
|
||||
|
||||
|
@ -1,16 +1,12 @@
|
||||
# Change
|
||||
|
||||
The game library
|
||||
|
||||
### Change
|
||||
|
||||
Sprite will change the x position by this number
|
||||
|
||||
## Block Editor
|
||||
### Block Editor
|
||||
|
||||

|
||||
|
||||
## KindScript
|
||||
### JavaScript
|
||||
|
||||
Sprite will change the x position by this number
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -8,7 +8,7 @@ Scrolls the frames within an [Image](/reference/images/image) on the [LED screen
|
||||
|
||||

|
||||
|
||||
### KindScript
|
||||
### JavaScript
|
||||
|
||||
```
|
||||
export function scrollImage(_this: micro_bit.Image, xOffsetPerStep: number, interval: number)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||

|
||||
|
||||
### 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(`
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -28,5 +28,5 @@ basic.forever(() => {
|
||||
|
||||
### See also
|
||||
|
||||
[compass heading](/input/compass-heading)
|
||||
[compass heading](/reference/input/compass-heading)
|
||||
|
||||
|
@ -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, () => {})
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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(`
|
||||
. . . . .
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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:
|
||||
|
||||

|
||||
|
||||
|
@ -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).
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
@ -0,0 +1,8 @@
|
||||
# Serial
|
||||
|
||||
[Serial communication](/device/serial) between the BBC micro:bit and another computer.
|
||||
|
||||
```cards
|
||||
serial.writeLine("");
|
||||
serial.writeValue("x", 0);
|
||||
```
|
33
docs/reference/serial/write-line.md
Normal 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)
|
||||
|
36
docs/reference/serial/write-value.md
Normal 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)
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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`:
|
||||
|
||||

|
||||
|
||||
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
After Width: | Height: | Size: 52 KiB |
BIN
docs/static/mb/acc2.png
vendored
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
docs/static/mb/chart1.png
vendored
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
docs/static/mb/chart_title.png
vendored
Normal file
After Width: | Height: | Size: 43 KiB |
BIN
docs/static/mb/crocodile-clips-1.jpg
vendored
Before Width: | Height: | Size: 302 KiB |
BIN
docs/static/mb/crocodile-clips-2.jpg
vendored
Before Width: | Height: | Size: 277 KiB |
BIN
docs/static/mb/csv.png
vendored
Normal file
After Width: | Height: | Size: 7.2 KiB |
BIN
docs/static/mb/data-1.jpg
vendored
Before Width: | Height: | Size: 37 KiB |
BIN
docs/static/mb/data-2.jpg
vendored
Before Width: | Height: | Size: 112 KiB |
BIN
docs/static/mb/data-3.jpg
vendored
Before Width: | Height: | Size: 85 KiB |
BIN
docs/static/mb/data2.png
vendored
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
docs/static/mb/data3.png
vendored
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
docs/static/mb/data4.png
vendored
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
docs/static/mb/data7.png
vendored
Normal file
After Width: | Height: | Size: 59 KiB |
BIN
docs/static/mb/elements_styles_filters.png
vendored
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
docs/static/mb/lessons/data3.png
vendored
Normal file
After Width: | Height: | Size: 4.1 KiB |
@ -11,9 +11,13 @@
|
||||
"dependencies": {
|
||||
"microbit": "file:../microbit"
|
||||
},
|
||||
"microbit": {
|
||||
"yotta": {
|
||||
"config": {
|
||||
"MICROBIT_BLE_ENABLED": "1"
|
||||
"microbit-dal": {
|
||||
"bluetooth": {
|
||||
"enabled": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"installedVersion": "zakvul"
|
||||
|
@ -12,10 +12,14 @@
|
||||
"dependencies": {
|
||||
"microbit": "file:../microbit"
|
||||
},
|
||||
"microbit": {
|
||||
"yotta": {
|
||||
"config": {
|
||||
"MICROBIT_BLE_ENABLED": "0"
|
||||
"microbit-dal": {
|
||||
"bluetooth": {
|
||||
"enabled": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"installedVersion": "rlfgis"
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
9
libs/microbit/dal.d.ts
vendored
@ -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
|
||||
|
2
libs/microbit/enums.d.ts
vendored
@ -281,5 +281,7 @@ declare namespace serial {
|
||||
Int32BE = 10,
|
||||
// UInt32,
|
||||
}
|
||||
declare namespace storage {
|
||||
}
|
||||
|
||||
// Auto-generated. Do not edit. Really.
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|