from machine import Pin,ADC
from utime import sleep
from math import log
Beta = 3950
sensor=ADC(Pin(26))
seg7a= [Pin(0,Pin.OUT),Pin(1,Pin.OUT),Pin(2,Pin.OUT),
Pin(3,Pin.OUT),Pin(4,Pin.OUT),Pin(5,Pin.OUT),
Pin(6,Pin.OUT),Pin(7,Pin.OUT)] #abcdefgh
seg7b= [Pin(8,Pin.OUT),Pin(9,Pin.OUT),Pin(10,Pin.OUT),
Pin(11,Pin.OUT),Pin(12,Pin.OUT),Pin(13,Pin.OUT),
Pin(14,Pin.OUT),Pin(15,Pin.OUT)] #abcdefgh
#0 #1 #2
pat7=[[1,1,1,1,1,1,0,0],[0,1,1,0,0,0,0,0],[1,1,0,1,1,0,1,0],
#3 #4 #5
[1,1,1,1,0,0,1,0],[0,1,1,0,0,1,1,0],[1,0,1,1,0,1,1,0],
#6 #7 #8
[1,0,1,1,1,1,1,0],[1,1,1,0,0,0,0,0],[1,1,1,1,1,1,1,0],
#9
[1,1,1,1,0,1,1,0]]
def display7(value):
value = max(value,0)
a=int(value%10)
b=int(value/10)
for i in range(8):
seg7a[i].value((pat7[a][i]))
seg7b[i].value((pat7[b][i]))
while 1:
val=sensor.read_u16()
voltage=val/65535*3.3
celcius = 1/(log(1/(65535.00/val-1))/Beta+1.0/298.15)-273.15;
print("temperature",celcius,"^C")
i=int(celcius)
display7(i)
sleep(0.4)