二、环境
ESP32 C3开发板(MicroPython v1.19.1 on 2022-06-18)+ 独立按键模块 + I2C.96寸ssd1306屏幕模块+ led灯 + PWM调速小风扇模块 + 几根杜邦线 + Win10商业
ESP32和各个模块接线方法:
三、实验代码
from machine import Pin,I2C,PWM
from ssd1306 import SSD1306_I2C
from ufont import BMFont
import time
# 创建I2C对象
i2c = I2C(0,scl = Pin(5),sda = Pin(4),freq = 400_000)
# 创建oled屏幕对象
oled = SSD1306_I2C(128,64,i2c,0x3c)
# 挂载字体文件
font = BMFont("fonts/unifont-14-12888-16.v3.bmf")
# 定义上、下、左、右、中、SET、RST七个按键
UP = Pin(10,Pin.IN,Pin.PULL_UP)
DWN = Pin(6,Pin.IN,Pin.PULL_UP)
LFT = Pin(7,Pin.IN,Pin.PULL_UP)
RHT = Pin(9,Pin.IN,Pin.PULL_UP)
MID = Pin(2,Pin.IN,Pin.PULL_UP)
SET = Pin(3,Pin.IN,Pin.PULL_UP)
RST = Pin(8,Pin.IN,Pin.PULL_UP)
# 定义led灯对象
led = Pin(13,Pin.OUT)
def Key():
# "up","down","left ","right","middle","set","rst"
key = 1
if (key == 1 and (UP.value() == 0 or DWN.value() == 0 or LFT.value() == 0 or RHT.value() == 0) or MID.value() == 0 or SET.value() == 0 or RST.value() == 0):
time.sleep(0.020)
key = 0
if UP.value() == 0:
return "upper"
elif DWN.value() == 0:
return "down "
elif LFT.value() == 0:
return "Left "
elif RHT.value() == 0:
return "right"
elif MID.value() == 0:
return "middle"
elif SET.value() == 0:
return "set "
elif RST.value() == 0:
return "rst "
if(not(key == 0 and (UP.value() == 0 or DWN.value() == 0 or LFT.value() == 0 or RHT.value() == 0) or MID.value() == 0 or SET.value() == 0 or RST.value() == 0)):
key = 1
return -1
def dispaly():
#code = ["upper","down","Left ","right","middle","set","rst"]
#code = ("upper","down","Left ","right","middle","set","rst")
code = {
0:"upper",
1:"down ",
2:"Left ",
3:"right",
4:"middle",
5:"set ",
6:"rst ",
}
if Key() == code[0]:
font.text(oled,"%s"%(code[0]),32,20,color=1,font_size=24,reverse=False,clear=False,show=True,half_char=True, auto_wrap=True)
elif Key() == code[1]:
font.text(oled,"%s"%(code[1]),32,20,color=1,font_size=24,reverse=False,clear=False,show=True,half_char=True, auto_wrap=True)
elif Key() == code[2]:
font.text(oled,"%s"%(code[2]),32,20,color=1,font_size=24,reverse=False,clear=False,show=True,half_char=True, auto_wrap=True)
elif Key() == code[3]:
font.text(oled,"%s"%(code[3]),32,20,color=1,font_size=24,reverse=False,clear=False,show=True,half_char=True, auto_wrap=True)
elif Key() == code[4]:
font.text(oled,"%s"%(code[4]),32,20,color=1,font_size=24,reverse=False,clear=False,show=True,half_char=True, auto_wrap=True)
elif Key() == code[5]:
font.text(oled,"%s"%(code[5]),32,20,color=1,font_size=24,reverse=False,clear=False,show=True,half_char=True, auto_wrap=True)
elif Key() == code[6]:
font.text(oled,"%s"%(code[6]),32,20,color=1,font_size=24,reverse=False,clear=False,show=True,half_char=True, auto_wrap=True)
# 创建LED函数
def LED():
if Key() == "middle": # 当按下mid键时,反转LED状态
led.value(not led.value())
# while not MID.value():
# pass
# 创建motor函数
def motor():
# 定义PWM小风扇马达对象
文末有福利领取哦~
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
👉**一、Python所有方向的学习路线**
Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。
👉**二、Python必备开发工具**

👉**三、Python视频合集**
观看零基础学习视频,看视频学习是最快捷也是最有效果的方式,跟着视频中老师的思路,从基础到深入,还是很容易入门的。

👉 **四、实战案例**
光学理论是没用的,要学会跟着一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。**(文末领读者福利)**

👉**五、Python练习题**
检查学习结果。

👉**六、面试资料**
我们学习Python必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有阿里大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。


👉因篇幅有限,仅展示部分资料,这份完整版的Python全套学习资料已经上传
**了解详情:https://docs.qq.com/doc/DSnl3ZGlhT1RDaVhV**