# TMP36v5 - 15 readings - mean of middle
import board
import time
from analogio import AnalogIn
A2_in = AnalogIn(board.A2)
y = A2_in.value  # Throw away the first analog reading
def get_TMP36():
    x = A2_in.value
    # Calculate temperature
    millivolts = x * (3.275 * 1000 / 65535)
    tempC = (millivolts - 500) / 10
    return tempC
def get_temp():
    list = []
    readings = 15
    for i in range(readings):
        C = get_TMP36()  # Get temp in deg C
        list.append(C) # append to growing list
        time.sleep(0.05)
    count = 0
    list.sort()  # Sorts low to high
    # Average of middle 5
    t = 0
    for i in range(5,10):
        t = t + list[i]
    mean = t/5
    return mean

xx = input("\nHg temp: ")
for i in range(10):
    print("Temperature: ", get_temp())
    time.sleep(5)