Compare commits
122 Commits
Author | SHA1 | Date | |
---|---|---|---|
548d215b48 | |||
43da58f214 | |||
f90d052538 | |||
a3b34518b0 | |||
5a33dc8a81 | |||
7349e28898 | |||
26b9fdf40e | |||
3cf82b9be2 | |||
546c44bafa | |||
d727d3fcde | |||
6b0cf961c6 | |||
18419d763d | |||
99fdb53fa0 | |||
879fdd687e | |||
6c1b879c34 | |||
019bbc79fc | |||
f857a88541 | |||
6531e7bfbb | |||
2147225afd | |||
841ea6d060 | |||
3dddb2eb30 | |||
651cf14556 | |||
7f6fb5559b | |||
ea724038dc | |||
19757d4245 | |||
07a7b4048a | |||
45742aa2ac | |||
db0c5d9f9f | |||
8285250a1b | |||
de0257c7e9 | |||
3580012065 | |||
cdb23fffb6 | |||
6937c51549 | |||
69e90523e2 | |||
f76235736a | |||
8431243b63 | |||
458b4553d2 | |||
0f6e8854d8 | |||
5565bb7d24 | |||
6c539fb04f | |||
b30a0ced87 | |||
ac942e198a | |||
cef1f57e30 | |||
980ad6ce91 | |||
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 |
7
docs/_locales/pl/docs.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Dokumentacja
|
||||
|
||||
Witamy na stronach dokumentacji!
|
||||
|
||||
* Przeglądnij [instrukcje obsługi](/reference)
|
||||
* Dowiedz się więcej o [urządzeniu](/device)
|
||||
* Wystartuj z [lekcjami](/lessons)
|
@ -11,9 +11,7 @@ This example displays a random number every time the crocodile clip holds `GND`
|
||||
|
||||
### Connecting Crocodile Clips
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
### Lessons
|
||||
|
||||
|
@ -5,6 +5,9 @@
|
||||
|
||||
### ~column
|
||||
|
||||
## O365 Integration
|
||||
* [Science Experiments: Chart](/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
|
||||
|
@ -1,15 +1,16 @@
|
||||
# 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)
|
||||
|
||||
* [activity](/lessons/charting/acceleration)
|
||||
* [challenge](/lessons/charting/challenge)
|
||||
* [quiz](/lessons/charting/quiz)
|
||||
* [answers](/lessons/charting/quiz-answers)
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
@ -18,9 +19,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()
|
||||
|
@ -1,53 +1,85 @@
|
||||
# charting activity
|
||||
# Activity
|
||||
|
||||
Measure the acceleration on the micro:bit in the "z" direction.
|
||||
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.
|
||||
|
||||
### ~
|
||||
|
||||
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!
|
||||
We want to chart the data collected by using a tool in Excel.
|
||||
|
||||
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));
|
||||
});
|
||||
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.
|
||||
|
||||
|
||||
```
|
||||
|
||||
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!
|
||||
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
|
||||
* Display acceleration with y or z using plot bar graph by changing acceleration from "x" to "y" or "z"
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/charting/acceleration-challenge)
|
||||
|
||||
### ~
|
||||
|
||||
|
94
docs/lessons/charting/challenge.md
Normal file
@ -0,0 +1,94 @@
|
||||
# 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
|
||||
* Display acceleration with y or z using plot bar graph by changing acceleration from "x" to "y" or "z"
|
||||
|
33
docs/lessons/charting/quiz-answers.md
Normal file
@ -0,0 +1,33 @@
|
||||
# charting quiz answers
|
||||
|
||||
Measure the acceleration on the micro:bit in the "x" direction.
|
||||
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [glowing pendulum activity](/lessons/charting/acceleration)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Why are you creating a 'forever' loop?
|
||||
|
||||
<br/>
|
||||
|
||||
We are creating a forever loop to constantly display the appropriate brightness on the LED display.
|
||||
|
||||
## 2. Write the line of code to measure the acceleration with respect to the "x" axis and display this value in a bar graph.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
led.plotBarGraph(input.acceleration(Dimension.X), 0)
|
||||
```
|
||||
|
||||
## 3. After vigarously moving the micro:bit from side to side along the "x" axis for a sufficient amount of time,insert the Excel graph for displaying a line chart used to display trends over time.
|
||||
|
||||
<br/>
|
||||
|
||||

|
||||
|
23
docs/lessons/charting/quiz.md
Normal file
@ -0,0 +1,23 @@
|
||||
# charting quiz
|
||||
|
||||
Measure the acceleration on the micro:bit in the "x" direction.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [glowing pendulum tutorial](/lessons/glowing-pendulum/activity)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Why are you creating a 'forever' loop?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the line of code to measure the acceleration with respect to the "y" axis and store this value in a local variable called 'acceleration'.
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. After vigarously moving the micro:bit from side to side along the "x" axis for a sufficient amount of time,insert the Excel graph for displaying a line chart used to display trends over time.
|
||||
|
||||
|
@ -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/>
|
||||
|
||||
|
34
docs/lessons/seismograph.md
Normal file
@ -0,0 +1,34 @@
|
||||
# Seismograph Lesson
|
||||
|
||||
Build a seismograph with household materials
|
||||
|
||||
## Topic
|
||||
|
||||
Acceleration & Analog Read Pin
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/seismograph/activity)
|
||||
* [challenge](/lessons/seismograph/challenges)
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to **show LEDs** to turn on a LED light pattern on the LED screen. We will be learning basic comments such as show LEDs and pause.
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
basic.forever(() => {
|
||||
});
|
||||
led.plotBarGraph(input.acceleration(Dimension.Strength) - 1023, 0);
|
||||
led.plotBarGraph(pins.analogReadPin(AnalogPin.P0), 0);
|
||||
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to repeat code forever in the background
|
||||
* learn how to display a vertical bar graph based on the value.
|
||||
* learn how to return the sum of the two numbers
|
||||
* learn how to get acceleration value in milli-gravitys
|
||||
* learn how to read the connector value as analog as a value comprised between 0 and 1023
|
150
docs/lessons/seismograph/activity.md
Normal file
@ -0,0 +1,150 @@
|
||||
# Seismograph Activity
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
In this project, you will build your own seismograph.
|
||||
|
||||
## What you'll need:
|
||||
|
||||
* micro:bit
|
||||
* USB cable
|
||||
* Scissors
|
||||
* Glue gun
|
||||
* String
|
||||
* Cup (Plastic or Paper)
|
||||
* Magnet
|
||||
|
||||
Welcome! This activity will teach how to use the micro:bit to chart the strength of the acceleration. Let's get started!
|
||||
|
||||
1. Setup Cup: Use scissors to cut a usable window on the cup, which will be a square sized hole at the lid side of the cup. Use scissors to create a small hole in the center of the base of the cup.
|
||||
|
||||
2. Fasten Magnet: Fasten end of the string to the magnet with glue
|
||||
|
||||
3. Secure String: Fasten string to base of the cup and hang the remaining string outside the base of the cup.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Seismograph built, let's code!
|
||||
|
||||
### ~
|
||||
|
||||
4. Go to Codemicrobit.com
|
||||
|
||||
Click or tap Create Code
|
||||
Click or tap Block Editor
|
||||
|
||||
### ~
|
||||
|
||||
5.
|
||||
|
||||
We will measure `acceleration (mg)` in terms of strength. Get the acceleration value (milli g-force), as measured in strength.
|
||||
|
||||
```blocks
|
||||
input.acceleration(Dimension.Strength);
|
||||
```
|
||||
|
||||
### ~
|
||||
|
||||
6.
|
||||
|
||||
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 based on strength.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plotBarGraph(input.acceleration(Dimension.Strength), 0);
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
### ~
|
||||
|
||||
7.
|
||||
|
||||
Finally, we subtract the gravity from acceleration strength.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plotBarGraph(input.acceleration(Dimension.Strength) - 1023, 0);
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
### ~
|
||||
|
||||
8.
|
||||
|
||||
Notice that making vibrating the object below the micro:bit changes the values and the line appears as a wave to display the value of the strength as measured in milli-gravities. By making the object below the micro:bit vibrate, you will observe changing values of the micro:bit. Also, the LEDs shown on the Bar Graph fluctates based on the movement of the micro:bit strength.
|
||||
|
||||
NOTE: The black color reflects the micro:bit device.
|
||||
|
||||

|
||||
|
||||
|
||||
### ~
|
||||
|
||||
9.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
### ~
|
||||
|
||||
10.
|
||||
|
||||
We want to chart 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.
|
||||
|
||||
|
||||
### ~
|
||||
|
||||
10.
|
||||
|
||||
|
||||
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.
|
||||
|
||||
### ~
|
||||
|
||||
11.
|
||||
|
||||
|
||||

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

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

|
||||
|
||||
* Connect a micro:bit to your computer using your USB cable; compile; and repeat this experiment by vibrating the micro:bit. Then chart the data on Excel.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/seismograph/challenge)
|
||||
|
||||
### ~
|
||||
|
94
docs/lessons/seismograph/challenge.md
Normal file
@ -0,0 +1,94 @@
|
||||
# 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
|
||||
* Display acceleration with y or z using plot bar graph by changing acceleration from "x" to "y" or "z"
|
||||
|
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 |
Before Width: | Height: | Size: 302 KiB After Width: | Height: | Size: 302 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/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 |
BIN
docs/static/mb/line_chart.png
vendored
Normal file
After Width: | Height: | Size: 98 KiB |
9
docs/thank-you.md
Normal file
@ -0,0 +1,9 @@
|
||||
# You completed the survey!
|
||||
|
||||
```sim
|
||||
basic.forever(() => { basic.showString("THANK YOU") })
|
||||
```
|
||||
|
||||
Thank you for participating in this survey.
|
||||
|
||||
Please [contact us](mailto:microbitpilots@microsoft.com) with any information you think we might find useful.
|
@ -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"
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,4 +155,20 @@ namespace control {
|
||||
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 blockGap=8
|
||||
StringData* deviceName() {
|
||||
return ManagedString(microbit_friendly_name()).leakData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Derive a unique, consistent serial number of this device from internal data.
|
||||
*/
|
||||
//% blockId="control_device_serial_number" block="device serial number" weight=9
|
||||
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
|
||||
|
@ -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) {
|
||||
|
51
libs/microbit/messages.ts
Normal file
@ -0,0 +1,51 @@
|
||||
namespace messages {
|
||||
var streamid: string;
|
||||
|
||||
export function setStreamId(id: string) {
|
||||
streamid = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new message that includes the board serial number and the stream id if any
|
||||
*/
|
||||
export function createMessage() : Message {
|
||||
let m = new Message();
|
||||
m.addNumber('board', control.deviceSerialNumber());
|
||||
if (streamid != null && streamid.length > 0)
|
||||
m.addString('stream', streamid);
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* A message containig custom data
|
||||
*/
|
||||
export class Message {
|
||||
private buffer:string = '';
|
||||
|
||||
/**
|
||||
* Adds a string field to the message
|
||||
*/
|
||||
//%
|
||||
public addString(name:string, value:string) {
|
||||
if (this.buffer.length > 0) this.buffer += ',';
|
||||
this.buffer += name + ':"' + value + '"';
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a number field to the message
|
||||
*/
|
||||
//%
|
||||
public addNumber(name:string, value: number) {
|
||||
if (this.buffer.length > 0) this.buffer += ',';
|
||||
this.buffer += name + ':' + value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the message to a JSON payload
|
||||
*/
|
||||
//%
|
||||
public toJSON() : string {
|
||||
return '{' + this.buffer + '}';
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -31,9 +31,13 @@
|
||||
],
|
||||
"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));
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ namespace serial {
|
||||
* Prints a line of text to the serial
|
||||
* @param value to send over serial
|
||||
*/
|
||||
//% help=/serial/write-line
|
||||
//% blockId=serial_writeline block="serial|write %text"
|
||||
//% help=serial/write-line
|
||||
//% blockId=serial_writeline block="serial|write line %text"
|
||||
export function writeLine(text: string): void {
|
||||
writeString(text);
|
||||
writeString("\r\n");
|
||||
@ -17,6 +17,7 @@ namespace serial {
|
||||
/**
|
||||
* Prints a numeric value to the serial
|
||||
*/
|
||||
//% blockId=serial_writenumber block="serial|write number %value"
|
||||
export function writeNumber(value: number): void {
|
||||
writeString(value.toString());
|
||||
}
|
||||
@ -27,8 +28,8 @@ namespace serial {
|
||||
* @param value to write
|
||||
*/
|
||||
//% weight=80
|
||||
//% help=/serial/write-value
|
||||
//% blockId=serial_writevalue block="serial|write %name|= %value"
|
||||
//% help=serial/write-value
|
||||
//% blockId=serial_writevalue block="serial|write line %name|= %value"
|
||||
export function writeValue(name: string, value: number): void {
|
||||
writeString(name);
|
||||
writeString(": ");
|
||||
|
14
libs/microbit/shims.d.ts
vendored
@ -342,6 +342,18 @@ declare namespace control {
|
||||
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source|with value %value=control_event_value"
|
||||
//% blockExternalInputs=1 shim=control::onEvent
|
||||
function onEvent(src: number, value: number, handler: () => void): void;
|
||||
|
||||
/**
|
||||
* Gets a friendly name for the device derived from the its serial number
|
||||
*/
|
||||
//% blockId="control_device_name" block="device name" weight=10 blockGap=8 shim=control::deviceName
|
||||
function deviceName(): string;
|
||||
|
||||
/**
|
||||
* Derive a unique, consistent serial number of this device from internal data.
|
||||
*/
|
||||
//% blockId="control_device_serial_number" block="device serial number" weight=9 shim=control::deviceSerialNumber
|
||||
function deviceSerialNumber(): number;
|
||||
}
|
||||
|
||||
|
||||
@ -528,7 +540,7 @@ declare namespace serial {
|
||||
/**
|
||||
* Sends a piece of text through Serial connection.
|
||||
*/
|
||||
//% shim=serial::writeString
|
||||
//% blockId=serial_writestring block="serial write %text" shim=serial::writeString
|
||||
function writeString(text: string): void;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-microbit",
|
||||
"version": "0.2.78",
|
||||
"version": "0.2.99",
|
||||
"description": "BBC micro:bit target for PXT",
|
||||
"keywords": [
|
||||
"JavaScript",
|
||||
@ -29,6 +29,6 @@
|
||||
"typescript": "^1.8.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-core": "0.2.82"
|
||||
"pxt-core": "0.2.111"
|
||||
}
|
||||
}
|
||||
|
@ -56,11 +56,17 @@
|
||||
"hasHex": true,
|
||||
"deployDrives": "^MICROBIT"
|
||||
},
|
||||
"runtime": {
|
||||
"mathBlocks": true,
|
||||
"loopsBlocks": true,
|
||||
"logicBlocks": true,
|
||||
"variablesBlocks": true
|
||||
},
|
||||
"simulator": {
|
||||
"autoRun": true
|
||||
},
|
||||
"compileService": {
|
||||
"gittag": "v0.1.7",
|
||||
"gittag": "v0.1.8",
|
||||
"serviceId": "ws"
|
||||
},
|
||||
"serial": {
|
||||
|
@ -226,6 +226,20 @@ namespace pxsim.control {
|
||||
export function reset() {
|
||||
U.userError("reset not implemented in simulator yet")
|
||||
}
|
||||
|
||||
export function deviceName() : string {
|
||||
let b = board();
|
||||
return b && b.id
|
||||
? b.id.slice(0, 4)
|
||||
: 'abcd';
|
||||
}
|
||||
|
||||
export function deviceSerialNumber(): number {
|
||||
let b = board();
|
||||
return parseInt(b && b.id
|
||||
? b.id.slice(1)
|
||||
: '42');
|
||||
}
|
||||
|
||||
export function onEvent(id: number, evid: number, handler: RefAction) {
|
||||
pxt.registerWithDal(id, evid, handler)
|
||||
|
@ -5,10 +5,20 @@
|
||||
<meta charset="utf-8">
|
||||
<title>microbit simulator</title>
|
||||
<style>
|
||||
body {
|
||||
background: transparent;
|
||||
overflow: hidden;
|
||||
}
|
||||
html {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
body {
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
margin: 0;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
overflow-scrolling: touch;
|
||||
}
|
||||
</style>
|
||||
<script src="/cdn/bluebird.min.js"></script>
|
||||
<script src="/cdn/pxtsim.js"></script>
|
||||
|
@ -219,7 +219,7 @@ namespace pxsim.micro_bit {
|
||||
rx:5, ry:5,
|
||||
fill:`url(#${gid})`
|
||||
});
|
||||
this.thermometerText = Svg.child(this.g, "text", { class:'sim-text', x:60, y:130}) as SVGTextElement;
|
||||
this.thermometerText = Svg.child(this.g, "text", { class:'sim-text', x:58, y:130}) as SVGTextElement;
|
||||
this.updateTheme();
|
||||
|
||||
let pt = this.element.createSVGPoint();
|
||||
|
@ -511,7 +511,7 @@ namespace pxsim {
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.id = "b" + Math.random();
|
||||
this.id = "b" +Math_.random(2147483647);
|
||||
this.animationQ = new AnimationQueue(runtime);
|
||||
this.bus = new EventBus(runtime);
|
||||
this.radio = new RadioBus(runtime);
|
||||
|