Compare commits
65 Commits
Author | SHA1 | Date | |
---|---|---|---|
532abadb6b | |||
eea179e07c | |||
f94015803f | |||
f085253306 | |||
6de2f22542 | |||
3051e09bcf | |||
bd835a8a6e | |||
f75a034a3f | |||
71b3b6bb22 | |||
b868bd1e09 | |||
02e48f196c | |||
742eb7ea2f | |||
f1904143b6 | |||
e621252f3b | |||
3633d39f57 | |||
21bbf8fc86 | |||
dd5124f660 | |||
966ad1f503 | |||
d94f394d24 | |||
40ddd896cf | |||
5a8815c4fc | |||
9a04eb1790 | |||
906e2a2fff | |||
781339026e | |||
bd23de14e1 | |||
e6ca366d20 | |||
e2ce49d94b | |||
e3b6350785 | |||
66aba696dc | |||
5206f1f8e8 | |||
f9a7ec89e4 | |||
97894511dd | |||
e785ece9bd | |||
63035b3d5c | |||
1f8ea7ad30 | |||
899ca47a77 | |||
84f14182bf | |||
ca3702b4fe | |||
94f1b6c785 | |||
c749c8b644 | |||
b108f1538d | |||
45690215dd | |||
af42dbf30a | |||
45ecd883bb | |||
641a714f74 | |||
d1cd0a23a2 | |||
54331eb113 | |||
d4c53f1fb3 | |||
40305c3ccd | |||
e6761699d3 | |||
b15f140181 | |||
00e38e202b | |||
4cbabcd112 | |||
5def3518cf | |||
2c6f76e1a5 | |||
3eb529852b | |||
3b0cb40ea9 | |||
5cb3467194 | |||
d5628c08c8 | |||
c5c0103573 | |||
b89d6477c7 | |||
f3a6b00734 | |||
091fbb9db8 | |||
3de977c98f | |||
d262dc3704 |
@ -24,24 +24,23 @@ npm install
|
|||||||
|
|
||||||
### Running
|
### Running
|
||||||
|
|
||||||
Run this command to open a local web server:
|
Run this command to open a local web server (add ``sudo`` for Mac/Linux shells)
|
||||||
```
|
```
|
||||||
pxt serve
|
pxt serve
|
||||||
```
|
```
|
||||||
If the local server opens in the wrong browser, make sure to copy the URL containing the local token.
|
If the local server opens in the wrong browser, make sure to copy the URL containing the local token.
|
||||||
Otherwise, the editor will not be able to load the projects.
|
Otherwise, the editor will not be able to load the projects.
|
||||||
|
|
||||||
If you need modify the `.cpp` files, turn on yotta compilation with the ``-yt`` flag:
|
If you need modify the `.cpp` files, turn on yotta compilation with the ``-yt`` flag (add ``sudo`` for Mac/Linux shells):
|
||||||
```
|
```
|
||||||
pxt serve -yt
|
pxt serve -yt
|
||||||
```
|
```
|
||||||
|
|
||||||
To make sure you're running the latest tools, run
|
To make sure you're running the latest tools, run (add ``sudo`` for Mac/Linux shells)
|
||||||
```
|
```
|
||||||
npm update
|
pxt update
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
More instructions at https://github.com/Microsoft/pxt#running-a-target-from-localhost
|
More instructions at https://github.com/Microsoft/pxt#running-a-target-from-localhost
|
||||||
|
|
||||||
## Universal Windows App
|
## Universal Windows App
|
||||||
|
@ -28,6 +28,7 @@ input.onButtonPressed(Button.B, () => {
|
|||||||
* Browse the [API reference](/reference)
|
* Browse the [API reference](/reference)
|
||||||
* Learn more about the [device](/device)
|
* Learn more about the [device](/device)
|
||||||
* Get started with [lessons](/lessons)
|
* Get started with [lessons](/lessons)
|
||||||
|
* Frequently Asked Question [faq](/faq)
|
||||||
* Follow up with the [release notes](/release-notes)
|
* Follow up with the [release notes](/release-notes)
|
||||||
|
|
||||||
### Developers
|
### Developers
|
||||||
|
6
docs/faq.md
Normal file
6
docs/faq.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# Frequently Asked Questions
|
||||||
|
|
||||||
|
## Where can I get a BBC micro:bit?
|
||||||
|
|
||||||
|
More information at [http://uk.farnell.com/bbc-microbit](http://uk.farnell.com/bbc-microbit).
|
||||||
|
|
@ -1,37 +1,21 @@
|
|||||||
# Getting started
|
# Getting started
|
||||||
|
|
||||||
|
## ~avatar
|
||||||
|
|
||||||
Are you ready to build cool BBC micro:bit programs?
|
Are you ready to build cool BBC micro:bit programs?
|
||||||
|
|
||||||
Here are some challenges for you. Unscramble the blocks in the editor
|
Here are some challenges for you. Unscramble the blocks in the editor
|
||||||
to make real programs that work!
|
to make real programs that work!
|
||||||
|
|
||||||
### Show LEDs
|
## ~
|
||||||
|
|
||||||
Draw something in the editor with this block. You can draw another
|
### Happy face
|
||||||
smiley face, or try something else.
|
|
||||||
|
|
||||||
```shuffle
|
There are three blocks in the editor (the area to the left).
|
||||||
basic.showLeds(`
|
They should look like this:
|
||||||
. . . . .
|
|
||||||
. # . # .
|
|
||||||
. . . . .
|
|
||||||
# . . . #
|
|
||||||
. # # # .
|
|
||||||
`)
|
|
||||||
```
|
|
||||||
|
|
||||||
To move your program from your computer to the BBC micro:bit:
|
|
||||||
* Connect your micro:bit to the computer with the USB cable.
|
|
||||||
* Click **Compile**.
|
|
||||||
* Drag and drop the new file whose name ends in **.hex** into the **MICROBIT** window.
|
|
||||||
* Wait until the yellow light stops blinking!
|
|
||||||
|
|
||||||
### Show animation forever
|
|
||||||
|
|
||||||
Show one picture after another by snapping blocks together to create an
|
|
||||||
animation (like a cartoon)!
|
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
|
basic.forever(() => {
|
||||||
basic.showLeds(`
|
basic.showLeds(`
|
||||||
. . . . .
|
. . . . .
|
||||||
. # . # .
|
. # . # .
|
||||||
@ -41,28 +25,29 @@ animation (like a cartoon)!
|
|||||||
`)
|
`)
|
||||||
basic.showLeds(`
|
basic.showLeds(`
|
||||||
. . . . .
|
. . . . .
|
||||||
. # . # .
|
|
||||||
. . . . .
|
. . . . .
|
||||||
. # # # .
|
. . . . .
|
||||||
# . . . #
|
. . . . .
|
||||||
|
. . . . .
|
||||||
`)
|
`)
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
To move your program from your computer to the BBC micro:bit:
|
When you run this program, you will see a smiley face, then a blank
|
||||||
* Connect your micro:bit to the computer with the USB cable.
|
screen, then a smiley again -- it never stops! (That's because of the
|
||||||
* Click **Compile**.
|
``forever`` block.)
|
||||||
* Drag and drop the new file whose name ends in **.hex** into the **MICROBIT** window.
|
|
||||||
* Wait until the yellow light stops blinking!
|
|
||||||
|
|
||||||
### Repeat Forever
|
Click **Compile** to move your program to the BBC micro:bit!
|
||||||
|
|
||||||
Make an animation that never stops with the ``forever`` block.
|
### Happy unhappy face
|
||||||
|
|
||||||
Unscramble these blocks in the editor to make an animation that first
|
Draw an unhappy face instead of the blank screen. Click on the dots
|
||||||
shows a happy face, then an unhappy face, then a happy face, and never
|
in the second ``show leds`` block until it matches the blocks below.
|
||||||
stops.
|
Now you have an **animation** (cartoon) that shows a happy face,
|
||||||
|
then an unhappy one, then a happy one again, forever (or until
|
||||||
|
you turn off your micro:bit)!
|
||||||
|
|
||||||
```shuffle
|
```blocks
|
||||||
basic.forever(() => {
|
basic.forever(() => {
|
||||||
basic.showLeds(`
|
basic.showLeds(`
|
||||||
. . . . .
|
. . . . .
|
||||||
@ -80,43 +65,107 @@ basic.forever(() => {
|
|||||||
`)
|
`)
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
Click **Compile** to move your program to the BBC micro:bit!
|
||||||
|
|
||||||
### Your turn!
|
### Your turn!
|
||||||
|
|
||||||
You can also change the pictures to make your own animation.
|
Pile up more ``show leds`` blocks to create your animation! Create an
|
||||||
Make your own awesome animation with the ``show leds`` and ``forever``
|
animation with at least 5 pictures. What does this animation show?
|
||||||
blocks.
|
|
||||||
|
```blocks
|
||||||
|
basic.forever(() => {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
. # . # .
|
||||||
|
. . . . .
|
||||||
|
# . . . #
|
||||||
|
. # # # .
|
||||||
|
`)
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
. # . # .
|
||||||
|
. . . . .
|
||||||
|
# # # # #
|
||||||
|
. . . . .
|
||||||
|
`)
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
. # . # .
|
||||||
|
. . . . .
|
||||||
|
. # # # .
|
||||||
|
# . . . #
|
||||||
|
`)
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
. # . # .
|
||||||
|
. . . . .
|
||||||
|
# # # # #
|
||||||
|
. . . # #
|
||||||
|
`)
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
# . # . .
|
||||||
|
. . . . .
|
||||||
|
# . . . #
|
||||||
|
. # # # .
|
||||||
|
`)
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
. . # . #
|
||||||
|
. . . . .
|
||||||
|
# . . . #
|
||||||
|
. # # # .
|
||||||
|
`)
|
||||||
|
});
|
||||||
|
```
|
||||||
|
Click **Compile** to move your program to the BBC micro:bit!
|
||||||
|
|
||||||
#### ~hint
|
#### ~hint
|
||||||
|
|
||||||
You can make your animation longer if you use more than two pictures.
|
You can find the ``show leds`` block in the **Basic** part of the editor.
|
||||||
|
|
||||||
#### ~
|
#### ~
|
||||||
|
|
||||||
### Button A and B
|
### Button A and button B
|
||||||
|
|
||||||
This program will show the word `banana` on the LED
|
This program will show the word **ANTEATER** on the LED
|
||||||
screen when you press button `B`.
|
screen when you press button `A`.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
input.onButtonPressed(Button.B, () => {
|
input.onButtonPressed(Button.A, () => {
|
||||||
basic.showString("banana");
|
basic.showString("ANTEATER");
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### ~hint
|
||||||
|
|
||||||
|
The ``showString`` block can show letters, numbers, and punctuation
|
||||||
|
on the micro:bit screen.
|
||||||
|
|
||||||
|
#### ~
|
||||||
|
|
||||||
Now try to unscramble these blocks in the editor so that the micro:bit
|
Now try to unscramble these blocks in the editor so that the micro:bit
|
||||||
shows **YES** when you press button `A` and **NO** when when you press
|
shows **BANANA** when you press button `B`.
|
||||||
button `B`. All of the blocks under `on button A pressed` or
|
|
||||||
`on button B pressed` should run when you press that button.
|
|
||||||
|
|
||||||
```shuffle
|
```shuffle
|
||||||
input.onButtonPressed(Button.A, () => {
|
|
||||||
basic.showString("YES");
|
|
||||||
});
|
|
||||||
input.onButtonPressed(Button.B, () => {
|
input.onButtonPressed(Button.B, () => {
|
||||||
basic.showString("NO");
|
basic.showString("BANANA");
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
#### ~hint
|
||||||
|
|
||||||
|
You can find the letter `B` by clicking the letter `A` on the
|
||||||
|
``onButtonPressed`` block.
|
||||||
|
|
||||||
|
#### ~
|
||||||
|
|
||||||
|
Click **Compile** to move your program to the BBC micro:bit!
|
||||||
|
|
||||||
|
#### Your turn!
|
||||||
|
|
||||||
|
Can you combine these blocks so your program shows your real name
|
||||||
|
instead of **ANTEATER** when you press `A`, but _your secret agent
|
||||||
|
name_ instead of **BANANA** when you press `B`?
|
||||||
|
|
||||||
### Shake
|
### Shake
|
||||||
|
|
||||||
@ -125,7 +174,7 @@ You can find when someone is shaking the BBC micro:bit by checking its
|
|||||||
slowing down).
|
slowing down).
|
||||||
|
|
||||||
Unscramble these blocks in the editor to show a frownie when someone
|
Unscramble these blocks in the editor to show a frownie when someone
|
||||||
shakes the micro:bit.
|
shakes the micro:bit. (Ouch!)
|
||||||
|
|
||||||
```shuffle
|
```shuffle
|
||||||
input.onGesture(Gesture.Shake, () => {
|
input.onGesture(Gesture.Shake, () => {
|
||||||
@ -137,68 +186,317 @@ input.onGesture(Gesture.Shake, () => {
|
|||||||
# . . . #`);
|
# . . . #`);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
Click **Compile** to move your program to the BBC micro:bit!
|
||||||
### Tilting with gestures
|
|
||||||
|
|
||||||
You can also find when someone is tilting the micro:bit left or right,
|
|
||||||
face up or face down, and logo up or logo down (the logo is the yellow
|
|
||||||
oval picture at the top of the board).
|
|
||||||
|
|
||||||
Try to build a Rock Paper Scissors game where you tilt the micro:bit
|
|
||||||
left to show paper, right to show scissors, and down to show rock.
|
|
||||||
|
|
||||||
Unscramble these blocks in the editor and try this program on the
|
|
||||||
micro:bit itself!
|
|
||||||
|
|
||||||
```shuffle
|
|
||||||
input.onGesture(Gesture.TiltLeft, () => {
|
|
||||||
basic.showLeds(`
|
|
||||||
# # # # #
|
|
||||||
# . . . #
|
|
||||||
# . . . #
|
|
||||||
# . . . #
|
|
||||||
# # # # #`);
|
|
||||||
});
|
|
||||||
input.onGesture(Gesture.LogoDown, () => {
|
|
||||||
basic.showLeds(`
|
|
||||||
. . . . .
|
|
||||||
. # # # .
|
|
||||||
. # # # .
|
|
||||||
. # # # .
|
|
||||||
. . . . .`);
|
|
||||||
});
|
|
||||||
input.onGesture(Gesture.TiltRight, () => {
|
|
||||||
basic.showLeds(`
|
|
||||||
# # . . #
|
|
||||||
# # . # .
|
|
||||||
. . # . .
|
|
||||||
# # . # .
|
|
||||||
# # . . #`);
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
### Pins
|
### Pins
|
||||||
|
|
||||||
You can also use the pins as buttons. (The pins are the holes in the
|
You can also use the pins as buttons. (The pins are the holes in the
|
||||||
metal bar at the bottom of the micro:bit board.) For example, hold
|
metal stripe at the bottom of the micro:bit board.) For example, hold
|
||||||
the ``GND`` button with one hand and touch the ``0`` pin (called
|
the ``GND`` button with one hand and touch the ``0`` pin (called
|
||||||
``P0``) with your other hand to tell the micro:bit you're pressing it.
|
``P0``) with your other hand to tell the micro:bit you're pressing it.
|
||||||
|
|
||||||
Unscramble the blocks in the editor to show a smiley when you press
|
Unscramble the blocks in the editor to show a heart when you touch
|
||||||
pin ``P0``.
|
pin ``P0``.
|
||||||
|
|
||||||
```shuffle
|
```shuffle
|
||||||
input.onPinPressed(TouchPin.P0, () => {
|
input.onPinPressed(TouchPin.P0, () => {
|
||||||
basic.showLeds(`
|
basic.showLeds(`
|
||||||
. . . . .
|
|
||||||
. # . # .
|
. # . # .
|
||||||
. . . . .
|
# . # . #
|
||||||
# . . . #
|
# . . . #
|
||||||
. # # # .`);
|
. # . # .
|
||||||
|
. . # . .`);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
Click **Compile** to move your program to the BBC micro:bit!
|
||||||
|
|
||||||
|
## ~hint
|
||||||
|
|
||||||
|
Try this experiment: find a friend and hold hands. Touch the ``GND``
|
||||||
|
pin while your friend presses the ``P0`` pin. You should see the
|
||||||
|
heart! The electric current is going through your bodies and across
|
||||||
|
your handshake to make it happen!
|
||||||
|
|
||||||
|
## ~
|
||||||
|
|
||||||
|
## The amazing coin flipper
|
||||||
|
|
||||||
|
### ~avatar avatar
|
||||||
|
|
||||||
|
Are you trying to choose whether to play soccer or go to the movies
|
||||||
|
instead, or which toppings to have on your pizza? Build a coin
|
||||||
|
flipping machine with the BBC micro:bit to choose for you!
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
Here are the blocks to make your coin flipper. When you press button
|
||||||
|
`B`, the coin flipper will show either `H` for heads or `T` for tails
|
||||||
|
on the LED screen.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
input.onButtonPressed(Button.B, () => {
|
||||||
|
if (Math.randomBoolean()) {
|
||||||
|
basic.showString("H");
|
||||||
|
} else {
|
||||||
|
basic.showString("T");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
### ~hint
|
||||||
|
|
||||||
|
The ``pick random true or false`` block randomly tells the ``if``
|
||||||
|
block `true` or `false`. If the ``pick`` block picked `true`, the
|
||||||
|
``if`` block shows the letter `H`. Otherwise, it shows the letter `T`.
|
||||||
|
|
||||||
|
That's it!
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
### Keeping score
|
||||||
|
|
||||||
|
#### ~avatar
|
||||||
|
|
||||||
|
To keep track out of how many guesses you've won,
|
||||||
|
add these blocks to your coin flipper:
|
||||||
|
|
||||||
|
#### ~
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
input.onButtonPressed(Button.A, () => {
|
||||||
|
game.addScore(1);
|
||||||
|
});
|
||||||
|
input.onButtonPressed(Button.AB, () => {
|
||||||
|
basic.showNumber(game.score());
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Your turn!
|
These blocks mean that if you press button `A`, you will add `1` to
|
||||||
|
your score, and if you press `A` and `B` together, the micro:bit will
|
||||||
|
show your score.
|
||||||
|
|
||||||
Use the screen, buttons, gestures, and pins to make your own fun game
|
When you're done, your coin flipping program should look like this:
|
||||||
with the BBC micro:bit!
|
|
||||||
|
```blocks
|
||||||
|
input.onButtonPressed(Button.B, () => {
|
||||||
|
if (Math.randomBoolean()) {
|
||||||
|
basic.showString("H");
|
||||||
|
} else {
|
||||||
|
basic.showString("T");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
input.onButtonPressed(Button.A, () => {
|
||||||
|
game.addScore(1);
|
||||||
|
});
|
||||||
|
input.onButtonPressed(Button.AB, () => {
|
||||||
|
basic.showNumber(game.score());
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Flip until your thumbs get tired!
|
||||||
|
|
||||||
|
## Let's play Rock Paper Scissors!
|
||||||
|
|
||||||
|
### ~avatar avatar
|
||||||
|
|
||||||
|
Build a Rock Paper Scissors game with the BBC micro:bit! You can play
|
||||||
|
the game with a friend who has it on a micro:bit. You can also play
|
||||||
|
it with friends who are just using their hands. (The game is built
|
||||||
|
like a coin flipper, but with three choices instead of two.)
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
## Step 1: Getting started
|
||||||
|
|
||||||
|
We want the micro:bit to choose rock, paper, or scissors when you
|
||||||
|
shake it. Try creating an ``on shake`` block so when you shake the
|
||||||
|
micro:bit, it will run part of a program.
|
||||||
|
|
||||||
|
Clear up the blocks and add the blocks below.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
input.onGesture(Gesture.Shake, () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
Next, when you shake the micro:bit, it should pick a random number from `0` to `2`
|
||||||
|
and store it in the variable `item`.
|
||||||
|
|
||||||
|
Add a ``set`` block with a variable. Then add a ``pick random`` block,
|
||||||
|
and store the random number in the variable,
|
||||||
|
like this:
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
input.onGesture(Gesture.Shake, () => {
|
||||||
|
let item = Math.random(3)
|
||||||
|
})
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### ~hint
|
||||||
|
No one can predict random numbers. That's what makes them great for Rock Paper Scissors!
|
||||||
|
### ~
|
||||||
|
|
||||||
|
Each possible number these blocks can make (`0`, `1`, or `2`) means a different picture.
|
||||||
|
We will show the right picture for that number on the LED screen.
|
||||||
|
|
||||||
|
|
||||||
|
## Step 2: Picking paper
|
||||||
|
|
||||||
|
Put an ``if`` block after the ``let`` block that checks whether
|
||||||
|
`item` is `0`. Make sure the ``if`` block has an ``else if`` part
|
||||||
|
and an ``else`` part.
|
||||||
|
|
||||||
|
Next, add a ``show leds`` block that shows a
|
||||||
|
picture of a piece of paper:
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
input.onGesture(Gesture.Shake, () => {
|
||||||
|
let item = Math.random(3)
|
||||||
|
if (item == 0) {
|
||||||
|
basic.showLeds(`
|
||||||
|
# # # # #
|
||||||
|
# . . . #
|
||||||
|
# . . . #
|
||||||
|
# . . . #
|
||||||
|
# # # # #
|
||||||
|
`)
|
||||||
|
} else if (false) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 3: A random rock
|
||||||
|
|
||||||
|
Now we are going to add a new picture for the micro:bit to show
|
||||||
|
when another random number comes up.
|
||||||
|
|
||||||
|
Make the ``else if`` part check if the variable `item` is `1`.
|
||||||
|
Then add a ``show leds`` block with a picture of a rock.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
input.onGesture(Gesture.Shake, () => {
|
||||||
|
let item = Math.random(3)
|
||||||
|
if (item == 0) {
|
||||||
|
basic.showLeds(`
|
||||||
|
# # # # #
|
||||||
|
# . . . #
|
||||||
|
# . . . #
|
||||||
|
# . . . #
|
||||||
|
# # # # #
|
||||||
|
`)
|
||||||
|
} else if (item == 1) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
. # # # .
|
||||||
|
. # # # .
|
||||||
|
. # # # .
|
||||||
|
. . . . .
|
||||||
|
`)
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 4: Suddenly scissors
|
||||||
|
|
||||||
|
Add a ``show leds`` block with a picture of scissors to the ``else`` part:
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
input.onGesture(Gesture.Shake, () => {
|
||||||
|
let item = Math.random(3)
|
||||||
|
if (item == 0) {
|
||||||
|
basic.showLeds(`
|
||||||
|
# # # # #
|
||||||
|
# . . . #
|
||||||
|
# . . . #
|
||||||
|
# . . . #
|
||||||
|
# # # # #
|
||||||
|
`)
|
||||||
|
|
||||||
|
} else if (item == 1) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
. # # # .
|
||||||
|
. # # # .
|
||||||
|
. # # # .
|
||||||
|
. . . . .
|
||||||
|
`)
|
||||||
|
} else {
|
||||||
|
basic.showLeds(`
|
||||||
|
# # . . #
|
||||||
|
# # . # .
|
||||||
|
. . # . .
|
||||||
|
# # . # .
|
||||||
|
# # . . #
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### ~hint
|
||||||
|
|
||||||
|
You don't need to check if `item` is `2` because `2` is the only number left out of `0`, `1`, and `2`.
|
||||||
|
That's why you can use an ``else`` instead of an ``else if``.
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
Your game is ready!
|
||||||
|
|
||||||
|
Click **Compile** to move your program to the BBC micro:bit!
|
||||||
|
|
||||||
|
Have fun!
|
||||||
|
|
||||||
|
## Step 5: Are you the greatest?
|
||||||
|
|
||||||
|
Here is a way you can make your Rock Paper Scissors game better.
|
||||||
|
When button ``A`` is pressed,
|
||||||
|
the micro:bit will add `1` to your score.
|
||||||
|
|
||||||
|
Open the ``Game`` drawer, and then add the block ``change score by 1`` to your program,
|
||||||
|
like this:
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
input.onButtonPressed(Button.A, () => {
|
||||||
|
game.addScore(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 6: Prove you're the greatest!
|
||||||
|
|
||||||
|
After your micro:bit can add `1` to the score, show how many wins you have.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
input.onButtonPressed(Button.A, () => {
|
||||||
|
game.addScore(1)
|
||||||
|
basic.showString("WINS:")
|
||||||
|
basic.showNumber(game.score())
|
||||||
|
})
|
||||||
|
```
|
||||||
|
## Step 7: Staying honest
|
||||||
|
|
||||||
|
Success! Your micro:bit can track wins!
|
||||||
|
But what about losses?
|
||||||
|
Use the ``Game`` drawer to subtract `1` from your score when you press button `B`.
|
||||||
|
|
||||||
|
Here are all the blocks you will need:
|
||||||
|
|
||||||
|
```shuffle
|
||||||
|
input.onButtonPressed(Button.B, () => {
|
||||||
|
game.addScore(-1)
|
||||||
|
basic.showString("LOSSES:")
|
||||||
|
basic.showNumber(game.score())
|
||||||
|
})
|
||||||
|
```
|
||||||
|
Click **Compile** to move your program to the BBC micro:bit!
|
||||||
|
|
||||||
|
## Your turn!
|
||||||
|
|
||||||
|
How else can you make your game better?
|
||||||
|
Ever hear of [Rock Paper Scissors Spock Lizard](http://www.samkass.com/theories/RPSSL.html)?
|
||||||
|
@ -71,4 +71,4 @@
|
|||||||
|
|
||||||
### @section full
|
### @section full
|
||||||
|
|
||||||
The lessons promote computational thinking and computer science literacy[ read more...](/lessons/teach)
|
The lessons promote computational thinking and computer science literacy.
|
@ -139,7 +139,7 @@ You have two options to Analyze Data:
|
|||||||
|
|
||||||
Click or tap Download data
|
Click or tap Download data
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 13.
|
## 13.
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ You have two options to Analyze Data:
|
|||||||
|
|
||||||
Click or tap Download data
|
Click or tap Download data
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 12.
|
## 12.
|
||||||
|
|
||||||
|
@ -37,8 +37,11 @@ In this project, you will build a Rock Paper Scissors game with the BBC micro:bi
|
|||||||
You can play the game with a friend who has it on a micro:bit.
|
You can play the game with a friend who has it on a micro:bit.
|
||||||
You can also play it with friends who are just using their hands.
|
You can also play it with friends who are just using their hands.
|
||||||
|
|
||||||
|
## [START PROJECT](/#follow:/projects/rock-paper-scissors)
|
||||||
|
|
||||||
### ~
|
### ~
|
||||||
|
|
||||||
|
|
||||||
## Materials needed
|
## Materials needed
|
||||||
|
|
||||||
* Your BBC micro:bit -- that's it!
|
* Your BBC micro:bit -- that's it!
|
||||||
|
@ -1,16 +1,6 @@
|
|||||||
# Move
|
# Move
|
||||||
|
|
||||||
The game library
|
Sprite move by a certain number of LEDs
|
||||||
|
|
||||||
### Move
|
|
||||||
|
|
||||||
Sprite move by a certain number
|
|
||||||
|
|
||||||
## Block Editor
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## KindScript
|
|
||||||
|
|
||||||
```
|
```
|
||||||
export function move(_this: micro_bitSprites.LedSprite, leds: number)
|
export function move(_this: micro_bitSprites.LedSprite, leds: number)
|
||||||
|
@ -1,19 +1,5 @@
|
|||||||
# Position
|
# Position
|
||||||
|
|
||||||
The game library
|
|
||||||
|
|
||||||
### Create sprite
|
|
||||||
|
|
||||||
Reports the x or y position of a sprite on the LED screen
|
|
||||||
|
|
||||||
## Block Editor
|
|
||||||
|
|
||||||
Reports the x position of a sprite on the LED screen
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## KindScript
|
|
||||||
|
|
||||||
Reports the x position of a sprite on the LED screen
|
Reports the x position of a sprite on the LED screen
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -1,31 +1,7 @@
|
|||||||
# Reports
|
# Reports
|
||||||
|
|
||||||
The game library
|
|
||||||
|
|
||||||
### Reports
|
|
||||||
|
|
||||||
Reports the x or y position, the current direction of a sprite, or the brightness of a sprite on the LED screen
|
Reports the x or y position, the current direction of a sprite, or the brightness of a sprite on the LED screen
|
||||||
|
|
||||||
## Block Editor
|
|
||||||
|
|
||||||
Reports the x position of a sprite on the LED screen
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
Reports the y position of a sprite on the LED screen
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
Reports the brightness of a sprite on the LED screen
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
Reports the direction of a sprite on the LED screen
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## KindScript
|
|
||||||
|
|
||||||
Reports the x position of a sprite on the LED screen
|
Reports the x position of a sprite on the LED screen
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -1,13 +1,5 @@
|
|||||||
# Start Countdown
|
# Start Countdown
|
||||||
|
|
||||||
The game library supports simple single-player time-based games. The general goal of a game will be to achieve a top score before time runs out of time.
|
|
||||||
|
|
||||||
## Block Editor
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## KindScript
|
|
||||||
|
|
||||||
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
|
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -1,17 +1,5 @@
|
|||||||
# Touching
|
# Touching
|
||||||
|
|
||||||
The game library
|
|
||||||
|
|
||||||
### Touching
|
|
||||||
|
|
||||||
Reports true if sprite is touching specified sprite
|
|
||||||
|
|
||||||
## Block Editor
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## KindScript
|
|
||||||
|
|
||||||
Reports true if sprite is touching specified sprite
|
Reports true if sprite is touching specified sprite
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -1,17 +1,5 @@
|
|||||||
# Turn
|
# Turn
|
||||||
|
|
||||||
The game library
|
|
||||||
|
|
||||||
Rotates a sprite to the right by a certain number of degrees
|
|
||||||
|
|
||||||
## Block Editor
|
|
||||||
|
|
||||||
Rotates a sprite to the right by a certain number of degrees
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## KindScript
|
|
||||||
|
|
||||||
Rotates a sprite to the right by a certain number of degrees
|
Rotates a sprite to the right by a certain number of degrees
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
# Change Tempo By
|
# Change Tempo By
|
||||||
|
|
||||||
Change the tempo by the specified amount
|
Makes the [tempo](/reference/music/tempo) (speed of a piece of music)
|
||||||
|
faster or slower by the amount you say.
|
||||||
|
|
||||||
## Simulator
|
## Simulator
|
||||||
|
|
||||||
Simulation of this function is available in many, but not all browsers.
|
This function only works on the micro:bit and in some browsers.
|
||||||
|
|
||||||
```sig
|
```sig
|
||||||
music.changeTempoBy(20)
|
music.changeTempoBy(20)
|
||||||
@ -12,7 +13,21 @@ music.changeTempoBy(20)
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
* `bpm` : [Number](/reference/types/number) - change the tempo by beats per minute
|
* a [number](/reference/types/number) that says how much to change the bpm (beats per minute, or number of beats in a minute of the music that the micro:bit is playing).
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
This program makes the music faster by 12 bpm.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
music.changeTempoBy(12)
|
||||||
|
```
|
||||||
|
|
||||||
|
This program makes the music _slower_ by 12 bpm.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
music.changeTempoBy(-12)
|
||||||
|
```
|
||||||
|
|
||||||
### See also
|
### See also
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
# Rest
|
# Rest
|
||||||
|
|
||||||
Rests (plays nothing) for a specified time through pin PO.
|
Rest (play no sound) through pin `PO` for the amount of time you say.
|
||||||
|
|
||||||
## Simulator
|
## Simulator
|
||||||
|
|
||||||
Simulation of this function is available in many, but not all browsers.
|
This function only works on the micro:bit and in some browsers.
|
||||||
|
|
||||||
```sig
|
```sig
|
||||||
music.rest(400)
|
music.rest(400)
|
||||||
@ -12,7 +12,7 @@ music.rest(400)
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
* `ms`: [Number](/reference/types/number) - the duration of the rest (milliseconds)
|
* a [number](/reference/types/number) saying how many milliseconds the micro:bit should rest. One second is 1000 milliseconds.
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
# Ring Tone
|
# Ring Tone
|
||||||
|
|
||||||
Play a continuous tone through pin P0.
|
Play a musical tone through pin `P0` with the pitch as high or low as you say.
|
||||||
|
The tone will keep playing until you tell it not to.
|
||||||
|
|
||||||
## Simulator
|
## Simulator
|
||||||
|
|
||||||
Simulation of this function is available in many, but not all browsers.
|
This function only works on the micro:bit and in some browsers.
|
||||||
|
|
||||||
```sig
|
```sig
|
||||||
music.ringTone(440)
|
music.ringTone(440)
|
||||||
@ -12,11 +13,18 @@ music.ringTone(440)
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
* `frequency` : [Number](/reference/types/number) - Plays a tone in (Hz)
|
* a [number](/reference/types/number) that says the tone's
|
||||||
|
**frequency** (how high-pitched or low-pitched the tone is). This
|
||||||
|
number is in **Hz** (**Hertz**), which is a measurement of frequency
|
||||||
|
or pitch.
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
Play a sound based on the tile of the device
|
This program checks the **accelerometer** for the micro:bit's
|
||||||
|
**acceleration** (how much the micro:bit is speeding up or slowing
|
||||||
|
down). Then it uses that acceleration to make a tone. If the micro:bit
|
||||||
|
speeds up, the tone's pitch gets higher, and if it slows down, the
|
||||||
|
tone's pitch gets lower. It's fun -- try it!
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
basic.forever(() => {
|
basic.forever(() => {
|
||||||
@ -26,5 +34,6 @@ basic.forever(() => {
|
|||||||
|
|
||||||
### See also
|
### See also
|
||||||
|
|
||||||
[rest](/reference/music/rest), [play tone](/reference/music/play-tone) , [tempo](/reference/music/tempo), [set tempo](/reference/music/set-tempo), [change tempo by](/reference/music/change-tempo-by)
|
[rest](/reference/music/rest), [play tone](/reference/music/play-tone),
|
||||||
|
[tempo](/reference/music/tempo), [set tempo](/reference/music/set-tempo),
|
||||||
|
[change tempo by](/reference/music/change-tempo-by)
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
# Set Tempo
|
# Set Tempo
|
||||||
|
|
||||||
Sets the tempo to the specified amount
|
Makes the tempo (speed of a piece of music) as fast or slow as you say.
|
||||||
|
|
||||||
```sig
|
```sig
|
||||||
music.setTempo(60)
|
music.setTempo(60)
|
||||||
```
|
```
|
||||||
|
## Simulator
|
||||||
|
|
||||||
|
This function only works on the micro:bit and in some browsers.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
* Returns : [Number](/reference/types/number) - sets the tempo in beats per minute
|
* a [number](/reference/types/number) that means the bpm you want (beats per minute, or number of beats in a minute of the music that the micro:bit is playing).
|
||||||
|
|
||||||
### See also
|
### See also
|
||||||
|
|
||||||
|
@ -1,13 +1,19 @@
|
|||||||
# On Data Received
|
# On Data Received
|
||||||
|
|
||||||
Registers code to run when a packet is received over ``radio``.
|
Run part of a program when the micro:bit receives a
|
||||||
|
[number](/reference/types/number) or [string](/reference/types/string) over ``radio``.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
* body - is an action
|
* the part of the program to run when the micro:bit receives information over ``radio``.
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
This program keeps sending numbers that says how fast the micro:bit is
|
||||||
|
slowing down or speeding up. It also receives numbers for the same
|
||||||
|
thing from nearby micro:bits. It shows these numbers as a
|
||||||
|
[bar graph](/reference/led/plot-bar-graph).
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
basic.forever(() => {
|
basic.forever(() => {
|
||||||
radio.sendNumber(input.acceleration(Dimension.X));
|
radio.sendNumber(input.acceleration(Dimension.X));
|
||||||
@ -19,5 +25,6 @@ radio.onDataReceived(() => {
|
|||||||
|
|
||||||
### See also
|
### See also
|
||||||
|
|
||||||
[receive number](/reference/radio/receive-number), [send number](/reference/radio/send-number), [set group](/reference/radio/set-group)
|
[receive number](/reference/radio/receive-number),
|
||||||
|
[send number](/reference/radio/send-number), [set group](/reference/radio/set-group)
|
||||||
|
|
||||||
|
@ -1,33 +1,27 @@
|
|||||||
# Set Transmit Power
|
# Set Transmit Power
|
||||||
|
|
||||||
Sets the transmitter power for ``radio`` communications.
|
Make the ``radio`` signal of the micro:bit stronger or weaker.
|
||||||
The power can be set to a value between 0 (-30dbm) and 7 (+4dbm).
|
It can be as weak as `0` and as strong as `7`.
|
||||||
|
|
||||||
|
The scientific name for the strength of the ``radio`` signal is
|
||||||
|
**dBm**, or **decibel-milliwatts**. A signal strength of `0`
|
||||||
|
can be measured as -30 dBm, and a strength of `7` can be
|
||||||
|
measured as +4 dBm.
|
||||||
|
|
||||||
## Range
|
## Range
|
||||||
|
|
||||||
At power level 7, in an open area without significant interference (coming from WiFi networks or other devices operating on the 2.4 GHz range), you can get a **range of over 70m**.
|
If your micro:bit is sending with a strength of `7`, and you are in
|
||||||
|
an open area without many other computers around, the micro:bit signal
|
||||||
Indoors (or with additional interference), range will be significantly reduced.
|
can reach as far as 70 meters (about 230 feet).
|
||||||
|
|
||||||
## Important Security Consideration
|
|
||||||
|
|
||||||
The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits.
|
|
||||||
|
|
||||||
This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place.
|
|
||||||
|
|
||||||
For serious applications, BLE should be considered a substantially more secure alternative.
|
|
||||||
|
|
||||||
```sig
|
|
||||||
radio.setTransmitPower(1)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
* ``power`` -- a [number](/reference/types/number) between ``0`` and ``7``.
|
* a [number](/reference/types/number) between ``0`` and ``7`` that
|
||||||
|
means how strong the signal is.
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
Sets the transmitter power to full power at 7.
|
This program makes the ``radio`` send at full strength.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
radio.setTransmitPower(7)
|
radio.setTransmitPower(7)
|
||||||
|
BIN
docs/static/seismograph9.png
vendored
BIN
docs/static/seismograph9.png
vendored
Binary file not shown.
Before Width: | Height: | Size: 26 KiB |
BIN
docs/static/uploader/screenshot.png
vendored
Normal file
BIN
docs/static/uploader/screenshot.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
BIN
docs/static/uploader/tooltip.png
vendored
Normal file
BIN
docs/static/uploader/tooltip.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.3 KiB |
43
docs/uploader.md
Normal file
43
docs/uploader.md
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# Uploader
|
||||||
|
|
||||||
|
### ~avatar avatar
|
||||||
|
|
||||||
|
The Uploader **automatically** deploys .hex files to all BBC micro:bit connected to your computer.
|
||||||
|
|
||||||
|
## [DOWNLOAD](https://www.pxt.io/microbit-uploader.zip)
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
### ~column
|
||||||
|
|
||||||
|
### Works with any browser!
|
||||||
|
|
||||||
|
The uploader monitors your Downloads folder looking for any .hex file being download.
|
||||||
|
When it detects a new .hex file, the uploader tries to copy it to all connected BBC micro:bits (it copies it to the MICROBIT drives).
|
||||||
|
That's it!
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
### ~column
|
||||||
|
|
||||||
|
### System Requirements
|
||||||
|
|
||||||
|
* Windows XP or later
|
||||||
|
* .NET runtime 2.0 or higher
|
||||||
|
* Browser: this application will work for any web browser that is supported by the BBC micro:bit
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
### ~column
|
||||||
|
|
||||||
|
### Installation Instructions
|
||||||
|
|
||||||
|
* Download the [Microsoft.Uploader.Microbit.zip](/microbit-uploader.zip) file to your local computer.
|
||||||
|
* Unzip the .zip file to your desktop.
|
||||||
|
* Launch the Microsoft.Uploader.exe file before working on your BBC micro:bit.
|
||||||
|
|
||||||
|
### ~
|
@ -129,7 +129,7 @@ namespace devices {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a ``camera`` command to the parent device.
|
* Sends a ``camera`` command to the parent device.
|
||||||
* @param event TODO
|
* @param event event description
|
||||||
*/
|
*/
|
||||||
//% weight=30 help=devices/tell-camera-to
|
//% weight=30 help=devices/tell-camera-to
|
||||||
//% blockId=devices_camera icon="\uf030" block="tell camera to|%property" blockGap=8
|
//% blockId=devices_camera icon="\uf030" block="tell camera to|%property" blockGap=8
|
||||||
@ -139,7 +139,7 @@ namespace devices {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a ``remote control`` command to the parent device.
|
* Sends a ``remote control`` command to the parent device.
|
||||||
* @param event TODO
|
* @param event event description
|
||||||
*/
|
*/
|
||||||
//% weight=29 help=devices/tell-remote-control-to
|
//% weight=29 help=devices/tell-remote-control-to
|
||||||
//% blockId=devices_remote_control block="tell remote control to|%property" blockGap=14 icon="\uf144"
|
//% blockId=devices_remote_control block="tell remote control to|%property" blockGap=14 icon="\uf144"
|
||||||
@ -149,7 +149,7 @@ namespace devices {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends an ``alert`` command to the parent device.
|
* Sends an ``alert`` command to the parent device.
|
||||||
* @param event TODO
|
* @param event event description
|
||||||
*/
|
*/
|
||||||
//% weight=27 help=devices/raise-alert-to
|
//% weight=27 help=devices/raise-alert-to
|
||||||
//% blockId=devices_alert block="raise alert to|%property" icon="\uf0f3"
|
//% blockId=devices_alert block="raise alert to|%property" icon="\uf0f3"
|
||||||
@ -159,19 +159,19 @@ namespace devices {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers code to run when the device notifies about a particular event.
|
* Registers code to run when the device notifies about a particular event.
|
||||||
* @param event TODO
|
* @param event event description
|
||||||
* @param body TODO
|
* @param body code handler when event is triggered
|
||||||
*/
|
*/
|
||||||
//% help=devices/on-notified weight=26
|
//% help=devices/on-notified weight=26
|
||||||
//% blockId=devices_device_info_event block="on notified" icon="\uf10a"
|
//% blockId=devices_device_info_event block="on notified|%event" icon="\uf10a"
|
||||||
void onNotified(MesDeviceInfo event, Action body) {
|
void onNotified(MesDeviceInfo event, Action body) {
|
||||||
registerWithDal(MES_DEVICE_INFO_ID, (int)event, body);
|
registerWithDal(MES_DEVICE_INFO_ID, (int)event, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register code to run when the micro:bit receives a command from the paired gamepad.
|
* Register code to run when the micro:bit receives a command from the paired gamepad.
|
||||||
* @param name TODO
|
* @param name button name
|
||||||
* @param body TODO
|
* @param body code to run when button is pressed
|
||||||
*/
|
*/
|
||||||
//% help=devices/on-gamepad-button weight=40
|
//% help=devices/on-gamepad-button weight=40
|
||||||
//% weight=25
|
//% weight=25
|
||||||
@ -188,7 +188,7 @@ namespace devices {
|
|||||||
static void initSignalStrength() {
|
static void initSignalStrength() {
|
||||||
if (_signalStrength < 0) {
|
if (_signalStrength < 0) {
|
||||||
_signalStrength = 0;
|
_signalStrength = 0;
|
||||||
uBit.MessageBus.listen(MES_SIGNAL_STRENGTH_ID, MICROBIT_EVT_ANY, signalStrengthHandler);
|
uBit.messageBus.listen(MES_SIGNAL_STRENGTH_ID, MICROBIT_EVT_ANY, signalStrengthHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,5 +20,5 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"installedVersion": "zakvul"
|
"installedVersion": "ljipgq"
|
||||||
}
|
}
|
||||||
|
16
libs/microbit-devices/shims.d.ts
vendored
16
libs/microbit-devices/shims.d.ts
vendored
@ -7,7 +7,7 @@ declare namespace devices {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a ``camera`` command to the parent device.
|
* Sends a ``camera`` command to the parent device.
|
||||||
* @param event TODO
|
* @param event event description
|
||||||
*/
|
*/
|
||||||
//% weight=30 help=devices/tell-camera-to
|
//% weight=30 help=devices/tell-camera-to
|
||||||
//% blockId=devices_camera icon="\uf030" block="tell camera to|%property" blockGap=8 shim=devices::tellCameraTo
|
//% blockId=devices_camera icon="\uf030" block="tell camera to|%property" blockGap=8 shim=devices::tellCameraTo
|
||||||
@ -15,7 +15,7 @@ declare namespace devices {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a ``remote control`` command to the parent device.
|
* Sends a ``remote control`` command to the parent device.
|
||||||
* @param event TODO
|
* @param event event description
|
||||||
*/
|
*/
|
||||||
//% weight=29 help=devices/tell-remote-control-to
|
//% weight=29 help=devices/tell-remote-control-to
|
||||||
//% blockId=devices_remote_control block="tell remote control to|%property" blockGap=14 icon="\uf144" shim=devices::tellRemoteControlTo
|
//% blockId=devices_remote_control block="tell remote control to|%property" blockGap=14 icon="\uf144" shim=devices::tellRemoteControlTo
|
||||||
@ -23,7 +23,7 @@ declare namespace devices {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends an ``alert`` command to the parent device.
|
* Sends an ``alert`` command to the parent device.
|
||||||
* @param event TODO
|
* @param event event description
|
||||||
*/
|
*/
|
||||||
//% weight=27 help=devices/raise-alert-to
|
//% weight=27 help=devices/raise-alert-to
|
||||||
//% blockId=devices_alert block="raise alert to|%property" icon="\uf0f3" shim=devices::raiseAlertTo
|
//% blockId=devices_alert block="raise alert to|%property" icon="\uf0f3" shim=devices::raiseAlertTo
|
||||||
@ -31,17 +31,17 @@ declare namespace devices {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers code to run when the device notifies about a particular event.
|
* Registers code to run when the device notifies about a particular event.
|
||||||
* @param event TODO
|
* @param event event description
|
||||||
* @param body TODO
|
* @param body code handler when event is triggered
|
||||||
*/
|
*/
|
||||||
//% help=devices/on-notified weight=26
|
//% help=devices/on-notified weight=26
|
||||||
//% blockId=devices_device_info_event block="on notified" icon="\uf10a" shim=devices::onNotified
|
//% blockId=devices_device_info_event block="on notified|%event" icon="\uf10a" shim=devices::onNotified
|
||||||
function onNotified(event: MesDeviceInfo, body: () => void): void;
|
function onNotified(event: MesDeviceInfo, body: () => void): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register code to run when the micro:bit receives a command from the paired gamepad.
|
* Register code to run when the micro:bit receives a command from the paired gamepad.
|
||||||
* @param name TODO
|
* @param name button name
|
||||||
* @param body TODO
|
* @param body code to run when button is pressed
|
||||||
*/
|
*/
|
||||||
//% help=devices/on-gamepad-button weight=40
|
//% help=devices/on-gamepad-button weight=40
|
||||||
//% weight=25
|
//% weight=25
|
||||||
|
5
libs/microbit/dal.d.ts
vendored
5
libs/microbit/dal.d.ts
vendored
@ -223,12 +223,13 @@ declare const enum DAL {
|
|||||||
MICROBIT_ACCELEROMETER_REST_TOLERANCE = 200,
|
MICROBIT_ACCELEROMETER_REST_TOLERANCE = 200,
|
||||||
MICROBIT_ACCELEROMETER_TILT_TOLERANCE = 200,
|
MICROBIT_ACCELEROMETER_TILT_TOLERANCE = 200,
|
||||||
MICROBIT_ACCELEROMETER_FREEFALL_TOLERANCE = 400,
|
MICROBIT_ACCELEROMETER_FREEFALL_TOLERANCE = 400,
|
||||||
MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE = 1000,
|
MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE = 400,
|
||||||
MICROBIT_ACCELEROMETER_3G_TOLERANCE = 3072,
|
MICROBIT_ACCELEROMETER_3G_TOLERANCE = 3072,
|
||||||
MICROBIT_ACCELEROMETER_6G_TOLERANCE = 6144,
|
MICROBIT_ACCELEROMETER_6G_TOLERANCE = 6144,
|
||||||
MICROBIT_ACCELEROMETER_8G_TOLERANCE = 8192,
|
MICROBIT_ACCELEROMETER_8G_TOLERANCE = 8192,
|
||||||
MICROBIT_ACCELEROMETER_GESTURE_DAMPING = 10,
|
MICROBIT_ACCELEROMETER_GESTURE_DAMPING = 5,
|
||||||
MICROBIT_ACCELEROMETER_SHAKE_DAMPING = 10,
|
MICROBIT_ACCELEROMETER_SHAKE_DAMPING = 10,
|
||||||
|
MICROBIT_ACCELEROMETER_SHAKE_RTX = 30,
|
||||||
MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD = 4,
|
MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD = 4,
|
||||||
// built/yt/yotta_modules/microbit-dal/inc//drivers/MicroBitButton.h
|
// built/yt/yotta_modules/microbit-dal/inc//drivers/MicroBitButton.h
|
||||||
MICROBIT_BUTTON_EVT_DOWN = 1,
|
MICROBIT_BUTTON_EVT_DOWN = 1,
|
||||||
|
10
libs/microbit/enums.d.ts
vendored
10
libs/microbit/enums.d.ts
vendored
@ -278,6 +278,16 @@ declare namespace led {
|
|||||||
High = 4, // MICROBIT_PIN_EVT_PULSE_HI
|
High = 4, // MICROBIT_PIN_EVT_PULSE_HI
|
||||||
Low = 5, // MICROBIT_PIN_EVT_PULSE_LO
|
Low = 5, // MICROBIT_PIN_EVT_PULSE_LO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
declare enum PinPullMode {
|
||||||
|
//% block="down"
|
||||||
|
PullDown = 0,
|
||||||
|
//% block="up"
|
||||||
|
PullUp = 1,
|
||||||
|
//% block="none"
|
||||||
|
PullNone = 2,
|
||||||
|
}
|
||||||
declare namespace pins {
|
declare namespace pins {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,15 @@ enum class PulseValue {
|
|||||||
Low = MICROBIT_PIN_EVT_PULSE_LO
|
Low = MICROBIT_PIN_EVT_PULSE_LO
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class PinPullMode {
|
||||||
|
//% block="down"
|
||||||
|
PullDown = 0,
|
||||||
|
//% block="up"
|
||||||
|
PullUp = 1,
|
||||||
|
//% block="none"
|
||||||
|
PullNone = 2
|
||||||
|
};
|
||||||
|
|
||||||
MicroBitPin *getPin(int id) {
|
MicroBitPin *getPin(int id) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case MICROBIT_ID_IO_P0: return &uBit.io.P0;
|
case MICROBIT_ID_IO_P0: return &uBit.io.P0;
|
||||||
@ -214,6 +223,22 @@ namespace pins {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the pull of this pin.
|
||||||
|
* @param name pin to set the pull mode on
|
||||||
|
* @param pull one of the mbed pull configurations: PullUp, PullDown, PullNone
|
||||||
|
*/
|
||||||
|
//% help=pins/digital-set-pull weight=3
|
||||||
|
//% blockId=device_set_pull block="set pull|pin %pin|to %pull"
|
||||||
|
void setPull(DigitalPin name, PinPullMode pull) {
|
||||||
|
PinMode m = pull == PinPullMode::PullDown
|
||||||
|
? PinMode::PullDown
|
||||||
|
: pull == PinPullMode::PullUp ? PinMode::PullUp
|
||||||
|
: PinMode::PullNone;
|
||||||
|
PINOP(setPull(m));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new zero-initialized buffer.
|
* Create a new zero-initialized buffer.
|
||||||
* @param size number of bytes in the buffer
|
* @param size number of bytes in the buffer
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
"serial.cpp",
|
"serial.cpp",
|
||||||
"serial.ts",
|
"serial.ts",
|
||||||
"buffer.cpp",
|
"buffer.cpp",
|
||||||
"_locales/fr/strings.json"
|
"_locales/fr/microbit-strings.json"
|
||||||
],
|
],
|
||||||
"public": true,
|
"public": true,
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
|
9
libs/microbit/shims.d.ts
vendored
9
libs/microbit/shims.d.ts
vendored
@ -535,6 +535,15 @@ declare namespace pins {
|
|||||||
//% help=pins/analog-pitch weight=14 async shim=pins::analogPitch
|
//% help=pins/analog-pitch weight=14 async shim=pins::analogPitch
|
||||||
function analogPitch(frequency: number, ms: number): void;
|
function analogPitch(frequency: number, ms: number): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the pull of this pin.
|
||||||
|
* @param name pin to set the pull mode on
|
||||||
|
* @param pull one of the mbed pull configurations: PullUp, PullDown, PullNone
|
||||||
|
*/
|
||||||
|
//% help=pins/digital-set-pull weight=3
|
||||||
|
//% blockId=device_set_pull block="set pull|pin %pin|to %pull" shim=pins::setPull
|
||||||
|
function setPull(name: DigitalPin, pull: PinPullMode): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new zero-initialized buffer.
|
* Create a new zero-initialized buffer.
|
||||||
* @param size number of bytes in the buffer
|
* @param size number of bytes in the buffer
|
||||||
|
@ -9,9 +9,13 @@
|
|||||||
"testFiles": [
|
"testFiles": [
|
||||||
"neotest.ts"
|
"neotest.ts"
|
||||||
],
|
],
|
||||||
"microbit": {
|
"yotta": {
|
||||||
"config": {
|
"config": {
|
||||||
"MICROBIT_BLE_ENABLED": "0"
|
"microbit-dal": {
|
||||||
|
"bluetooth": {
|
||||||
|
"enabled": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"public": true,
|
"public": true,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pxt-microbit",
|
"name": "pxt-microbit",
|
||||||
"version": "0.2.142",
|
"version": "0.2.155",
|
||||||
"description": "BBC micro:bit target for PXT",
|
"description": "BBC micro:bit target for PXT",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"JavaScript",
|
"JavaScript",
|
||||||
@ -29,6 +29,6 @@
|
|||||||
"typescript": "^1.8.7"
|
"typescript": "^1.8.7"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pxt-core": "0.2.154"
|
"pxt-core": "0.2.167"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,9 @@
|
|||||||
"corepkg": "microbit",
|
"corepkg": "microbit",
|
||||||
"bundleddirs": [
|
"bundleddirs": [
|
||||||
"libs/microbit",
|
"libs/microbit",
|
||||||
"libs/microbit-radio"
|
"libs/microbit-radio",
|
||||||
|
"libs/microbit-devices",
|
||||||
|
"libs/neopixel"
|
||||||
],
|
],
|
||||||
"cloud": {
|
"cloud": {
|
||||||
"workspace": false,
|
"workspace": false,
|
||||||
@ -50,7 +52,9 @@
|
|||||||
"compile": {
|
"compile": {
|
||||||
"isNative": false,
|
"isNative": false,
|
||||||
"hasHex": true,
|
"hasHex": true,
|
||||||
"deployDrives": "^MICROBIT"
|
"deployDrives": "^MICROBIT",
|
||||||
|
"driveName": "MICROBIT",
|
||||||
|
"hexMimeType": "application/x-microbit-hex"
|
||||||
},
|
},
|
||||||
"runtime": {
|
"runtime": {
|
||||||
"mathBlocks": true,
|
"mathBlocks": true,
|
||||||
@ -66,7 +70,7 @@
|
|||||||
"yottaTarget": "bbc-microbit-classic-gcc",
|
"yottaTarget": "bbc-microbit-classic-gcc",
|
||||||
"yottaCorePackage": "pxt-microbit-core",
|
"yottaCorePackage": "pxt-microbit-core",
|
||||||
"githubCorePackage": "microsoft/pxt-microbit-core",
|
"githubCorePackage": "microsoft/pxt-microbit-core",
|
||||||
"gittag": "v0.1.10",
|
"gittag": "v0.1.11",
|
||||||
"serviceId": "ws"
|
"serviceId": "ws"
|
||||||
},
|
},
|
||||||
"serial": {
|
"serial": {
|
||||||
@ -84,10 +88,9 @@
|
|||||||
"organizationLogo": "./static/Microsoft-logo_rgb_c-gray.png",
|
"organizationLogo": "./static/Microsoft-logo_rgb_c-gray.png",
|
||||||
"homeUrl": "https://m.pxt.io/",
|
"homeUrl": "https://m.pxt.io/",
|
||||||
"embedUrl": "https://m.pxt.io/",
|
"embedUrl": "https://m.pxt.io/",
|
||||||
"koduUrl": "https://www.kodugamelab.com/bbc-microbit/",
|
|
||||||
"privacyUrl": "https://go.microsoft.com/fwlink/?LinkId=521839",
|
"privacyUrl": "https://go.microsoft.com/fwlink/?LinkId=521839",
|
||||||
"termsOfUseUrl": "https://go.microsoft.com/fwlink/?LinkID=206977",
|
"termsOfUseUrl": "https://go.microsoft.com/fwlink/?LinkID=206977",
|
||||||
"visualStudioCode": true,
|
"boardName": "BBC micro:bit",
|
||||||
"docMenu": [
|
"docMenu": [
|
||||||
{
|
{
|
||||||
"name": "About",
|
"name": "About",
|
||||||
@ -104,10 +107,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Lessons",
|
"name": "Lessons",
|
||||||
"path": "/lessons"
|
"path": "/lessons"
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Device",
|
|
||||||
"path": "/device"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"sideDoc": "getting-started"
|
"sideDoc": "getting-started"
|
||||||
|
@ -524,29 +524,35 @@ namespace pxsim.pins {
|
|||||||
export function digitalReadPin(pinId: number): number {
|
export function digitalReadPin(pinId: number): number {
|
||||||
let pin = getPin(pinId);
|
let pin = getPin(pinId);
|
||||||
if (!pin) return;
|
if (!pin) return;
|
||||||
pin.mode = PinMode.Digital | PinMode.Input;
|
pin.mode = PinFlags.Digital | PinFlags.Input;
|
||||||
return pin.value > 100 ? 1 : 0;
|
return pin.value > 100 ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function digitalWritePin(pinId: number, value: number) {
|
export function digitalWritePin(pinId: number, value: number) {
|
||||||
let pin = getPin(pinId);
|
let pin = getPin(pinId);
|
||||||
if (!pin) return;
|
if (!pin) return;
|
||||||
pin.mode = PinMode.Digital | PinMode.Output;
|
pin.mode = PinFlags.Digital | PinFlags.Output;
|
||||||
pin.value = value > 0 ? 1023 : 0;
|
pin.value = value > 0 ? 1023 : 0;
|
||||||
runtime.queueDisplayUpdate();
|
runtime.queueDisplayUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setPull(pinId: number, pull: number) {
|
||||||
|
let pin = getPin(pinId);
|
||||||
|
if (!pin) return;
|
||||||
|
pin.pull = pull;
|
||||||
|
}
|
||||||
|
|
||||||
export function analogReadPin(pinId: number): number {
|
export function analogReadPin(pinId: number): number {
|
||||||
let pin = getPin(pinId);
|
let pin = getPin(pinId);
|
||||||
if (!pin) return;
|
if (!pin) return;
|
||||||
pin.mode = PinMode.Analog | PinMode.Input;
|
pin.mode = PinFlags.Analog | PinFlags.Input;
|
||||||
return pin.value || 0;
|
return pin.value || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function analogWritePin(pinId: number, value: number) {
|
export function analogWritePin(pinId: number, value: number) {
|
||||||
let pin = getPin(pinId);
|
let pin = getPin(pinId);
|
||||||
if (!pin) return;
|
if (!pin) return;
|
||||||
pin.mode = PinMode.Analog | PinMode.Output;
|
pin.mode = PinFlags.Analog | PinFlags.Output;
|
||||||
pin.value = value ? 1 : 0;
|
pin.value = value ? 1 : 0;
|
||||||
runtime.queueDisplayUpdate();
|
runtime.queueDisplayUpdate();
|
||||||
}
|
}
|
||||||
@ -554,7 +560,7 @@ namespace pxsim.pins {
|
|||||||
export function analogSetPeriod(pinId: number, micros: number) {
|
export function analogSetPeriod(pinId: number, micros: number) {
|
||||||
let pin = getPin(pinId);
|
let pin = getPin(pinId);
|
||||||
if (!pin) return;
|
if (!pin) return;
|
||||||
pin.mode = PinMode.Analog | PinMode.Output;
|
pin.mode = PinFlags.Analog | PinFlags.Output;
|
||||||
pin.period = micros;
|
pin.period = micros;
|
||||||
runtime.queueDisplayUpdate();
|
runtime.queueDisplayUpdate();
|
||||||
}
|
}
|
||||||
@ -580,7 +586,7 @@ namespace pxsim.pins {
|
|||||||
export function analogPitch(frequency: number, ms: number) {
|
export function analogPitch(frequency: number, ms: number) {
|
||||||
// update analog output
|
// update analog output
|
||||||
let pin = board().pins.filter(pin => !!pin && pin.pitch)[0] || board().pins[0];
|
let pin = board().pins.filter(pin => !!pin && pin.pitch)[0] || board().pins[0];
|
||||||
pin.mode = PinMode.Analog | PinMode.Output;
|
pin.mode = PinFlags.Analog | PinFlags.Output;
|
||||||
if (frequency <= 0) {
|
if (frequency <= 0) {
|
||||||
pin.value = 0;
|
pin.value = 0;
|
||||||
pin.period = 0;
|
pin.period = 0;
|
||||||
@ -598,7 +604,7 @@ namespace pxsim.pins {
|
|||||||
AudioContextManager.stop();
|
AudioContextManager.stop();
|
||||||
pin.value = 0;
|
pin.value = 0;
|
||||||
pin.period = 0;
|
pin.period = 0;
|
||||||
pin.mode = PinMode.Unused;
|
pin.mode = PinFlags.Unused;
|
||||||
runtime.queueDisplayUpdate();
|
runtime.queueDisplayUpdate();
|
||||||
cb()
|
cb()
|
||||||
}, ms);
|
}, ms);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>microbit simulator</title>
|
<title>BBC micro:bit simulator</title>
|
||||||
<style>
|
<style>
|
||||||
html {
|
html {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@ -13,11 +13,10 @@ html {
|
|||||||
|
|
||||||
body {
|
body {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
width:100%;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
-webkit-overflow-scrolling: touch;
|
|
||||||
overflow-scrolling: touch;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<script src="/cdn/bluebird.min.js"></script>
|
<script src="/cdn/bluebird.min.js"></script>
|
||||||
|
@ -183,20 +183,20 @@ namespace pxsim.micro_bit {
|
|||||||
if (!pin) return;
|
if (!pin) return;
|
||||||
let text = this.pinTexts[index];
|
let text = this.pinTexts[index];
|
||||||
let v = "";
|
let v = "";
|
||||||
if (pin.mode & PinMode.Analog) {
|
if (pin.mode & PinFlags.Analog) {
|
||||||
v = Math.floor(100 - (pin.value || 0) / 1023 * 100) + "%";
|
v = Math.floor(100 - (pin.value || 0) / 1023 * 100) + "%";
|
||||||
if (text) text.textContent = (pin.period ? "~" : "") + (pin.value || 0) + "";
|
if (text) text.textContent = (pin.period ? "~" : "") + (pin.value || 0) + "";
|
||||||
}
|
}
|
||||||
else if (pin.mode & PinMode.Digital) {
|
else if (pin.mode & PinFlags.Digital) {
|
||||||
v = pin.value > 0 ? '0%' : '100%';
|
v = pin.value > 0 ? '0%' : '100%';
|
||||||
if (text) text.textContent = pin.value > 0 ? "1" : "0";
|
if (text) text.textContent = pin.value > 0 ? "1" : "0";
|
||||||
}
|
}
|
||||||
else if (pin.mode & PinMode.Touch) {
|
else if (pin.mode & PinFlags.Touch) {
|
||||||
v = pin.touched ? '0%' : '100%';
|
v = pin.touched ? "0%" : "100%";
|
||||||
if (text) text.textContent = "";
|
if (text) text.textContent = "";
|
||||||
} else {
|
} else {
|
||||||
v = '100%';
|
v = "100%";
|
||||||
if (text) text.textContent = '';
|
if (text) text.textContent = "";
|
||||||
}
|
}
|
||||||
if (v) svg.setGradientValue(this.pinGradients[index], v);
|
if (v) svg.setGradientValue(this.pinGradients[index], v);
|
||||||
}
|
}
|
||||||
@ -651,7 +651,7 @@ svg.sim.grayscale {
|
|||||||
let state = this.board;
|
let state = this.board;
|
||||||
let pin = state.pins[index];
|
let pin = state.pins[index];
|
||||||
let svgpin = this.pins[index];
|
let svgpin = this.pins[index];
|
||||||
if (pin.mode & PinMode.Input) {
|
if (pin.mode & PinFlags.Input) {
|
||||||
let cursor = svg.cursorPoint(pt, this.element, ev);
|
let cursor = svg.cursorPoint(pt, this.element, ev);
|
||||||
let v = (400 - cursor.y) / 40 * 1023
|
let v = (400 - cursor.y) / 40 * 1023
|
||||||
pin.value = Math.max(0, Math.min(1023, Math.floor(v)));
|
pin.value = Math.max(0, Math.min(1023, Math.floor(v)));
|
||||||
@ -664,7 +664,7 @@ svg.sim.grayscale {
|
|||||||
let pin = state.pins[index];
|
let pin = state.pins[index];
|
||||||
let svgpin = this.pins[index];
|
let svgpin = this.pins[index];
|
||||||
svg.addClass(svgpin, "touched");
|
svg.addClass(svgpin, "touched");
|
||||||
if (pin.mode & PinMode.Input) {
|
if (pin.mode & PinFlags.Input) {
|
||||||
let cursor = svg.cursorPoint(pt, this.element, ev);
|
let cursor = svg.cursorPoint(pt, this.element, ev);
|
||||||
let v = (400 - cursor.y) / 40 * 1023
|
let v = (400 - cursor.y) / 40 * 1023
|
||||||
pin.value = Math.max(0, Math.min(1023, Math.floor(v)));
|
pin.value = Math.max(0, Math.min(1023, Math.floor(v)));
|
||||||
|
@ -8,7 +8,7 @@ namespace pxsim {
|
|||||||
greyscale
|
greyscale
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum PinMode {
|
export enum PinFlags {
|
||||||
Unused = 0,
|
Unused = 0,
|
||||||
Digital = 0x0001,
|
Digital = 0x0001,
|
||||||
Analog = 0x0002,
|
Analog = 0x0002,
|
||||||
@ -22,11 +22,12 @@ namespace pxsim {
|
|||||||
touched = false;
|
touched = false;
|
||||||
value = 0;
|
value = 0;
|
||||||
period = 0;
|
period = 0;
|
||||||
mode = PinMode.Unused;
|
mode = PinFlags.Unused;
|
||||||
pitch = false;
|
pitch = false;
|
||||||
|
pull = 0; // PullDown
|
||||||
|
|
||||||
isTouched(): boolean {
|
isTouched(): boolean {
|
||||||
this.mode = PinMode.Touch;
|
this.mode = PinFlags.Touch;
|
||||||
return this.touched;
|
return this.touched;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user