?1
項目簡介
?2
項目硬件介紹

?3
項目設計思路
?4
實現功能展示


?5
主要代碼及說明
import mathdef fill_circle(self, x, y, radius, color):"""Draw a circle at the given location, size and filled with color.Args:x (int): Center x coordinatey (int): Center y coordinateradius (int): Radius in pixelscolor (int): 565 encoded color"""ii = radiuswhile ii >= -radius :delta_x = int(math.sqrt(radius**2 - ii**2))self.hline(x-delta_x, y+ii, delta_x*2, color)ii=ii-1
image_file0 = "/back.bin" #圖片文件地址image_file1 = "/logo.bin"ther_x = 113ther_y = 160slider_x = 110slider_y = 217ther_color = st7789.GREENthreshold = 40threshold_temp = 40st7789_res = 0st7789_dc = 1disp_width = 240disp_height = 240CENTER_Y = int(disp_width/2)CENTER_X = int(disp_height/2)
spi_sck=machine.Pin(2)spi_tx=machine.Pin(3)spi0=machine.SPI(0,baudrate=4000000, phase=1, polarity=1, sck=spi_sck, mosi=spi_tx)print(spi0)display = st7789.ST7789(spi0, disp_width, disp_width,reset=machine.Pin(st7789_res, machine.Pin.OUT),dc=machine.Pin(st7789_dc, machine.Pin.OUT),xstart=0, ystart=0, rotation=0)Joy_x = machine.ADC(29)Joy_y = machine.ADC(28)buttonB = machine.Pin(5,machine.Pin.IN, machine.Pin.PULL_UP) #BbuttonA = machine.Pin(6,machine.Pin.IN, machine.Pin.PULL_UP) #ABuzz = machine.PWM(machine.Pin(23))SensorTemp = machine.ADC(4)offset = 3.3/65535
display.fill(st7789.BLACK)display.text(font2, "Hello! RPi Pico", 10, 10)display.text(font2, "HGF", 10, 40)display.text(font2, "MicroPython", 35, 100)display.text(font2, "EETREE", 35, 150)display.text(font2, "www.eetree.cn", 30, 200)utime.sleep(1)f_image = open(image_file1, 'rb')for column in range(1,240):buf=f_image.read(480)display.blit_buffer(buf, 1, column, 240, 1)utime.sleep(1)
f_image = open(image_file0, 'rb')for column in range(1,240):buf=f_image.read(480)display.blit_buffer(buf, 1, column, 240, 1)display.hline(30, 222, 180, st7789.BLACK)display.text(font1, "Temp:", 10, 60, st7789.BLACK, st7789.WHITE)display.text(font1, "Thre:", 10, 100, st7789.BLACK, st7789.WHITE)display.fill_rect(slider_x, slider_y, 10, 10, st7789.BLACK)display.text(font1, str(threshold_temp), 52, 100, st7789.BLACK, st7789.WHITE)
display.fill_circle(121,170,18,ther_color)temperature = round(27 - (SensorTemp.read_u16()*offset - 0.706)/0.001721,2)print(temperature)display.text(font1, str(temperature)+' ', 52, 60, st7789.BLACK, st7789.WHITE)if temperature >= threshold :ther_color = st7789.REDBuzz.freq(500)Buzz.duty_u16(500)elif temperature <= threshold-1 :ther_color = st7789.GREENBuzz.deinit()ther_y = int(153 - temperature*1.53)display.fill_rect(ther_x, 30, 17, ther_y-30, st7789.WHITE)display.fill_rect(ther_x, ther_y, 17, int(temperature*1.7), ther_color)
if buttonA.value() == 0 :utime.sleep(0.05)while buttonA.value() == 0 :threshold_temp = int( 40+(Joy_x.read_u16()-32768)/830)print(threshold_temp)display.fill_rect(slider_x, slider_y, 10, 10, st7789.WHITE)display.hline(slider_x, 222, 10, st7789.BLACK)slider_x = 38+int(threshold_temp*2)display.fill_rect(slider_x, slider_y, 10, 10, st7789.BLACK)display.text(font1, str(threshold_temp)+' ', 52, 100, st7789.BLACK, st7789.WHITE)else :threshold = threshold_temp
?6
主要難題及解決方法
7
未來的計劃或建議
END
硬禾學堂
硬禾團隊一直致力于給電子工程師和相關專業的同學,帶來規范的核心技能課程,幫助大家在學習和工作的各個階段,都能有效地提升自己的職業能力。

硬禾學堂
我們一起在電子領域探索前進
關注硬禾公眾號,隨時直達課堂

點擊閱讀原文查看更多