DevBoxPico

Code Ref

DevBox (Pico) Code Temperaturanzeige:

# created, copyed and modified by 838375 V4.1 - Temperaturmessung und Anzeige mit Display und Buttons
# import Module
import machine
import utime
from machine import ADC #mainboardsensor
from machine import Pin
import picodisplay as display # Pico Display boilerplate
import time, random
# Display Setting
width = display.get_width()
height = display.get_height()
display_buffer = bytearray(width * height * 2)
display.init(display_buffer)
display.set_backlight(0.5)
# Setup Temperaturmessung und Konvertierung
sensor_temp = machine.ADC(4)
conversion_factor = 3.3 / (65535)
display.set_backlight(0.5)
# Setup LEDs
led25 = Pin(25, Pin.OUT) #mainboard LED
#led06 = Pin(6, Pin.OUT) #Pimoroni Board LED rot
#led07 = Pin(7, Pin.OUT) #Pimoroni Board LED gruen
led08 = Pin(8, Pin.OUT) #Pimoroni Board LED blau
# Definierungen und Funktionen
def clear():
display.set_pen(0, 0, 0)
display.clear()
display.update()
def resetLeds():
led06.value(0)
led07.value(0)
led08.value(0)
led25.value(0)
resetLeds()
def hsv_to_rgb(h, s, v):
if s == 0.0:
return v, v, v
i = int(h * 6.0)
f = (h * 6.0) - i
p = v * (1.0 - s)
q = v * (1.0 - s * f)
t = v * (1.0 - s * (1.0 - f))
i = i % 6
if i == 0:
return v, t, p
if i == 1:
return q, v, p
if i == 2:
return p, v, t
if i == 3:
return p, q, v
if i == 4:
return t, p, v
if i == 5:
return v, p, q
# Zähler auf Null setzen
h = 0
o = 0
clear()
#code
#led08.value(1)
#utime.sleep(3)
led08.value(1)
reading = sensor_temp.read_u16() * conversion_factor
temperature = round(27 - (reading - 0.706) / 0.001721)
display.set_pen(0, 0, 139)
display.rectangle(0, 0, 300, 140)
display.set_pen(255, 255, 255)
display.text("Temperatur:", 10, 30, 0, 3)
display.text(" " + "{:.0f}".format(temperature) + "." + "c", 10, 30, 0, 7)
display.update()
utime.sleep(3)


#display.clear()
#clear()