# https://how2electronics.com/how-to-use-adc-in-raspberry-pi-pico-adc-example-code/
# https://wiki.seeedstudio.com/Grove-Temperature_Sensor/
# https://www.iope.com.br/sensor-temperatura-pt100#:~:text=Essa%20varia%C3%A7%C3%A3o%20da%20resist%C3%AAncia%20el%C3%A9trica,el%C3%A9trica%20em%20fun%C3%A7%C3%A3o%20da%20temperatura%2C
# https://wiki.sj.ifsc.edu.br/index.php/ESTE:_Analog_Temperature_Sensor_2_(NTC_-_Negative_Temperature_Coeficient)
# https://docs.wokwi.com/pt-BR/parts/wokwi-ntc-temperature-sensor
from machine import ADC, Pin
import utime
from prints import *
from blink_led import *
from scale import *
# ---------------------------------------
# PORTS CONFIGURATION
led = Pin(1,Pin.OUT)
adc = machine.ADC(26) # create ADC object on ADC pin
# INITIAL TIMESTAMP TIME
timestamp_initial = utime.ticks_us()
# SETUP DESIRED PRINTS
show_prints = prints()
show_prints.temperatura()
show_prints.all_params()
# SETUP TEMPERATURE SCALE
escala = scale.celsius
# ---------------------------------------
# ---------------------------------------
def ler(escala):
get_timestamp()
analogValue = adc.read_u16() # Values: 0-65535
analogValue = analogValue/64 # Values: 0-1023
if(show_prints.valor_adc_ == True):
print('O valor adc lido é:',analogValue)
temperatura = scale.convert(show_prints, escala, analogValue)
average_temperature(temperatura)
# ---------------------------------------
# ---------------------------------------
def get_timestamp():
timestamp_actual = utime.ticks_us()
timepassed = (timestamp_actual - timestamp_initial ) /1000000
if(show_prints.tempo_==True):
print('{:0.2f}s'.format(timepassed))
# ---------------------------------------
lista_temperaturas = []
def average_temperature(temperatura):
#Append value to a list
#Print average of last temperature values
lista_temperaturas.append(temperatura)
if(len(lista_temperaturas)>7):
lista_temperaturas.pop(0)
media = sum(lista_temperaturas)/len(lista_temperaturas)
if(show_prints.media_==True):
print('Média últimos valores: {:0.2f}ºC '.format(media))
# ---------------------------------------
# ---------------------------------------
while True:
if(show_prints.has_prints == False):
print('--------------')
ler(escala)
blink_led(led,400)