我有一台10年前买的旧笔记本电脑酷派。除了添加RGB灯外,我还心想,如果笔记本电脑能自动控制散热板,那该有多好。因此,我经历了以下步骤。我使用了Python中的psutil和gputil库来提取笔记本电脑的硬件信息,您可以看到下面的Python脚本。
代码: 全选
import psutil
import GPUtil as gu
def show_gpu_temp():
gpu = gu.getGPUs()[0]
return gpu.temperature
def show_cpu_freq():
current_freq, _, _ = psutil.cpu_freq()
return current_freq
def show_cpu_perecent():
cpu_perecent = psutil.cpu_percent()
return cpu_perecent
def cpu_core_count():
cpu_cores = psutil.cpu_count()
return cpu_cores
def show_memory_info():
total_memory, available_memory, percent, used_memory, free_memory = psutil.virtual_memory()
return percent
在获得笔记本电脑硬件信息后,我们将这些信息发送到我在LabVIEW图形环境中以框图的形式编写的程序中。LabVIEW的图形面板以一种吸引人的方式显示信息。在收到信息并以图形方式显示后,我通过蓝牙通信向Raspberry Pi Pico微控制器发送控制命令以打开酷派风扇。当向Raspberry Pi Pico发送开机命令时,RGB指示灯也会亮起。您可以在下面看到以框图形式编写的程序。
最后,在我用Microython语言编写的脚本的帮助下,我通过蓝牙通信接收控制命令。一旦Raspberry Pi Pico收到命令,它就可以启用或禁用冷却板风扇和RGB环。你可以看到我为Raspberrry Pi Pico编写的程序以及下面的电路图。我还使用了L298电机驱动程序来运行冷却板风扇。我还使用了HC-05模块进行蓝牙通信。
代码: 全选
from machine import UART
from machine import Pin as pin
from time import sleep
import machine, neopixel
#####
#thanks to microsoft copilot for guiding me to write these functions to control RGB LED ring using neopixel library
# Pin number, number of LEDs, and bpp
PIN_NUM = 15
NUM_LEDS = 16
BPP = 4
# Create a neopixel object
np = neopixel.NeoPixel(machine.Pin(PIN_NUM), NUM_LEDS, bpp=BPP)
# Define the rainbow colors
RED = (255, 0, 0, 128)
ORANGE = (255, 128, 0, 128)
YELLOW = (255, 255, 0, 128)
GREEN = (0, 255, 0, 128)
BLUE = (0, 0, 255, 128)
INDIGO = (75, 0, 130, 128)
VIOLET = (148, 0, 211, 128)
# Store the colors in a list
COLORS = [RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET]
# Loop through the colors and display them on the LEDs
def rainbow():
for color in COLORS:
# Set the color of each pixel
for i in range(NUM_LEDS):
np[i] = color
# Write the data to the LEDs
np.write()
time.sleep(0.5)
def disable_rainbow():
for color in COLORS:
# Set the color of each pixel
for i in range(NUM_LEDS):
np[i] = (0, 0, 0, 0)
# Write the data to the LEDs
np.write()
#####
ut = UART(0,9600)
command = b'S'
#Define Driver pins
in1 = pin(16,pin.OUT)
in3 = pin(17,pin.OUT)
#########
ENA = pin(18,pin.OUT)
ENB = pin(19,pin.OUT)
ENA.value(1)
ENB.value(1)
#########
def enable_fan():
in1.value(1)
in3.value(1)
def disable_fan():
in1.value(0)
in3.value(0)
disable_fan()
while True:
if ut.any():
command = ut.readline()
#print(command)
if command == b's':
disable_fan()
elif command == b'o':
enable_fan()
rainbow()
elif command == b'f':
disable_fan()
disable_rainbow()
else:
pass