# imports
import machine
import math
import utime
from machine import Pin , ADC
from utime import sleep
#######################################
# Pin and constant definitions
DIG_1 = 11
DOT_PIN = 7
start_time = 0
inputs =ADC(22)
p_button =Pin(28 , Pin.IN ,Pin.PULL_DOWN)
displayCodes = [
0xC0, #0 -> 0b11000000
0xF9, #1
0xA4, #2
0xB0, #3
0x99, #4
0x92, #5
0x82, #6
0xF8, #7
0x80, #8
0x90 #9
]
display_value = 0
def sensor():
global celsius
BETA = 3950
analogValue = temp_sensor.read_u16()
celsius = 1 / (log(1 / (65535. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15
return celsius
def scan_display():
temp_display_value = display_value
for i in range(3, -1, -1): # 3, 2, 1, 0
display_digit(int(temp_display_value%10), i , i==2)
time.sleep(0.01)
Pin(DIG_1 + i, Pin.OUT).off()
Pin(DOT_PIN, Pin.OUT).value(1)
temp_display_value /= 10
def display_digit(digit_value, digit_index, dp_enable=False):
for i in range(7): #0->7
Pin(i, Pin.OUT).value((1<<i) & displayCodes[digit_value])
Pin(DIG_1 + digit_index, Pin.OUT).on()
if dp_enable:
Pin(DOT_PIN, Pin.OUT).value(0)
def read_value():
global display_value , celsius
if celsius >= 0 :
display_value = (celsius*10)
else :
display_value = (celsius*-10)
def main():
while True:
p_button.irq(trigger=Pin.IRQ_FALLING,handler=call_back)
scan_display()
if __name__ == '__main__':
main()