pxt-calliope/docs/projects/love-meter.md

37 lines
943 B
Markdown
Raw Normal View History

2017-12-07 05:23:17 +01:00
# Love meter
2016-06-14 17:12:13 +02:00
2017-12-07 05:23:17 +01:00
Make a love meter, how sweet! The @boardname@ is feeling the love, then sometimes not so much!
2016-06-11 23:12:12 +02:00
## Step 1
Let's build a **LOVE METER** machine. Place a ``||input:on pin pressed||`` block to run code when pin ``P0`` is pressed.
2016-06-11 23:12:12 +02:00
```blocks
input.onPinPressed(TouchPin.P0, () => {
});
```
## Step 2
Using ``||basic:show number||`` and ``||Math:pick random||`` blocks, show a random number from 0 to 100 when pin ``P0`` is pressed.
2016-06-11 23:12:12 +02:00
```blocks
input.onPinPressed(TouchPin.P0, () => {
2018-06-01 20:42:38 +02:00
basic.showNumber(Math.randomRange(0, 101));
2016-06-11 23:12:12 +02:00
});
```
## Step 3
Show ``"LOVE METER"`` on the screen when the @boardname@ starts.
2016-06-11 23:12:12 +02:00
```blocks
basic.showString("LOVE METER");
2016-06-11 23:12:12 +02:00
input.onPinPressed(TouchPin.P0, () => {
2018-06-01 20:42:38 +02:00
basic.showNumber(Math.randomRange(0, 101));
2016-06-11 23:12:12 +02:00
});
2016-06-25 23:22:50 +02:00
```
## Step 4
Click ``|Download|`` to transfer your code in your @boardname@. Hold the ``GND`` pin with other hand and press pin ``P0`` with the other hand to trigger this code.