Skip to content

Commit ed872da

Browse files
docs: Merge the wake_source() function into deep_sleep().
1 parent 2d95e0a commit ed872da

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

docs/power.rst

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,34 +81,27 @@ Functions
8181
will start running from the beginning.
8282

8383

84-
.. py:function:: deep_sleep()
84+
.. py:function:: deep_sleep(ms=None, pins=None, buttons=None, run_every=False)
8585
8686
Set the micro:bit into the a mode where it can wake up and continue
8787
operation.
8888

89-
The programme state is preserved and on wake it will resume operation
90-
where it left off.
89+
The programme state is preserved and when it wakes up it will resume
90+
operation where it left off.
9191

92-
The wake up sources are configured with the ``wake_source()`` function.
93-
If no wake up sources have been configured it will sleep indefinitely.
94-
95-
Deep Sleep mode will consume more battery power than Off mode.
96-
97-
.. py:function:: wake_source(pins=None, buttons=None, ms=None, run_every=False)
92+
The Deep Sleep mode will consume more battery power than Off mode.
9893

99-
Configure the "Deep Sleep" wake-up sources.
100-
101-
These wake-up source will not work for the Off mode.
94+
The wake up sources are configured via arguments.
95+
If no wake up sources have been configured it will sleep indefinitely.
10296

97+
:param ms: A time in milliseconds to wait before it wakes up.
10398
:param pins: A single instance or a tuple of pins, e.g.
10499
``wake_source(pins=(pin0, pin2))``.
105100
:param buttons: A single instance or a tuple of buttons, e.g.
106101
``wake_source(buttons=button_a)``.
107-
:param ms: A time in milliseconds to wait before it wakes up.
108102
:param run_every: Set to ``True`` to wake up with each
109103
``microbit.run_every`` scheduled run.
110104

111-
112105
Examples
113106
========
114107

@@ -136,15 +129,13 @@ Example programme showing the power management API::
136129
display.show(Image.SURPRISED)
137130
elif button_b.is_pressed():
138131
display.scroll("Sleep")
139-
# First let's configure the wake up sources for deep sleep
140-
power.wake_source(
132+
# Go into Deep Sleep with multiple wake up sources
133+
power.deep_sleep(
141134
pins=(pin0, pin1),
142-
buttons=button_a
143-
ms=5*60*1000 # In 5 minutes it wakes up anyway
144-
run_every=False # Blocks run_every from waking up the board
135+
buttons=button_a,
136+
ms=5*60*1000, # In 5 minutes it wakes up anyway
137+
run_every=False, # Blocks run_every from waking up the board
145138
)
146-
# Now let's go to sleep
147-
power.deep_sleep()
148139
# When the micro:bit wakes up will it continue running from here
149140
display.show(Image.ASLEEP)
150141
sleep(1000)
@@ -162,11 +153,9 @@ Example using data logging::
162153
def log_temperature():
163154
log.add(temp=temperature())
164155

165-
# Configure the wake up sources to wake up with run_every & button A
166-
power.wake_source(buttons=button_a, run_every=True)
167-
168156
while True:
169157
if button_a.is_pressed():
170158
# Display the temperature when button A is pressed
171159
display.scroll(temperature())
172-
power.deep_sleep()
160+
# To go sleep and wake up with run_every or button A
161+
power.deep_sleep(buttons=button_a, run_every=True)

0 commit comments

Comments
 (0)