918af4f3ac
* change simulator svg * change radio image * Remove google fonts cdn * change color of 'advanced' button * font fix * font fix 2 * display fix * change fullsceen simulator bg * Continuous servo * handle continuous state * adding shims * update rendering for continuous servos * fixing sim * fix sig * typo * fix sim * bump pxt * bump pxt * rerun travis * Input blocks revision - add Button and Pin event types - merge onPinPressed & onPinReleased in new onPinEvent function - create new onButtonEvent function * update input blocks in docs and tests * remove device_pin_release block * Hide DAL.x behind Enum * bring back deprecated blocks, but hide them * shims and locales files * fix input.input. typing * remove buildpr * bump V3 * update simulator aspect ratio * add Loudness Block * revoke loudness block * Adds soundLevel To be replaced by pxt-common-packages when DAL is updated. * Remove P0 & P3 from AnalogPin Co-authored-by: Juri <gitkraken@juriwolf.de>
59 lines
1.4 KiB
Markdown
59 lines
1.4 KiB
Markdown
# Dice
|
|
|
|
## Introduction @unplugged
|
|
|
|
Let's turn the @boardname@ into a dice!
|
|
(Want to learn how the accelerometer works? [Watch this video](https://youtu.be/byngcwjO51U)).
|
|
|
|
![A mini dice](/calliope/tutorials/04_dice_animation.gif)
|
|
|
|
## Step 1 @fullscreen
|
|
|
|
We need 3 pieces of code: one to detect a throw (shake), another to pick a random number, and then one to show the number.
|
|
|
|
Place the ``||input:on shake||`` block onto the editor workspace. It runs code when you shake the @boardname@.
|
|
|
|
```blocks
|
|
input.onGesture(Gesture.Shake, () => {
|
|
|
|
})
|
|
```
|
|
|
|
## Step 2 @fullscreen
|
|
|
|
Get a ``||basic:show number||`` block and place it inside the ``||input:on shake||`` block to display a number.
|
|
|
|
```blocks
|
|
input.onGesture(Gesture.Shake, () => {
|
|
basic.showNumber(0)
|
|
})
|
|
```
|
|
|
|
## Step 3 @fullscreen
|
|
|
|
Put a ``||Math:pick random||`` block in the ``||basic:show number||`` block to pick a random number.
|
|
|
|
```blocks
|
|
input.onGesture(Gesture.Shake, () => {
|
|
basic.showNumber(randint(0, 10))
|
|
})
|
|
```
|
|
|
|
## Step 4 @fullscreen
|
|
|
|
A typical dice shows values from `1` to `6`. So, in ``||Math:pick random||``, don't forget to choose the right minimum and maximum values!
|
|
|
|
```blocks
|
|
input.onGesture(Gesture.Shake, () => {
|
|
basic.showNumber(randint(1, 6))
|
|
})
|
|
```
|
|
|
|
## Step 5
|
|
|
|
Use the simulator to try out your code. Does it show the number you expected?
|
|
|
|
## Step 6
|
|
|
|
If you have a @boardname@ connected, click ``|Download|`` and transfer your code to the @boardname@!
|