from machine import ADC,Pin
from utime import sleep
from math import log
BETA = 3950
sensor = ADC(Pin(27))
seg_1 = [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)]
seg_2 = [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)]
#0 #1 #2 #3
seg_display = [[1,1,1,1,1,1,0,0],[0,1,1,0,0,0,0,0],[1,1,0,1,1,0,1,0],[1,1,1,1,0,0,1,0],
#4 #5 #6 #7
[0,1,1,0,0,1,1,0],[1,0,1,1,0,1,1,0],[1,0,1,1,1,1,1,0],[1,1,1,0,0,0,0,0],
#8 #9
[1,1,1,1,1,1,1,0],[1,1,1,1,0,1,1,0]]
def display(value):
a=int(value%10)
b=int(value/10)
for i in range(8):
seg_1[i].value((seg_display[a][i]))
seg_2[i].value((seg_display[b][i]))
def temp():
val=sensor.read_u16()
voltage=val/65535*3.300
print(val,voltage)
celcius=1/(log(1/(65535/val-1))/BETA+1.0/298.15)-273.15;
print("Temperature",celcius,"^C")
display(int(celcius))
sleep(0.1)
while 1:
temp()