Map and clean deprecated functions (#175)
* add image and deprecated arrow functions * update locales * map basic.showArrow * map arrow blocks * map & remove arrow images * remove arrow blocks * update locales * remove & patch: rgbw -> rgb button/pin pressed -> button/pin event loudness -> soundLevel * update ts mappings for arrows * add wip ts patch rules * update .blocks files * use Click instead of Down as default in Documentation and tests * patch test.blocks * fix lowercase name tag * update test.blocks * update blocks test files * update blocks test files * format block files * pass blocks file tests * fix ts mapping * fix color.defl value closes https://github.com/microsoft/pxt-calliope/issues/136 * fix ts mappings - add optional spacing at the end of rgbw() - map up to v4.0.19 * add suggested changes * replace innerText by textContent Co-authored-by: JW <gitkraken@juriwolf.de> Co-authored-by: Juri <info@juriwolf.de>
This commit is contained in:
+4
-4
@@ -26,12 +26,12 @@ The Calliope mini is packaged with sensors, radio and other goodies. Learn about
|
||||
You can program the Calliope mini using [Blocks](/blocks) or [JavaScript](/javascript) in your web browser via the [Calliope mini APIs](/reference):
|
||||
|
||||
```block
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
basic.showString("Hi!");
|
||||
})
|
||||
```
|
||||
```typescript
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
basic.showString("Hi!");
|
||||
})
|
||||
```
|
||||
@@ -54,7 +54,7 @@ The simulator has support for the LED screen, buttons, as well as compass, accel
|
||||
basic.forever(() => {
|
||||
basic.showString("Hi!");
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
led.stopAnimation();
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
@@ -63,7 +63,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
# . . . #
|
||||
. # # # .`);
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Down, () => {
|
||||
led.stopAnimation();
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
|
||||
@@ -17,7 +17,7 @@ if (led.point(1,1) && led.point(2,2)) {
|
||||
When you compare two Numbers, you get a Boolean value, such as the comparison `x < 5` in the code below:
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
let x = randint(0, 5)
|
||||
if(x < 5) {
|
||||
basic.showString("low");
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
If the [light level](/reference/input/light-level) is `< 100`, this code sets the brightness to `255` when the button A is pressed:
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
if(input.lightLevel()<100){
|
||||
led.setBrightness(255);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
This program will show the numbers 0, 1, 2, 3, and 4 one after another on the LED screen.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
for(let i = 0; i < 5; ++i) {
|
||||
basic.showNumber(i)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
The following example uses a while loop to make a diagonal line on the LED screen (points `0, 0`, `1, 1`, `2, 2`, `3, 3`, `4, 4`).
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
let index = 4;
|
||||
while(index >= 0) {
|
||||
led.plot(index, index);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
In this example, ``on start`` sets a dimmer brightness on the screen and the button handler shows a string.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
basic.showString("Hello!")
|
||||
})
|
||||
led.setBrightness(50)
|
||||
|
||||
@@ -59,7 +59,7 @@ A counter is a great example:
|
||||
|
||||
```blocks
|
||||
let counter = 0;
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
counter = counter + 1;
|
||||
basic.showNumber(counter);
|
||||
});
|
||||
|
||||
@@ -38,7 +38,7 @@ Each time the crocodile clip is firmly connected and disconnected from pin `P0`,
|
||||
the @boardname@ will return a random Number between 0 and the parameter limit.
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
input.onPinTouchEvent(TouchPin.P0, ButtonEvent.Down, () => {
|
||||
basic.showNumber(randint(0, 10))
|
||||
})
|
||||
```
|
||||
|
||||
@@ -63,7 +63,7 @@ for (let i = 0; i < values.length; i++) {
|
||||
The ``||led:plot bar graph||`` also sends the number value it's plotting to the console. You can see the output in the Data Viewer. It charts the values and they appear as individual numbers in console.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
for (let i = 0; i < 25; i++) {
|
||||
if (i % 2 > 0) {
|
||||
led.plotBarGraph(0, 0)
|
||||
|
||||
@@ -51,7 +51,7 @@ The first job of the scheduler is to allow multiple *subprograms* to be queued u
|
||||
```typescript
|
||||
let count = 0
|
||||
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
count++;
|
||||
})
|
||||
|
||||
@@ -74,7 +74,7 @@ The second statement informs the scheduler that on each and every event of the *
|
||||
// statement 1
|
||||
let count = 0
|
||||
// statement 2
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
count++;
|
||||
})
|
||||
```
|
||||
@@ -85,7 +85,7 @@ The third statement queues a `forever` loop for later execution by the scheduler
|
||||
// statement 1
|
||||
let count = 0
|
||||
// statement 2
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
count++;
|
||||
})
|
||||
// statement 3
|
||||
@@ -157,7 +157,7 @@ As a result, you can easily add a new capability to the micro:bit by just adding
|
||||
```typescript
|
||||
let count = 0
|
||||
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
count = count + 1
|
||||
})
|
||||
|
||||
@@ -165,7 +165,7 @@ basic.forever(() => {
|
||||
basic.showNumber(count)
|
||||
})
|
||||
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Down, () => {
|
||||
count = 0
|
||||
})
|
||||
```
|
||||
|
||||
@@ -6,7 +6,7 @@ The code below shows a simple script that sends a line when the BBC micro:bit st
|
||||
|
||||
```blocks
|
||||
serial.writeLine("started...")
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
serial.writeLine("A pressed")
|
||||
})
|
||||
```
|
||||
|
||||
@@ -4,19 +4,19 @@ The JavaScript simulator allows you to test and execute most BBC micro:bit progr
|
||||
It allows you to emulate sensor data or user interactions.
|
||||
|
||||
```sim
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
basic.showString("A");
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
basic.showString("B");
|
||||
});
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
input.onPinTouchEvent(TouchPin.P0, ButtonEvent.Click, () => {
|
||||
basic.showString("0");
|
||||
});
|
||||
input.onPinPressed(TouchPin.P1, () => {
|
||||
input.onPinTouchEvent(TouchPin.P1, ButtonEvent.Click, () => {
|
||||
basic.showString("1");
|
||||
});
|
||||
input.onPinPressed(TouchPin.P2, () => {
|
||||
input.onPinTouchEvent(TouchPin.P2, ButtonEvent.Click, () => {
|
||||
basic.showString("2");
|
||||
});
|
||||
input.temperature()
|
||||
|
||||
@@ -22,13 +22,13 @@ Here's a program that simulates cell life in the LED matrix. Use button ``A`` fo
|
||||
let lifeChart: Image = null
|
||||
|
||||
//Use button A for the next iteration of game of life
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
gameOfLife();
|
||||
show();
|
||||
})
|
||||
|
||||
//Use button B for reseting to random initial seed state
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
reset();
|
||||
show();
|
||||
})
|
||||
|
||||
@@ -11,7 +11,7 @@ Let's create a coin flipping program to simulate a real coin toss. We'll use ico
|
||||
Get an ``||input:on button A pressed||`` block from the ``||input:Input||`` drawer in the toolbox. We'll put our coin flipping code in here.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
})
|
||||
```
|
||||
|
||||
@@ -22,7 +22,7 @@ Grab an ``||logic:if else||`` block and set it inside ``||input:on button A pres
|
||||
The ``||Math:pick random true or false||`` returns a random ``true`` or ``false`` value which we use to determine a ``heads`` or ``tails`` result for a coin toss.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
if (Math.randomBoolean()) {
|
||||
} else {
|
||||
}
|
||||
@@ -34,7 +34,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
Now, put a ``||basic:show icon||`` block inside both the ``||logic:if||`` and the ``||logic:else||``. Pick images to mean ``heads`` and ``tails``.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
if (Math.randomBoolean()) {
|
||||
basic.showIcon(IconNames.Skull)
|
||||
} else {
|
||||
@@ -52,7 +52,7 @@ Press button **A** in the simulator to try the coin toss code.
|
||||
You can animate the coin toss to add the feeling of suspense. Place different ``||basic:show icon||`` blocks before the ``||logic:if||`` to show that the coin is flipping.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
basic.showIcon(IconNames.Diamond)
|
||||
basic.showIcon(IconNames.SmallDiamond)
|
||||
basic.showIcon(IconNames.Diamond)
|
||||
|
||||
@@ -11,7 +11,7 @@ Make a love meter, how sweet! The @boardname@ is feeling the love, then sometime
|
||||
Let's build a **LOVE METER** machine. Place an ``||input:on pin pressed||`` block to run code when pin **0** is pressed. Use ``P0`` from the list of pin inputs.
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
input.onPinTouchEvent(TouchPin.P0, ButtonEvent.Down, () => {
|
||||
});
|
||||
```
|
||||
|
||||
@@ -20,7 +20,7 @@ input.onPinPressed(TouchPin.P0, () => {
|
||||
Using ``||basic:show number||`` and ``||Math:pick random||`` blocks, show a random number from `0` to `100` when pin **0** is pressed.
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
input.onPinTouchEvent(TouchPin.P0, ButtonEvent.Down, () => {
|
||||
basic.showNumber(randint(0, 100));
|
||||
});
|
||||
```
|
||||
@@ -34,7 +34,7 @@ Show ``"LOVE METER"`` on the screen when the @boardname@ starts.
|
||||
|
||||
```blocks
|
||||
basic.showString("LOVE METER");
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
input.onPinTouchEvent(TouchPin.P0, ButtonEvent.Down, () => {
|
||||
basic.showNumber(randint(0, 100));
|
||||
});
|
||||
```
|
||||
|
||||
@@ -12,7 +12,7 @@ Use ``||input:on button pressed||`` to send a text message over radio with ``||r
|
||||
Every @boardname@ nearby will receive this message.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
radio.sendString("Yo");
|
||||
});
|
||||
```
|
||||
@@ -41,7 +41,7 @@ radio.onReceivedString(function (receivedString) {
|
||||
Press button **A** on the simulator, you will notice that a second @boardname@ appears (if your screen is too small, the simulator might decide not to show it). Try pressing **A** again and notice that the "Yo" message gets displayed on the other @boardname@.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
radio.sendString("Yo");
|
||||
});
|
||||
radio.onReceivedString(function (receivedString) {
|
||||
|
||||
@@ -13,7 +13,7 @@ First, let's get your name to display on the screen.
|
||||
From the ``||input:Input||`` Toolbox drawer, drag an ``||input:on button A pressed||`` block onto the Workspace.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, function () {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, function () {
|
||||
|
||||
})
|
||||
```
|
||||
@@ -23,7 +23,7 @@ input.onButtonPressed(Button.A, function () {
|
||||
From the ``||basic:Basic||`` Toolbox drawer drag a ``||basic:show string||`` block into the ``||input:on button A pressed||`` block.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, function () {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, function () {
|
||||
basic.showString("Hello!")
|
||||
})
|
||||
```
|
||||
@@ -33,7 +33,7 @@ input.onButtonPressed(Button.A, function () {
|
||||
In the ``||basic:show string||`` block, type your name.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, function () {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, function () {
|
||||
basic.showString("My Name")
|
||||
})
|
||||
```
|
||||
@@ -43,7 +43,7 @@ input.onButtonPressed(Button.A, function () {
|
||||
Go to the simulator and test your name badge by pressing button **A**.
|
||||
|
||||
```sim
|
||||
input.onButtonPressed(Button.A, function () {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, function () {
|
||||
basic.showString("My Name")
|
||||
})
|
||||
```
|
||||
|
||||
@@ -123,7 +123,7 @@ basic.forever(function () {
|
||||
**MakeCode blocks for the Robot Unicorn controller**
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.AB, function () {
|
||||
input.onButtonEvent(Button.AB, ButtonEvent.Down, function () {
|
||||
radio.sendNumber(4)
|
||||
basic.showLeds(`
|
||||
# . . . #
|
||||
|
||||
@@ -83,7 +83,7 @@ Now that we are detecting pulses, we can use a variable to count them too. In th
|
||||
|
||||
```blocks
|
||||
let pulseCount = 0
|
||||
input.onButtonPressed(Button.A, function () {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, function () {
|
||||
basic.showNumber(pulseCount)
|
||||
pulseCount = 0
|
||||
})
|
||||
|
||||
@@ -12,7 +12,7 @@ Code the buttons on the @boardname@ to show that it's happy or sad.
|
||||
Place a ``||input:on button pressed||`` block to run code when button **A** is pressed.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
});
|
||||
```
|
||||
|
||||
@@ -21,7 +21,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
Place a ``||basic:show leds||`` block inside ``||input:on button pressed||`` to display a smiley on the screen. Press the **A** button in the simulator to see the smiley.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
basic.showLeds(`
|
||||
# # . # #
|
||||
# # . # #
|
||||
@@ -37,7 +37,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
Add ``||input:on button pressed||`` and ``||basic:show leds||`` blocks to display a frowny when button **B** is pressed.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
basic.showLeds(`
|
||||
# # . # #
|
||||
# # . # #
|
||||
@@ -53,7 +53,7 @@ input.onButtonPressed(Button.B, () => {
|
||||
Add a secret mode that happens when **A** and **B** are pressed together. For this case, add multiple ``||basic:show leds||`` blocks to create an animation.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.AB, () => {
|
||||
input.onButtonEvent(Button.AB, ButtonEvent.Click, () => {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
# . # . .
|
||||
|
||||
@@ -59,7 +59,7 @@ Use a ``||input:on button pressed||`` block to handle the **A** button. Put in a
|
||||
|
||||
```blocks
|
||||
let sprite = game.createSprite(2, 2)
|
||||
input.onButtonPressed(Button.A, function () {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, function () {
|
||||
if (sprite.get(LedSpriteProperty.X) == 2) {
|
||||
} else {
|
||||
}
|
||||
@@ -77,7 +77,7 @@ Finally, pull out an ``||game:add score||`` and a ``||game:game over||`` block t
|
||||
|
||||
```blocks
|
||||
let sprite = game.createSprite(2, 2)
|
||||
input.onButtonPressed(Button.A, function () {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, function () {
|
||||
if (sprite.get(LedSpriteProperty.X) == 2) {
|
||||
game.addScore(1)
|
||||
} else {
|
||||
|
||||
@@ -18,7 +18,7 @@ basic.forever(() => {
|
||||
|
||||
});
|
||||
basic.pause(100);
|
||||
basic.showArrow(ArrowNames.North);
|
||||
basic.showIcon(IconNames.ArrowNorth);
|
||||
```
|
||||
|
||||
## See also
|
||||
@@ -27,4 +27,4 @@ basic.showArrow(ArrowNames.North);
|
||||
[showIcon](/reference/basic/show-icon),
|
||||
[showLeds](/reference/basic/show-leds), [showString](/reference/basic/show-string),
|
||||
[clearScreen](/reference/basic/clear-screen), [forever](/reference/basic/forever), [pause](/reference/basic/pause),
|
||||
[showArrow](/reference/basic/show-arrow), [showAnimation](/reference/basic/show-animation)
|
||||
[showAnimation](/reference/basic/show-animation)
|
||||
|
||||
@@ -43,7 +43,7 @@ let num = 0
|
||||
basic.forever(() => {
|
||||
basic.showNumber(num)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
num = num + 1
|
||||
})
|
||||
```
|
||||
@@ -59,7 +59,7 @@ Try this on your @boardname@:
|
||||
basic.forever(() => {
|
||||
basic.showNumber(6789)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
basic.showNumber(2)
|
||||
})
|
||||
```
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
# Show Arrow
|
||||
|
||||
Shows the selected arrow on the LED screen
|
||||
|
||||
```sig
|
||||
basic.showArrow(ArrowNames.North)
|
||||
```
|
||||
|
||||
|
||||
## Parameters
|
||||
|
||||
* ``direction``, the identifier of the arrow to display
|
||||
* ``interval`` (optional), the time to display in milliseconds. default is 400.
|
||||
|
||||
## Example
|
||||
|
||||
This program shows all eight arrows.
|
||||
|
||||
```blocks
|
||||
for (let index = 0; index <= 7; index++) {
|
||||
basic.showArrow(index)
|
||||
basic.pause(300)
|
||||
}
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[showIcon](/reference/basic/show-icon),
|
||||
[showLeds](/reference/basic/show-leds)
|
||||
@@ -24,7 +24,7 @@ bluetooth.stopAdvertising();
|
||||
## Example: stop advertising on button pressed
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
bluetooth.stopAdvertising();
|
||||
})
|
||||
```
|
||||
|
||||
@@ -27,7 +27,7 @@ bluetooth.onBluetoothDisconnected(() => {
|
||||
basic.showString("D");
|
||||
connected = 0;
|
||||
});
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
if (connected == 1) {
|
||||
bluetooth.uartWriteLine("HELLO");
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ bluetooth.onBluetoothDisconnected(() => {
|
||||
basic.showString("D");
|
||||
connected = 0;
|
||||
});
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
if (connected == 1) {
|
||||
bluetooth.uartWriteString("HELLO");
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ control.inBackground(() => {
|
||||
basic.pause(100)
|
||||
}
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
num++;
|
||||
})
|
||||
```
|
||||
@@ -42,7 +42,7 @@ let num = 0
|
||||
basic.forever(() => {
|
||||
basic.showNumber(num)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
num++;
|
||||
})
|
||||
```
|
||||
|
||||
@@ -24,11 +24,11 @@ When you get tired of counting, press button `B` to reset the
|
||||
```blocks
|
||||
let item = 0;
|
||||
basic.showNumber(item);
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
item = item + 1;
|
||||
basic.showNumber(item);
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Down, () => {
|
||||
control.reset();
|
||||
});
|
||||
```
|
||||
|
||||
@@ -9,7 +9,7 @@ An event handler is code that is associated with a particular event, such as "bu
|
||||
Functions named "on <event>" create an association between an event and the event handler code. For example, the following code registers the event handler (the code between the `do` and `end` keywords) with the event of a press of button A:
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
basic.showString("hello", 150)
|
||||
})
|
||||
```
|
||||
@@ -21,7 +21,7 @@ After this code executes, then whenever button A is pressed in the future, the s
|
||||
Once you have registered an event handler for an event, like above, that event handler is active for the rest of the program execution. If you want to stop the string "hello" from printing each time button A is pressed then you need to arrange for the following code to execute:
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
})
|
||||
```
|
||||
|
||||
@@ -32,10 +32,10 @@ The above code associated an event handler that does nothing with the event of a
|
||||
The above example also illustrates that there is only one event handler for each event. What is the result of the following code?
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
basic.showString("hello", 150)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
basic.showString("goodbye", 150)
|
||||
})
|
||||
```
|
||||
@@ -43,7 +43,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
The answer is that whenever button A is pressed, the string "goodbye" will be printed. If you want both the strings "hello" and "goodbye" to be printed, you need to write the code like this:
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
basic.showString("hello", 150)
|
||||
basic.showString("goodbye", 150)
|
||||
})
|
||||
|
||||
@@ -16,11 +16,11 @@ Press button ``A`` as much as possible to increase the score.
|
||||
Press ``B`` to display the score and reset the score.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Down, () => {
|
||||
basic.showNumber(game.score())
|
||||
game.setScore(0)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
```
|
||||
|
||||
@@ -16,7 +16,7 @@ Press button ``A`` as much as possible.
|
||||
At the end of 10 seconds, the program will show your score.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
game.startCountdown(10000)
|
||||
|
||||
@@ -27,7 +27,7 @@ let img = images.createImage(`
|
||||
. . . . .
|
||||
`)
|
||||
img.showImage(0)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
img.clear()
|
||||
img.showImage(0)
|
||||
})
|
||||
|
||||
@@ -14,10 +14,10 @@ If you press button `B`, it shows an animation and ends the game.
|
||||
|
||||
```blocks
|
||||
basic.showString("PICK A BUTTON");
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
basic.showString("YOU WIN!");
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Down, () => {
|
||||
game.gameOver();
|
||||
});
|
||||
```
|
||||
|
||||
@@ -20,7 +20,7 @@ degrees -- exactly the opposite direction.
|
||||
```blocks
|
||||
let ball = game.createSprite(4, 2);
|
||||
basic.showNumber(ball.get(LedSpriteProperty.Direction));
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Down, () => {
|
||||
ball.ifOnEdgeBounce();
|
||||
basic.showNumber(ball.get(LedSpriteProperty.Direction));
|
||||
});
|
||||
|
||||
@@ -15,7 +15,7 @@ game.isPaused()
|
||||
Resume the game if it's paused and button **B** is pressed.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, function () {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Down, function () {
|
||||
if (game.isPaused()) {
|
||||
game.resume()
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ game.isRunning()
|
||||
If the game is currently running, end the game if button **B** is pressed.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, function () {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, function () {
|
||||
if (game.isRunning()) {
|
||||
game.gameOver()
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ This program adds one point to your score every time you press button
|
||||
second) and shows your score.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Down, () => {
|
||||
game.addScore(1);
|
||||
basic.pause(500);
|
||||
basic.showNumber(game.score());
|
||||
|
||||
@@ -16,11 +16,11 @@ Press button ``A`` as much as possible to increase the score.
|
||||
Press ``B`` to display the score and reset the score.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
basic.showNumber(game.score())
|
||||
game.setScore(0)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
```
|
||||
|
||||
@@ -17,7 +17,7 @@ Press button ``A`` as much as possible.
|
||||
At the end of 10 seconds, the program will show your score.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
game.startCountdown(10000)
|
||||
|
||||
@@ -19,14 +19,12 @@ images.createBigImage(`
|
||||
`);
|
||||
images.createImage(``).showImage(0);
|
||||
images.createImage(``).scrollImage(0,0);
|
||||
images.arrowImage(ArrowNames.North)
|
||||
images.iconImage(IconNames.Heart)
|
||||
images.arrowNumber(ArrowNames.North)
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
[createImage](/reference/images/create-image), [createBigImage](/reference/images/create-big-image),
|
||||
[showImage](/reference/images/show-image), [scrollImage](/reference/images/scroll-image),
|
||||
[arrowImage](/reference/images/arrow-image), [iconImage](/reference/images/icon-image), [arrowNumber](/reference/images/arrow-number),
|
||||
[iconImage](/reference/images/icon-image),
|
||||
[pixel](/reference/images/pixel), [set-pixel](/reference/images/set-pixel)
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
# arrow Image
|
||||
|
||||
Create an arrow shaped [image](/reference/images/image) for the [LED screen](/device/screen).
|
||||
|
||||
```sig
|
||||
images.arrowImage(ArrowNames.North)
|
||||
```
|
||||
|
||||
The arrow points in the direction of the arrow name you choose, like `North`.
|
||||
|
||||
## Parameters
|
||||
|
||||
* **i**: the arrow name to make an arrow [image](/reference/images/image) for. You can make an arrow image that points in one of these directions:
|
||||
|
||||
>* `North`
|
||||
>* `NorthEast`
|
||||
>* `East`
|
||||
>* `SouthEast`
|
||||
>* `South`
|
||||
>* `SouthWest`
|
||||
>* `West`
|
||||
>* `NorthWest`
|
||||
|
||||
## Example
|
||||
|
||||
Display a left arrow when button A is pressed or a right arrow when button B is pressed.
|
||||
|
||||
```blocks
|
||||
let arrowLeft = images.arrowImage(ArrowNames.West)
|
||||
let arrowRight = images.arrowImage(ArrowNames.East)
|
||||
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
arrowLeft.showImage(0);
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
arrowRight.showImage(0);
|
||||
});
|
||||
```
|
||||
## See also
|
||||
|
||||
[arrow number](/reference/images/arrow-number)
|
||||
@@ -1,33 +0,0 @@
|
||||
# arrow Number
|
||||
|
||||
Get the number that matches an arrow image name.
|
||||
|
||||
```sig
|
||||
images.arrowNumber(ArrowNames.North)
|
||||
```
|
||||
|
||||
Each arrow image name has a number for it. You can find the number for any arrow name with ``||Images:arrow number||``.
|
||||
|
||||
## Parameters
|
||||
|
||||
* **arrow**: the arrow name to get an arrow number for. These are the arrow names:
|
||||
|
||||
>* `North`
|
||||
* `NorthEast`
|
||||
* `East`
|
||||
* `SouthEast`
|
||||
* `South`
|
||||
* `SouthWest`
|
||||
* `West`
|
||||
* `NorthWest`
|
||||
|
||||
## Example
|
||||
|
||||
Get the arrow number for `ArrowNames.South`.
|
||||
|
||||
```blocks
|
||||
let arrowSouthNumber = images.arrowNumber(ArrowNames.South)
|
||||
```
|
||||
## See also
|
||||
|
||||
[arrow image](/reference/images/arrow-image)
|
||||
@@ -36,10 +36,10 @@ let arrows = images.createBigImage(`
|
||||
. . # . . . # # # .
|
||||
. . # . . . . # . .
|
||||
`);
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
arrows.showImage(0);
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
arrows.showImage(5);
|
||||
});
|
||||
```
|
||||
|
||||
@@ -25,7 +25,7 @@ arrow and show it on the LED screen. If you press button `B`, the
|
||||
program will show a picture of the arrow upside-down.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. # # # .
|
||||
@@ -34,7 +34,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
. . # . .
|
||||
`).showImage(0);
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
|
||||
@@ -20,10 +20,10 @@ Show a happy face when button A is pressed or a sad face when button B is presse
|
||||
let iamHappy = images.iconImage(IconNames.Happy)
|
||||
let iamSad = images.iconImage(IconNames.Sad)
|
||||
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
iamHappy.showImage(0);
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
iamSad.showImage(0);
|
||||
});
|
||||
```
|
||||
|
||||
@@ -31,10 +31,10 @@ let arrows = images.createBigImage(`
|
||||
. . # . . . # # # .
|
||||
. . # . . . . # . .
|
||||
`);
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
arrows.showImage(0);
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
arrows.showImage(5);
|
||||
});
|
||||
```
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
Events and data from sensors
|
||||
|
||||
```cards
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
|
||||
});
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
|
||||
});
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
input.onPinTouchEvent(TouchPin.P0, ButtonEvent.Click, () => {
|
||||
|
||||
});
|
||||
input.buttonIsPressed(Button.A);
|
||||
|
||||
@@ -23,7 +23,7 @@ confuse the @boardname@.
|
||||
This example runs the calibration when the user presses **A+B** buttons.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.AB, () => {
|
||||
input.onButtonEvent(Button.AB, ButtonEvent.Click, () => {
|
||||
input.calibrateCompass();
|
||||
})
|
||||
```
|
||||
|
||||
@@ -41,15 +41,15 @@ let degrees = 0
|
||||
basic.forever(() => {
|
||||
degrees = input.compassHeading()
|
||||
if (degrees < 45) {
|
||||
basic.showArrow(ArrowNames.North)
|
||||
basic.showIcon(IconNames.ArrowNorth)
|
||||
} else if (degrees < 135) {
|
||||
basic.showArrow(ArrowNames.East)
|
||||
basic.showIcon(IconNames.ArrowEast)
|
||||
} else if (degrees < 225) {
|
||||
basic.showArrow(ArrowNames.South)
|
||||
basic.showIcon(IconNames.ArrowSouth)
|
||||
} else if (degrees < 315) {
|
||||
basic.showArrow(ArrowNames.West)
|
||||
basic.showIcon(IconNames.ArrowWest)
|
||||
} else {
|
||||
basic.showArrow(ArrowNames.North)
|
||||
basic.showIcon(IconNames.ArrowNorth)
|
||||
}
|
||||
})
|
||||
```
|
||||
@@ -70,7 +70,7 @@ confuse the @boardname@.
|
||||
Keep the calibration handy by running it when the user pressed **A+B**.
|
||||
|
||||
```block
|
||||
input.onButtonPressed(Button.AB, () => {
|
||||
input.onButtonEvent(Button.AB, ButtonEvent.Click, () => {
|
||||
input.calibrateCompass();
|
||||
})
|
||||
```
|
||||
|
||||
@@ -29,7 +29,7 @@ program shows the light level
|
||||
on the [LED screen](/device/screen).
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
let level = input.lightLevel()
|
||||
basic.showNumber(level)
|
||||
})
|
||||
|
||||
@@ -9,7 +9,7 @@ on the @boardname@.
|
||||
* For `A` and `B` together: This handler works when `A` and `B` are both pushed down, then one of them is released within 1.5 seconds of pushing down the second button.
|
||||
|
||||
```sig
|
||||
input.onButtonPressed(Button.A, () => {})
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {})
|
||||
```
|
||||
|
||||
Find out how buttons provide input to the @boardname@ in this video:
|
||||
@@ -24,7 +24,7 @@ Each time you press the button, the [LED screen](/device/screen) shows the `coun
|
||||
```blocks
|
||||
let count = 0
|
||||
basic.showNumber(count)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
count++;
|
||||
basic.showNumber(count);
|
||||
})
|
||||
@@ -35,7 +35,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
This example shows a number from 1 to 6 when you press the `B` button.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
let dice = randint(0, 5) + 1
|
||||
basic.showNumber(dice)
|
||||
})
|
||||
|
||||
@@ -14,7 +14,7 @@ through your body and back into the @boardname@. This is called
|
||||
**completing a circuit**. It's like you're a big wire!
|
||||
|
||||
```sig
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
input.onPinTouchEvent(TouchPin.P0, ButtonEvent.Click, () => {
|
||||
})
|
||||
```
|
||||
|
||||
@@ -43,7 +43,7 @@ Every time you press the pin, the program shows the number of times on the scree
|
||||
```blocks
|
||||
let count = 0
|
||||
basic.showNumber(count)
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
input.onPinTouchEvent(TouchPin.P0, ButtonEvent.Click, () => {
|
||||
count = count + 1
|
||||
basic.showNumber(count)
|
||||
})
|
||||
|
||||
@@ -13,7 +13,7 @@ through your body and back into the @boardname@. This is called
|
||||
**completing a circuit**. It's like you're a big wire!
|
||||
|
||||
```sig
|
||||
input.onPinReleased(TouchPin.P0, () => {
|
||||
input.onPinTouchEvent(TouchPin.P0, ButtonEvent.Up, () => {
|
||||
})
|
||||
```
|
||||
|
||||
@@ -36,7 +36,7 @@ Every time you release the pin, the program shows the number of times on the scr
|
||||
```blocks
|
||||
let count = 0
|
||||
basic.showNumber(count, 100)
|
||||
input.onPinReleased(TouchPin.P0, () => {
|
||||
input.onPinTouchEvent(TouchPin.P0, ButtonEvent.Up, () => {
|
||||
count = count + 1
|
||||
basic.showNumber(count, 100)
|
||||
})
|
||||
|
||||
@@ -18,7 +18,7 @@ program finds the number of milliseconds since the program started
|
||||
and shows it on the [LED screen](/device/screen).
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
let now = input.runningTime()
|
||||
basic.showNumber(now)
|
||||
})
|
||||
|
||||
@@ -15,7 +15,7 @@ led.enable(false);
|
||||
This program turns off the screen when pressing button ``B``
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
led.enable(false)
|
||||
});
|
||||
```
|
||||
|
||||
@@ -13,7 +13,7 @@ This program sets up the ``stop animation`` part of the program,
|
||||
and then shows a string that you can stop with button ``B``.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
led.stopAnimation();
|
||||
});
|
||||
basic.showString("STOP ME! STOP ME! PLEASE, WON'T SOMEBODY STOP ME?");
|
||||
|
||||
@@ -43,7 +43,7 @@ music.onEvent(MusicEvent.BackgroundMelodyResumed, () => {
|
||||
music.onEvent(MusicEvent.BackgroundMelodyRepeated, () => {
|
||||
serial.writeLine("background repeated")
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
music.beginMelody(music.builtInMelody(Melodies.BaDing), MelodyOptions.Once)
|
||||
})
|
||||
music.setTempo(100)
|
||||
|
||||
@@ -17,7 +17,7 @@ This example send the frequency and duration over radio
|
||||
and plays it on the remote @boardname@.
|
||||
|
||||
```typescript
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
music.playTone(440, 120)
|
||||
led.toggle(0, 0)
|
||||
})
|
||||
@@ -26,7 +26,7 @@ radio.onReceivedNumber(function (receivedNumber) {
|
||||
const duration = receivedNumber & 0xffff;
|
||||
music.playTone(freq, duration);
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
music.setPlayTone((frequency: number, duration: number) => {
|
||||
radio.sendNumber((frequency << 16) | (duration & 0xffff));
|
||||
})
|
||||
|
||||
@@ -48,7 +48,7 @@ keeper @boardname@, you can press button `B` on the remote to buzz and
|
||||
make the score bigger on the other @boardname@.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
pins.digitalWritePin(DigitalPin.P1, 1);
|
||||
basic.pause(500);
|
||||
pins.digitalWritePin(DigitalPin.P1, 0);
|
||||
|
||||
@@ -46,7 +46,7 @@ will use ``digital write pin`` to make the other @boardname@ buzz and
|
||||
make the score bigger.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
pins.digitalWritePin(DigitalPin.P1, 1);
|
||||
basic.pause(500);
|
||||
pins.digitalWritePin(DigitalPin.P1, 0);
|
||||
|
||||
@@ -34,7 +34,7 @@ If you load this program onto two or more @boardname@s, you can send a code word
|
||||
The other @boardname@s will receive the code word and then show it.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
radio.sendString("Codeword: TRIMARAN")
|
||||
basic.showString("SENT");
|
||||
})
|
||||
@@ -59,10 +59,10 @@ This program will also receive your friend's mood.
|
||||
|
||||
```blocks
|
||||
let data: string = "";
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
radio.sendString("H");
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
radio.sendString("S");
|
||||
});
|
||||
radio.onDataReceived(() => {
|
||||
|
||||
@@ -27,7 +27,7 @@ in the `x` direction (left and right) to other @boardname@s. This kind
|
||||
of program might be useful in a model car or model rocket.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
radio.sendNumber(input.acceleration(Dimension.X))
|
||||
})
|
||||
```
|
||||
|
||||
@@ -26,7 +26,7 @@ code word from one of them to the others by pressing button `A`. The
|
||||
other @boardname@s will receive the code word and then show it.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
radio.sendString("Codeword: TRIMARAN")
|
||||
basic.showString("SENT");
|
||||
})
|
||||
|
||||
@@ -29,7 +29,7 @@ or model rocket.
|
||||
|
||||
```blocks
|
||||
radio.setGroup(99)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
radio.sendValue("acc", input.acceleration(Dimension.X))
|
||||
})
|
||||
```
|
||||
|
||||
@@ -30,7 +30,7 @@ the second @boardname@), this program sends temperature data to the
|
||||
serial port.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, function () {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, function () {
|
||||
radio.sendNumber(input.temperature())
|
||||
radio.sendValue("temp", input.temperature())
|
||||
radio.sendString("It's warm now")
|
||||
|
||||
@@ -29,7 +29,7 @@ the second @boardname@), this program sends temperature data to
|
||||
serial.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
radio.sendNumber(input.temperature());
|
||||
});
|
||||
radio.onDataReceived(() => {
|
||||
|
||||
@@ -32,7 +32,7 @@ serial port to use the pins. The new configuration uses pin ``P1`` to transmit a
|
||||
``P2`` to receive. The baud rate is set to `9600`.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
serial.redirect(SerialPin.P1, SerialPin.P2, BaudRate.BaudRate9600);
|
||||
});
|
||||
```
|
||||
|
||||
@@ -34,19 +34,19 @@ let direction = ""
|
||||
basic.forever(() => {
|
||||
degrees = input.compassHeading()
|
||||
if (degrees < 45) {
|
||||
basic.showArrow(ArrowNames.North)
|
||||
basic.showIcon(IconNames.ArrowNorth)
|
||||
direction = "North"
|
||||
} else if (degrees < 135) {
|
||||
basic.showArrow(ArrowNames.East)
|
||||
basic.showIcon(IconNames.ArrowEast)
|
||||
direction = "East"
|
||||
} else if (degrees < 225) {
|
||||
basic.showArrow(ArrowNames.South)
|
||||
basic.showIcon(IconNames.ArrowSouth)
|
||||
direction = "South"
|
||||
} else if (degrees < 315) {
|
||||
basic.showArrow(ArrowNames.West)
|
||||
basic.showIcon(IconNames.ArrowWest)
|
||||
direction = "West"
|
||||
} else {
|
||||
basic.showArrow(ArrowNames.North)
|
||||
basic.showIcon(IconNames.ArrowNorth)
|
||||
direction = "North"
|
||||
}
|
||||
serial.writeLine(direction + " @ " + degrees + " degrees")
|
||||
|
||||
@@ -13,7 +13,7 @@ basic.showString("Micro!")
|
||||
Well, the text stopped scrolling. Place the ``||basic:show string||`` block in the ``||input:on button pressed||`` slot to scroll your name when button **A** is pressed.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
basic.showString("Micro!")
|
||||
});
|
||||
```
|
||||
@@ -25,7 +25,7 @@ Place some blocks to display a smiley when button **B** is pressed.
|
||||
Use the dropdown to find ``B``!
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
basic.showLeds(`
|
||||
# # . # #
|
||||
# # . # #
|
||||
|
||||
@@ -13,7 +13,7 @@ basic.showString("My Name")
|
||||
Well, you noticed that the text stopped. Place the ``||basic:show string||`` block in an ``||input:on button pressed||`` block to scroll your name whenever button **A** is pressed.
|
||||
|
||||
```block
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
basic.showString("My Name")
|
||||
});
|
||||
```
|
||||
@@ -23,7 +23,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
Ok, let's try to talk to the @boardname@ using a button. Change the text in ``||basic:show string||`` to ask the question "How are you?". Add another ``||basic:show string||`` with "....." to show that the @boardname@ is thinking.
|
||||
|
||||
```block
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
basic.showString("How are you?")
|
||||
basic.showString(".....");
|
||||
})
|
||||
@@ -34,7 +34,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
Now, make the @boardname@ give an answer with a smiley face! Find the ``||basic:show leds||`` and draw a smiley face on the block by clicking on the LEDs. Press button **A** in the simulator and see the @boardname@ respond to your question.
|
||||
|
||||
```block
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
basic.showString("How are you?")
|
||||
basic.showString(".....");
|
||||
basic.showLeds(`
|
||||
|
||||
@@ -57,7 +57,7 @@ You could simply save the light measurements in an array like this:
|
||||
|
||||
```blocks
|
||||
let darkness: number[] = []
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
for (let i = 0; i < 60 * 4; i++) {
|
||||
darkness.push(input.lightLevel())
|
||||
basic.pause(60000)
|
||||
@@ -77,7 +77,7 @@ The code in blocks for recording the light level is modified to make our file da
|
||||
|
||||
```typescript-ignore
|
||||
let darkness = pins.createBuffer(60 * 4);
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
for (let i = 0; i < 60 * 4; i++) {
|
||||
darkness.setNumber(NumberFormat.UInt8LE, i, input.lightLevel())
|
||||
basic.pause(60000)
|
||||
@@ -90,7 +90,7 @@ Later, we can upload the file to the laptop computer by pressing the **B** butto
|
||||
```typescript-ignore
|
||||
let dataReady = false;
|
||||
let darkness = pins.createBuffer(60 * 4);
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
|
||||
for (let i = 0; i < 60 * 4; i++) {
|
||||
darkness.setNumber(NumberFormat.UInt8LE, i, input.lightLevel())
|
||||
basic.pause(60000)
|
||||
@@ -98,7 +98,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
dataReady = true;
|
||||
})
|
||||
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
|
||||
if (dataReady) {
|
||||
serial.writeLine("Transferring file: DARKNESS, Length: " + darkness.length + " bytes...");
|
||||
serial.writeBuffer(darkness)
|
||||
|
||||
Reference in New Issue
Block a user