crwdns258736:0crwdne258736:0
crwdns258738:0crwdne258738:0
crwdns258850:0crwdne258850:0
crwdns258742:0crwdne258742:0
crwdns258744:0crwdne258744:0
- crwdns258746:0crwdne258746:0
- crwdns258748:0crwdne258748:0
- crwdns258750:0crwdne258750:0
crwdns258752:0crwdne258752:0
- crwdns258754:0crwdne258754:0
- crwdns258756:0crwdne258756:0
crwdns258758:0crwdne258758:0
- crwdns258852:0crwdne258852:0
- crwdns258762:0crwdne258762:0 crwdns258764:0crwdne258764:0
- crwdns258766:0crwdne258766:0
- crwdns258768:0crwdne258768:0
- crwdns258770:0crwdne258770:0
- crwdns258772:0crwdne258772:0
crwdns258774:0crwdne258774:0
1from microbit import *
2
3# function to read data file:
4def get_nv_data(name):
5 try:
6 with open(name) as f:
7 v = int(f.read())
8 except OSError:
9 v = temperature()
10 try:
11 with open(name, 'w') as f:
12 f.write(str(v))
13 except OSError:
14 display.scroll('Cannot create file %s' % name)
15
16 except ValueError:
17 display.scroll('invalid data in file %s' % name)
18 v = temperature()
19
20 return v
21
22# function to write data file:
23def set_nv_data(name, value):
24 try:
25 with open(name, 'w') as f:
26 f.write(str(value))
27 except OSError:
28 display.scroll('Cannot write to file %s' % name)
29
30min = get_nv_data('min.txt')
31max = get_nv_data('max.txt')
32
33while True:
34 currentTemp = temperature()
35 if currentTemp < min:
36 min = currentTemp
37 set_nv_data('min.txt', min)
38 if currentTemp > max:
39 max = currentTemp
40 set_nv_data('max.txt', max)
41 if accelerometer.was_gesture('shake'):
42 display.scroll(currentTemp)
43 if button_a.was_pressed():
44 display.scroll(get_nv_data('min.txt'))
45 if button_b.was_pressed():
46 display.scroll(get_nv_data('max.txt'))
47 if pin2.is_touched():
48 display.scroll('clearing data')
49 set_nv_data('min.txt', currentTemp)
50 set_nv_data('max.txt', currentTemp)
51
crwdns258776:0crwdne258776:0
crwdns258778:0crwdne258778:0 crwdns258780:0crwdne258780:0 crwdns258782:0crwdne258782:0
crwdns258854:0crwdne258854:0
crwdns258786:0crwdne258786:0
- crwdns258856:0crwdne258856:0
- crwdns258858:0crwdne258858:0 crwdns258860:0crwdne258860:0
- crwdns258862:0crwdne258862:0 crwdns291710:0crwdne291710:0
crwdns258866:0crwdne258866:0 crwdns258800:0crwdne258800:0
- crwdns291712:0crwdne291712:0
- crwdns258870:0crwdne258870:0
crwdns258872:0crwdne258872:0 crwdns258874:0crwdne258874:0
crwdns258876:0crwdne258876:0 crwdns258812:0crwdne258812:0
crwdns258814:0crwdne258814:0
- crwdns291714:0crwdne291714:0 crwdns258880:0crwdne258880:0
- crwdns258882:0crwdne258882:0
- crwdns258884:0crwdne258884:0
This content is published under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) licence.