File tree Expand file tree Collapse file tree 2 files changed +34
-32
lines changed Expand file tree Collapse file tree 2 files changed +34
-32
lines changed Original file line number Diff line number Diff line change @@ -110,35 +110,5 @@ A minimal example::
110
110
111
111
An example that runs through all of the functions of the log module API:
112
112
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
Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments