Skip to content

Commit 772c839

Browse files
docs: Move log.rst code into a script in the examples folder.
1 parent 4d6299f commit 772c839

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

docs/log.rst

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -108,37 +108,7 @@ A minimal example::
108108
def log_temp():
109109
log.add(temp=temperature())
110110

111-
An example that runs through some of the functions of the log module API::
111+
An example that runs through some of the functions of the log module API:
112112

113-
from microbit import *
114-
import log
115-
116-
# Configure the labels and select a time unit for the timestamp
117-
log.set_labels('temp', 'brightness', timestamp=log.SECONDS)
118-
119-
# Send each data row to the serial output
120-
log.set_mirroring(True)
121-
122-
# This decorator schedules this function to run every 10s 50ms
123-
@run_every(s=10, ms=50)
124-
def log_data():
125-
"""Log the temperature and light level, and display an icon."""
126-
log.add(temp=temperature(), brightness=display.read_light_level())
127-
display.show(Image.SURPRISED)
128-
sleep(500)
129-
130-
while True:
131-
if button_a.is_pressed() and button_b.is_pressed():
132-
display.show(Image.MEH)
133-
# Delete the log file using the "full" options, which takes
134-
# longer but ensures the data is wiped from the device
135-
log.delete(full=True)
136-
elif button_a.is_pressed():
137-
display.show(Image.HAPPY)
138-
# Log only the light level, the temp entry will be empty
139-
log.add({
140-
"brightness": display.read_light_level()
141-
})
142-
else:
143-
display.show(Image.CONFUSED)
144-
sleep(500)
113+
.. include:: ../examples/data-logging.py
114+
:code: python

examples/data-logging.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from microbit import *
2+
import log
3+
4+
# Configure the labels and select a time unit for the timestamp
5+
log.set_labels('temp', 'brightness', timestamp=log.SECONDS)
6+
7+
# Send each data row to the serial output
8+
log.set_mirroring(True)
9+
10+
# This decorator schedules this function to run every 10s 50ms
11+
@run_every(s=10, ms=50)
12+
def log_data():
13+
"""Log the temperature and light level, and display an icon."""
14+
log.add(temp=temperature(), brightness=display.read_light_level())
15+
display.show(Image.SURPRISED)
16+
sleep(500)
17+
18+
while True:
19+
if button_a.is_pressed() and button_b.is_pressed():
20+
display.show(Image.MEH)
21+
# Delete the log file using the "full" options, which takes
22+
# longer but ensures the data is wiped from the device
23+
log.delete(full=True)
24+
elif button_a.is_pressed():
25+
display.show(Image.HAPPY)
26+
# Log only the light level, the temp entry will be empty
27+
log.add({
28+
"brightness": display.read_light_level()
29+
})
30+
else:
31+
display.show(Image.CONFUSED)
32+
sleep(500)

0 commit comments

Comments
 (0)