import time
for i in range(3):
print("1")
time.sleep(1)
for i in range(3):
print("2")
time.sleep(1)
输出为
import _thread
import time
import sys
import machine
def test1(*args, **kwargs):
for i in range(3):
print("1")
time.sleep(1)
def test2(*args, **kwargs):
for i in range(3):
print("2")
time.sleep(1)
# 此处创建2个线程
thread_1 = _thread.start_new_thread(test1, (1,))
thread_2 = _thread.start_new_thread(test2, (2,))
说明:_thread.start_new_thread
import _thread
import time
import sys
import machine
# ---------- 这是一个线程要执行的代码 ------------
def test1(*args, **kwargs):
while True:
print("1")
time.sleep(1)
# ---------- 这是另一个线程要执行的代码 ------------
def test2(*args, **kwargs):
while True:
print("2")
time.sleep(1)
# ---------- 这里创建线程 ------------
thread_1 = _thread.start_new_thread(test1, (1,))
thread_2 = _thread.start_new_thread(test2, (2,))
# ---------- 这是主线程要执行的代码 ------------
while True:
print("3")
time.sleep(1)
PWM,英文名Pulse Width Modulation,是脉冲宽度调制缩写,它是通过调节占空比的变化来调节信号、能量等的变化。
相信很多人都有把绿植给养死的经历,可能是浇水过多、忘记浇水、较长时间不在家不能浇水等,本文介绍一种可以灵活定制的智能浇花方案。
MicroPython 在 ESP32 上支持线程(Thread)功能,通过_thread模块实现。线程允许程序并发执行多个任务,适合处理需要同时运行的场景,例如传感器数据采集和网络通信。
掌控板3.0升级了主控,还主打AI。带有双麦克风阵列,增加了音频解码芯片,板载了一个1W喇叭,还把之前的单色屏幕换成了1.47寸的彩色屏幕,有更多的可玩性。
使用了 MicroPython 库,通过 定时器(Timer) 和 ADC(模数转换器) 功能来实时读取传感器数据。使用定时器可以实现高精度、非阻塞、低资源消耗的周期性任务,保证实时性和可靠性,特别适用于嵌入式系统中的多任务处理和低功耗场景。
ESP32的DAC函数可以实现真正的模拟输出。
ESP32 没有Arduino输出 PWM 的 analogWrite(pin, value) 方法,取而代之的 ESP32 有一个 LEDC 来实现PWM功能。
machine.pwm是MicroPython中用于控制PWM输出的模块之一,它提供了一些方法和属性,用于设置和控制PWM输出的频率、占空比等参数,从而实现对各种应用场景的控制。
Pin 类是 machine 模块下面的一个硬件类,用于对引脚的配置和控制,提供对 GPIO 的操作方法。
MicroPython的SPI是一个用于进行串行外设接口总线协议的类。
本文以一个简单的例程帮助大家在 MicroPython 下使用 I2C