from machine import Pin, SoftI2C
from ssd1306 import SSD1306_I2C
from machine import Pin,Timer,ADC,PWM
from math import log
import time
from time import sleep
NTC=ADC(Pin(27))
I2C = SoftI2C(scl=Pin(12),sda=Pin(14))
BETA = 3950
led=Pin(17,Pin.OUT)
buzzerPin = Pin(16,Pin.OUT)
def ntc(NTC):
analogValue = NTC.read()
celsius = 1 / (log(1 / (4096. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15
return celsius
while True:
celsius=ntc(NTC)
oled = SSD1306_I2C(128, 64, I2C, addr=0x3c)
if celsius>40:
text=str(round(celsius,1))
oled.text(text,50,28)
oled.show()
time.sleep_ms(800)
buzzer = PWM(buzzerPin ,freq = 100, duty=900)
led.value(1)
elif celsius<=40:
led(0)
buzzer = PWM(buzzerPin ,freq = 100, duty=0)
text=str(round(celsius,1))
oled.text(text,50,28)
oled.show()
time.sleep_ms(800)