|
1 | 1 | # Makecode Extension to enable power management on micro:bit (V2) |
2 | 2 |
|
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/). |
| 3 | +Use this extension to add all the blocks you will need to use less power in your program when you are using the [latest micro:bit](https://microbit.org/new-microbit/). |
4 | 4 |
|
5 | 5 | This extension might be useful when you want to conserve battery power, such as during a data logging activity. |
6 | 6 |
|
| 7 | + |
7 | 8 | ## Usage |
8 | 9 |
|
9 | | -### Put the micro:bit to sleep 💤 |
| 10 | +### Put the micro:bit to sleep in a low power mode 💤 |
10 | 11 |
|
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. |
| 12 | +The ``||power.lowPowerRequest||`` block will ask the micro:bit to switch to low power mode at the next opportunity, such as when the current code operation has been allowed to complete, or inside ``||basic.pause(ms)||``. |
12 | 13 |
|
13 | 14 | ```blocks |
14 | 15 | input.onButtonPressed(Button.B, function () { |
15 | | - power.powerDownRequest() |
| 16 | + power.lowPowerRequest() |
16 | 17 | }) |
17 | 18 | ``` |
18 | 19 |
|
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. |
| 20 | +You can send ``||power.lowPowerRequest(LowPowerMode.Wait)||``. Then micro:bit will also pause until a full power event occurs. |
| 21 | + |
| 22 | +The ``||power.lowPowerPause(ms)||`` block will ask the micro:bit to sleep for a set interval in milliseconds. |
20 | 23 |
|
21 | | -The ``||power.deepSleepPause(ms)||`` block will also ask the micro:bit to sleep for a set interval in milliseconds. |
| 24 | +In low power mode, micro:bit is asleep, and your program is paused. When micro:bit wakes up to full power mode, your program continues from the point it stopped. |
22 | 25 |
|
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. |
| 26 | +You can use the ``||power.lowPowerEnable(PowerDown.prevent)||`` and ``||power.lowPowerEnable(PowerDown.allow)||`` blocks to block low power requests until the code between the two blocks has finished running. It is expected that you would use these blocks in pairs. |
24 | 27 |
|
25 | 28 | ```blocks |
26 | 29 | basic.forever(function () { |
27 | | - power.powerDownEnable(PowerDown.prevent) |
| 30 | + power.lowPowerEnable(PowerDown.prevent) |
28 | 31 | led.plot(2, 2) |
29 | 32 | basic.pause(1000) |
30 | 33 | led.unplot(2, 2) |
31 | 34 | led.plot(2, 1) |
32 | 35 | basic.pause(1000) |
33 | 36 | led.unplot(2, 1) |
34 | | - power.powerDownEnable(PowerDown.allow) |
35 | | - power.powerDownRequest() |
| 37 | + power.lowPowerEnable(PowerDown.allow) |
| 38 | + power.lowPowerRequest() |
36 | 39 | }) |
37 | 40 | ``` |
38 | 41 |
|
39 | | -### Wake the micro:bit from sleep ⏰ |
| 42 | +### Wake up micro:bit to full power mode ⏰ |
40 | 43 |
|
41 | | -In order to wake the micro:bit, you need to define an event to trigger the wake up call. |
| 44 | +In order to wake up micro:bit to full power mode, you need to define an event to trigger the wake up call. |
42 | 45 |
|
43 | 46 | 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 | 47 |
|
45 | 48 | ```blocks |
46 | | -power.wakeOnEnable(PowerWakeup.A) |
47 | | -power.wakeOnEnable(PowerWakeup.P0) |
| 49 | +power.fullPowerOn(FullPowerSource.A) |
| 50 | +power.fullPowerOn(FullPowerSource.P0) |
48 | 51 | ``` |
49 | 52 |
|
50 | 53 | 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 | 54 |
|
52 | 55 | ```blocks |
53 | | -power.wakeEvery(60000, function () { |
| 56 | +power.fullPowerEvery(60000, function () { |
54 | 57 | basic.showIcon(IconNames.Happy) |
55 | 58 | basic.clearScreen() |
| 59 | + power.lowPowerRequest() |
56 | 60 | }) |
57 | 61 | ``` |
58 | 62 |
|
|
0 commit comments