Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
742eb7ea2f | ||
|
|
f1904143b6 | ||
|
|
e621252f3b | ||
|
|
3633d39f57 | ||
|
|
21bbf8fc86 | ||
|
|
dd5124f660 | ||
|
|
966ad1f503 | ||
|
|
d94f394d24 | ||
|
|
40ddd896cf | ||
|
|
5a8815c4fc | ||
|
|
9a04eb1790 | ||
|
|
906e2a2fff | ||
|
|
781339026e | ||
|
|
bd23de14e1 | ||
|
|
e6ca366d20 | ||
|
|
e2ce49d94b | ||
|
|
e3b6350785 | ||
|
|
66aba696dc | ||
|
|
45690215dd | ||
|
|
af42dbf30a |
@@ -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
|
||||||
|
|||||||
@@ -188,47 +188,6 @@ input.onGesture(Gesture.Shake, () => {
|
|||||||
```
|
```
|
||||||
Click **Compile** to move your program to the BBC micro:bit!
|
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). Tilting a micro:bit like this
|
|
||||||
is called a **gesture**.
|
|
||||||
|
|
||||||
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 a real
|
|
||||||
micro:bit!
|
|
||||||
|
|
||||||
```shuffle
|
|
||||||
input.onGesture(Gesture.TiltLeft, () => {
|
|
||||||
basic.showLeds(`
|
|
||||||
# # # # #
|
|
||||||
# . . . #
|
|
||||||
# . . . #
|
|
||||||
# . . . #
|
|
||||||
# # # # #`);
|
|
||||||
});
|
|
||||||
input.onGesture(Gesture.LogoDown, () => {
|
|
||||||
basic.showLeds(`
|
|
||||||
. . . . .
|
|
||||||
. # # # .
|
|
||||||
. # # # .
|
|
||||||
. # # # .
|
|
||||||
. . . . .`);
|
|
||||||
});
|
|
||||||
input.onGesture(Gesture.TiltRight, () => {
|
|
||||||
basic.showLeds(`
|
|
||||||
# # . . #
|
|
||||||
# # . # .
|
|
||||||
. . # . .
|
|
||||||
# # . # .
|
|
||||||
# # . . #`);
|
|
||||||
});
|
|
||||||
```
|
|
||||||
Click **Compile** to move your program to the BBC micro:bit!
|
|
||||||
|
|
||||||
### 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
|
||||||
@@ -236,91 +195,129 @@ 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!
|
Click **Compile** to move your program to the BBC micro:bit!
|
||||||
|
|
||||||
### Your turn!
|
## ~hint
|
||||||
|
|
||||||
Use the screen, buttons, gestures, and pins to make your own fun game
|
Try this experiment: find a friend and hold hands. Touch the ``GND``
|
||||||
with the BBC micro:bit! What about some of these?
|
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!
|
||||||
|
|
||||||
* A backpack burglar alarm
|
## ~
|
||||||
* Daily news broadcaster for your class
|
|
||||||
* Animated jewelry
|
|
||||||
* A _complete_ animated cartoon
|
|
||||||
* A calculator
|
|
||||||
* A music box
|
|
||||||
|
|
||||||
These are all things you can make with the BBC micro:bit by itself.
|
## The amazing coin flipper
|
||||||
Just think what you can do if you connect the micro:bit's pins to
|
|
||||||
extra parts like microphones and other **sensors**!
|
### ~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
|
||||||
|
basic.forever(() => {
|
||||||
|
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());
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
When you're done, your coin flipping program should look like this:
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
basic.forever(() => {
|
||||||
|
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!
|
## Let's play Rock Paper Scissors!
|
||||||
|
|
||||||
### ~avatar avatar
|
### ~avatar avatar
|
||||||
|
|
||||||
```sim
|
Build a Rock Paper Scissors game with the BBC micro:bit! You can play
|
||||||
input.onGesture(Gesture.Shake, () => {
|
the game with a friend who has it on a micro:bit. You can also play
|
||||||
let img = Math.random(3)
|
it with friends who are just using their hands. (The game is built
|
||||||
if (img == 0) {
|
like a coin flipper, but with three choices instead of two.)
|
||||||
basic.showLeds(`
|
|
||||||
# # # # #
|
|
||||||
# . . . #
|
|
||||||
# . . . #
|
|
||||||
# . . . #
|
|
||||||
# # # # #
|
|
||||||
`)
|
|
||||||
|
|
||||||
} else if (img == 1) {
|
|
||||||
basic.showLeds(`
|
|
||||||
. . . . .
|
|
||||||
. # # # .
|
|
||||||
. # # # .
|
|
||||||
. # # # .
|
|
||||||
. . . . .
|
|
||||||
`)
|
|
||||||
} else {
|
|
||||||
basic.showLeds(`
|
|
||||||
# # . . #
|
|
||||||
# # . # .
|
|
||||||
. . # . .
|
|
||||||
# # . # .
|
|
||||||
# # . . #
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
```
|
|
||||||
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.
|
|
||||||
|
|
||||||
## [START PROJECT](/#follow:/projects/rock-paper-scissors)
|
|
||||||
|
|
||||||
### ~
|
### ~
|
||||||
|
|
||||||
|
|
||||||
## Materials needed
|
|
||||||
|
|
||||||
* Your BBC micro:bit -- that's it!
|
|
||||||
|
|
||||||
## Step 1: Getting started
|
## Step 1: Getting started
|
||||||
|
|
||||||
We want the micro:bit to choose rock, paper, or scissors when you
|
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
|
shake it. Try creating an ``on shake`` block so when you shake the
|
||||||
micro:bit, it will run part of a program.
|
micro:bit, it will run part of a program.
|
||||||
|
|
||||||
|
Clear up the blocks and add the blocks below.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
input.onGesture(Gesture.Shake, () => {
|
input.onGesture(Gesture.Shake, () => {
|
||||||
|
|
||||||
@@ -328,8 +325,7 @@ input.onGesture(Gesture.Shake, () => {
|
|||||||
```
|
```
|
||||||
|
|
||||||
Next, when you shake the micro:bit, it should pick a random number from `0` to `2`
|
Next, when you shake the micro:bit, it should pick a random number from `0` to `2`
|
||||||
and store it in the variable `weapon`. (This variable is named `weapon` because
|
and store it in the variable `item`.
|
||||||
rock, paper, and scissors are the weapons you use to battle your friends!)
|
|
||||||
|
|
||||||
Add a ``set`` block with a variable. Then add a ``pick random`` block,
|
Add a ``set`` block with a variable. Then add a ``pick random`` block,
|
||||||
and store the random number in the variable,
|
and store the random number in the variable,
|
||||||
@@ -337,7 +333,7 @@ like this:
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
input.onGesture(Gesture.Shake, () => {
|
input.onGesture(Gesture.Shake, () => {
|
||||||
let weapon = Math.random(3)
|
let item = Math.random(3)
|
||||||
})
|
})
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -353,7 +349,7 @@ We will show the right picture for that number on the LED screen.
|
|||||||
## Step 2: Picking paper
|
## Step 2: Picking paper
|
||||||
|
|
||||||
Put an ``if`` block after the ``let`` block that checks whether
|
Put an ``if`` block after the ``let`` block that checks whether
|
||||||
`weapon` is `0`. Make sure the ``if`` block has an ``else if`` part
|
`item` is `0`. Make sure the ``if`` block has an ``else if`` part
|
||||||
and an ``else`` part.
|
and an ``else`` part.
|
||||||
|
|
||||||
Next, add a ``show leds`` block that shows a
|
Next, add a ``show leds`` block that shows a
|
||||||
@@ -361,8 +357,8 @@ picture of a piece of paper:
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
input.onGesture(Gesture.Shake, () => {
|
input.onGesture(Gesture.Shake, () => {
|
||||||
let weapon = Math.random(3)
|
let item = Math.random(3)
|
||||||
if (weapon == 0) {
|
if (item == 0) {
|
||||||
basic.showLeds(`
|
basic.showLeds(`
|
||||||
# # # # #
|
# # # # #
|
||||||
# . . . #
|
# . . . #
|
||||||
@@ -383,13 +379,13 @@ input.onGesture(Gesture.Shake, () => {
|
|||||||
Now we are going to add a new picture for the micro:bit to show
|
Now we are going to add a new picture for the micro:bit to show
|
||||||
when another random number comes up.
|
when another random number comes up.
|
||||||
|
|
||||||
Make the ``else if`` part check if the variable `weapon` is `1`.
|
Make the ``else if`` part check if the variable `item` is `1`.
|
||||||
Then add a ``show leds`` block with a picture of a rock.
|
Then add a ``show leds`` block with a picture of a rock.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
input.onGesture(Gesture.Shake, () => {
|
input.onGesture(Gesture.Shake, () => {
|
||||||
let weapon = Math.random(3)
|
let item = Math.random(3)
|
||||||
if (weapon == 0) {
|
if (item == 0) {
|
||||||
basic.showLeds(`
|
basic.showLeds(`
|
||||||
# # # # #
|
# # # # #
|
||||||
# . . . #
|
# . . . #
|
||||||
@@ -397,8 +393,7 @@ input.onGesture(Gesture.Shake, () => {
|
|||||||
# . . . #
|
# . . . #
|
||||||
# # # # #
|
# # # # #
|
||||||
`)
|
`)
|
||||||
|
} else if (item == 1) {
|
||||||
} else if (weapon == 1) {
|
|
||||||
basic.showLeds(`
|
basic.showLeds(`
|
||||||
. . . . .
|
. . . . .
|
||||||
. # # # .
|
. # # # .
|
||||||
@@ -418,8 +413,8 @@ Add a ``show leds`` block with a picture of scissors to the ``else`` part:
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
input.onGesture(Gesture.Shake, () => {
|
input.onGesture(Gesture.Shake, () => {
|
||||||
let weapon = Math.random(3)
|
let item = Math.random(3)
|
||||||
if (weapon == 0) {
|
if (item == 0) {
|
||||||
basic.showLeds(`
|
basic.showLeds(`
|
||||||
# # # # #
|
# # # # #
|
||||||
# . . . #
|
# . . . #
|
||||||
@@ -428,7 +423,7 @@ input.onGesture(Gesture.Shake, () => {
|
|||||||
# # # # #
|
# # # # #
|
||||||
`)
|
`)
|
||||||
|
|
||||||
} else if (weapon == 1) {
|
} else if (item == 1) {
|
||||||
basic.showLeds(`
|
basic.showLeds(`
|
||||||
. . . . .
|
. . . . .
|
||||||
. # # # .
|
. # # # .
|
||||||
@@ -451,7 +446,7 @@ input.onGesture(Gesture.Shake, () => {
|
|||||||
|
|
||||||
### ~hint
|
### ~hint
|
||||||
|
|
||||||
You don't need to check if `weapon` is `2` because `2` is the only number left out of `0`, `1`, and `2`.
|
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``.
|
That's why you can use an ``else`` instead of an ``else if``.
|
||||||
|
|
||||||
### ~
|
### ~
|
||||||
|
|||||||
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
|
||||||
|
|||||||
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
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pxt-microbit",
|
"name": "pxt-microbit",
|
||||||
"version": "0.2.147",
|
"version": "0.2.153",
|
||||||
"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.161"
|
"pxt-core": "0.2.165"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,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": {
|
||||||
|
|||||||
@@ -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