6727| 0
|
[ESP32系列教程] 使用ESP32 和 micropython点亮RGB LED. |
MicroPython 是 Python 3 语言的精简实现 ,包括Python标准库的一小部分,经过优化可在微控制器中运行。本人只是想通过MP更多更快的掌握python语言。编程环境用了uPyCraft。里面集成了一些基础运行库。烧录略显繁琐。下面简单介绍一下。这个软件。 首先下载python3.7: www.python.org/downloads 之后安装uPyCraft 下载ESP32的micropython固件。 http://micropython.org/download#esp32 选串口端口 没安装CP2102驱动的,安装驱动https://www.silabs.com/products/ ... -bridge-vcp-drivers 选板子 烧录 烧录选项要按我选的来选。但串口端口是选你的实际端口 烧录进程 有时候烧录失败,需要在烧录前按着Boot按键,重新烧录一次 烧录成功后的显示 ====================== 很繁琐是吧。我们的项目是用了ws2812灯带。如图,我们只需要连三个脚。VCC,GND和DATA 在ESP32上DATA连的是IO14. [mw_shl_code=applescript,true]# gada888 import machine, neopixel import time # number of pixels n = 9 # strip control gpio p = 14 np = neopixel.NeoPixel(machine.Pin(p), n) # set single pixel (1st pixel = index [0]) to red color np[0] = (255, 0, 0) np.write() time.sleep(1) # set strip color def set_color(r, g, b): for i in range(n): np = (r, g, b) np.write() set_color(0, 0, 255) time.sleep(1) # fade in/out def fade_in_out(color, wait): for i in range(0, 4 * 256, 8): for j in range(n): if (i // 256) % 2 == 0: val = i & 0xff else: val = 255 - (i & 0xff) if color == 'red': np[j] = (val, 0, 0) elif color == 'green': np[j] = (0, val, 0) elif color == 'blue': np[j] = (0, 0, val) elif color == 'purple': np[j] = (val, 0, val) elif color == 'yellow': np[j] = (val, val, 0) elif color == 'teal': np[j] = (0, val, val) elif color == 'white': np[j] = (val, val, val) np.write() time.sleep_ms(wait) #fade_in_out('red', 0) fade_in_out('green', 10) #fade_in_out('blue', 25) #fade_in_out('purple', 10) fade_in_out('yellow', 10) fade_in_out('teal', 10) #fade_in_out('white', 10) time.sleep(1) [/mw_shl_code] |
© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed