crwdns258736:0crwdne258736:0
crwdns258738:0crwdne258738:0
crwdns258744:0crwdne258744:0
crwdns258752:0crwdne258752:0
- crwdns258754:0crwdne258754:0
- crwdns258756:0crwdne258756:0
crwdns258758:0crwdne258758:0
- crwdns258762:0crwdne258762:0 crwdns258764:0crwdne258764:0
- crwdns258766:0crwdne258766:0
- crwdns258768:0crwdne258768:0
- crwdns258770:0crwdne258770:0
- crwdns258772:0crwdne258772:0
crwdns258774:0crwdne258774:0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from microbit import *
# function to read data file:
def get_nv_data(name):
try:
with open(name) as f:
v = int(f.read())
except OSError:
v = temperature()
try:
with open(name, 'w') as f:
f.write(str(v))
except OSError:
display.scroll('Cannot create file %s' % name)
except ValueError:
display.scroll('invalid data in file %s' % name)
v = temperature()
return v
# function to write data file:
def set_nv_data(name, value):
try:
with open(name, 'w') as f:
f.write(str(value))
except OSError:
display.scroll('Cannot write to file %s' % name)
min = get_nv_data('min.txt')
max = get_nv_data('max.txt')
while True:
currentTemp = temperature()
if currentTemp < min:
min = currentTemp
set_nv_data('min.txt', min)
if currentTemp > max:
max = currentTemp
set_nv_data('max.txt', max)
if accelerometer.was_gesture('shake'):
display.scroll(currentTemp)
if button_a.was_pressed():
display.scroll(get_nv_data('min.txt'))
if button_b.was_pressed():
display.scroll(get_nv_data('max.txt'))
if pin2.is_touched():
display.scroll('clearing data')
set_nv_data('min.txt', currentTemp)
set_nv_data('max.txt', currentTemp)
crwdns258776:0crwdne258776:0
crwdns258786:0crwdne258786:0
crwdns258814:0crwdne258814:0
- crwdns258882:0crwdne258882:0
- crwdns258884:0crwdne258884:0