1
项目简介
2
项目硬件介绍
3
项目设计思路
4
实现功能展示
5
主要代码及说明
import math
def fill_circle(self, x, y, radius, color):
"""
Draw a circle at the given location, size and filled with color.
Args:
x (int): Center x coordinate
y (int): Center y coordinate
radius (int): Radius in pixels
color (int): 565 encoded color
"""
ii = radius
while 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 = 113
ther_y = 160
slider_x = 110
slider_y = 217
ther_color = st7789.GREEN
threshold = 40
threshold_temp = 40
st7789_res = 0
st7789_dc = 1
disp_width = 240
disp_height = 240
CENTER_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) #B
buttonA = machine.Pin(6,machine.Pin.IN, machine.Pin.PULL_UP) #A
Buzz = 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.RED
Buzz.freq(500)
Buzz.duty_u16(500)
elif temperature <= threshold-1 :
ther_color = st7789.GREEN
Buzz.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
硬禾学堂
硬禾团队一直致力于给电子工程师和相关专业的同学,带来规范的核心技能课程,帮助大家在学习和工作的各个阶段,都能有效地提升自己的职业能力。
硬禾学堂
我们一起在电子领域探索前进
关注硬禾公众号,随时直达课堂
点击阅读原文查看更多