-
Notifications
You must be signed in to change notification settings - Fork 0
/
EXPERIMENT 4-MIN MAX TEMPERATURE
46 lines (37 loc) · 1.06 KB
/
EXPERIMENT 4-MIN MAX TEMPERATURE
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
#Write a program so it displays the temperature in Fahrenheit as well as the maximum and minimum temperatures it has seen.
import time
import os
base_dir="/sys/bus/w1/devices/28-000008bdd91e/w1_slave"
def read_temp_raw():
f = open(base_dir, "r")
lines = f.readlines()
f.close()
return lines
temp=[]
def read_temp():
lines = read_temp_raw()
while lines[0].strip()[-3:] == "YES":
time.sleep(1)
lines = read_temp_raw()
equal_pos = lines[1].find("t=")
if equal_pos != -1:
temp_string=lines[1][equal_pos+2:]
temp_c=float(temp_string)/1000
temp_f=temp_c*(9.0/5.0)+32.0
temp.append(temp_f)
return(temp_f)
try:
while True:
print(read_temp())
except KeyboardInterrupt:
max=temp[0]
min=temp[0]
print('Readings: ',temp)
for i in (temp):
if(i>max):
max=i
for i in (temp):
if(i<min):
min=i
print('min: ',min)
print('max: ',max)