Skip to content

Commit 98064b4

Browse files
Update readme to add some basic documentation (#3)
* Add initial docs * Update README.md
1 parent 1220dcb commit 98064b4

File tree

1 file changed

+48
-15
lines changed

1 file changed

+48
-15
lines changed

README.md

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,60 @@
1+
# Makecode Extension to enable power management on micro:bit (V2)
12

2-
## Use as Extension
3+
Use this extension to add all the blocks you will need to power the micro:bit on and off in your program when you are using the [latest micro:bit](https://microbit.org/new-microbit/).
34

4-
This repository can be added as an **extension** in MakeCode.
5+
This extension might be useful when you want to conserve battery power, such as during a data logging activity.
56

6-
* open [https://makecode.microbit.org/](https://makecode.microbit.org/)
7-
* click on **New Project**
8-
* click on **Extensions** under the gearwheel menu
9-
* search for **https://github.com/microbit-foundation/pxt-power** and import
7+
## Usage
108

11-
## Edit this project ![Build status badge](https://github.com/microbit-foundation/pxt-power/workflows/MakeCode/badge.svg)
9+
### Put the micro:bit to sleep 💤
1210

13-
To edit this repository in MakeCode.
11+
To make the micro:bit sleep, you need to send a request to power it down. The ``||power.powerDownRequest||`` block will ask the micro:bit to power down at the next opportunity, such as when the current code operation has been allowed to complete.
1412

15-
* open [https://makecode.microbit.org/](https://makecode.microbit.org/)
16-
* click on **Import** then click on **Import URL**
17-
* paste **https://github.com/microbit-foundation/pxt-power** and click import
13+
```blocks
14+
input.onButtonPressed(Button.B, function () {
15+
power.powerDownRequest()
16+
})
17+
```
1818

19-
## Blocks preview
19+
You can also ask the micro:bit to enter a ``||power.deepSleep||`` where it will pause until a wake up event occurs and power down at the next opportunity.
2020

21-
This image shows the blocks code from the last commit in master.
22-
This image may take a few minutes to refresh.
21+
The ``||power.deepSleepPause(ms)||`` block will also ask the micro:bit to sleep for a set interval in milliseconds.
2322

24-
![A rendered view of the blocks](https://github.com/microbit-foundation/pxt-power/raw/master/.github/makecode/blocks.png)
23+
You can also use the ``||PowerDown.prevent||`` and ``||PowerDown.allow||`` blocks to block a power down request until the code inside the two blocks has finished running. It is expected that you would use these blocks in pairs.
24+
25+
```blocks
26+
basic.forever(function () {
27+
power.powerDownEnable(PowerDown.prevent)
28+
led.plot(2, 2)
29+
basic.pause(1000)
30+
led.unplot(2, 2)
31+
led.plot(2, 1)
32+
basic.pause(1000)
33+
led.unplot(2, 1)
34+
power.powerDownEnable(PowerDown.allow)
35+
power.powerDownRequest()
36+
})
37+
```
38+
39+
### Wake the micro:bit from sleep ⏰
40+
41+
In order to wake the micro:bit, you need to define an event to trigger the wake up call.
42+
43+
You can wake the micro:bit when a button or pin is pressed. In this example, the micro:bit will wake up when Button A or Pin 0 has been pressed.
44+
45+
```blocks
46+
power.wakeOnEnable(PowerWakeup.A)
47+
power.wakeOnEnable(PowerWakeup.P0)
48+
```
49+
50+
You can also wake the micro:bit at a set time interval in milliseconds. In this example, the micro:bit will wake up every minute and show a smiley face on the screen
51+
52+
```blocks
53+
power.wakeEvery(60000, function () {
54+
basic.showIcon(IconNames.Happy)
55+
basic.clearScreen()
56+
})
57+
```
2558

2659
## License
2760

0 commit comments

Comments
 (0)