Compare commits

..

23 Commits

Author SHA1 Message Date
Peli de Halleux
e37ac1a1d7 0.2.91 2016-04-26 10:43:51 -07:00
Peli de Halleux
17eb36a8dc Bump pxt-core to 0.2.99 2016-04-26 10:43:49 -07:00
Peli de Halleux
10d44b97cc more serial infos 2016-04-26 10:29:05 -07:00
Peli de Halleux
67f2fdcfec 0.2.90 2016-04-25 12:44:04 -07:00
Peli de Halleux
d11c5a9028 Bump pxt-core to 0.2.98 2016-04-25 12:44:03 -07:00
Michael Elliot Braun
6150850729 glowing pend update 2016-04-25 11:32:20 -07:00
Michael Elliot Braun
76a18fa61b updated glowing pendulum 2016-04-25 11:31:06 -07:00
Peli de Halleux
2bd66ae4ef 0.2.89 2016-04-22 23:14:03 -07:00
Peli de Halleux
f6eefde27c Bump pxt-core to 0.2.96 2016-04-22 23:14:01 -07:00
Peli de Halleux
60c9e4a82f 0.2.88 2016-04-22 14:54:24 -07:00
Peli de Halleux
56713227c5 0.2.87 2016-04-22 14:48:01 -07:00
Peli de Halleux
fd6e110790 Bump pxt-core to 0.2.95 2016-04-22 14:47:59 -07:00
Peli de Halleux
2336521df1 0.2.86 2016-04-22 13:38:45 -07:00
Peli de Halleux
2ce72aeb28 Bump pxt-core to 0.2.93 2016-04-22 13:38:43 -07:00
Peli de Halleux
e746c13212 don't filter or throttle serial, let the user deal with it. 2016-04-22 13:12:43 -07:00
Peli de Halleux
9e073aee36 fixing doc links. fix for #49 2016-04-22 12:37:47 -07:00
Peli de Halleux
3906f06a2f 0.2.85 2016-04-22 00:15:11 -07:00
Peli de Halleux
d89747fa46 typo in default value 2016-04-22 00:14:57 -07:00
Peli de Halleux
c4e6618baa 0.2.84 2016-04-22 00:07:31 -07:00
Peli de Halleux
5232be58ce auto adjusting bar graph + debouncing sending data over serial 2016-04-21 23:44:22 -07:00
Peli de Halleux
5a75483811 updated target definition 2016-04-21 22:46:40 -07:00
Peli de Halleux
4b40585690 0.2.83 2016-04-21 14:26:36 -07:00
Peli de Halleux
dd65efaab6 Bump pxt-core to 0.2.92 2016-04-21 14:26:34 -07:00
11 changed files with 87 additions and 37 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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));
}

View File

@@ -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,7 +28,7 @@ namespace serial {
* @param value to write
*/
//% weight=80
//% help=/serial/write-value
//% help=serial/write-value
//% blockId=serial_writevalue block="serial|write %name|= %value"
export function writeValue(name: string, value: number): void {
writeString(name);

View File

@@ -528,7 +528,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;
}

View File

@@ -1,6 +1,6 @@
{
"name": "pxt-microbit",
"version": "0.2.82",
"version": "0.2.91",
"description": "BBC micro:bit target for PXT",
"keywords": [
"JavaScript",
@@ -29,6 +29,6 @@
"typescript": "^1.8.7"
},
"dependencies": {
"pxt-core": "0.2.89"
"pxt-core": "0.2.99"
}
}

View File

@@ -56,6 +56,9 @@
"hasHex": true,
"deployDrives": "^MICROBIT"
},
"runtime": {
"mathBlocks": true
},
"simulator": {
"autoRun": true
},

View File

@@ -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();