OpenMV4H7教程(一)点亮LED
一、最基础的入门,点亮LED灯
(1)使用PuTTY,选COM5或其他,波特率9600
(2)在窗口输入命令
from pyb import LED
LED(3).on()
LED蓝灯亮
LED(1).on()
>>> LED(2).on()
>>> LED(1).off()
>>> LED(2).on()
>>> LED(2).off()
>>> LED(3).on()
>>> LED(3).off()
>>> LED(4).on()
1是红;2是绿;3是蓝
二、循环流水灯
from pyb import LED
>>> import utime
>>> for i in range(2,4):
... LED(i).off()
... while 1:
... for i in range(2,4):
... LED(i).on()
... utime.sleep(1)
... LED(i).off()
三、用开关控制LED灯
开关接地和P9,用开关控制LED(3)即蓝灯
from pyb import Pin,LED
KEY=Pin('P9',Pin.IN,Pin.PULL_UP)
while 1:
if KEY.value()==0: #留意不要漏了冒号
LED(3).on()
else:
LED(3).off()
四、接线图
五、常用命令:如果
if <条件判断1>:
<执行1>
elif <条件判断2>:
<执行2>
elif <条件判断3>:
<执行3>
else:
<执行4>
例子:
age = 20
if age >= 6: #如果age大于或等于6,就打印**
print(‘teenager’)
elif age >= 18: #如果age大于或等于18,就打印*
print(‘adult’)
else: #否则,就打印
print(‘kid’)
from pyb import Pin,LED
KEY9=Pin('P9',Pin.IN,Pin.PULL_UP)
KEY8=Pin('P8',Pin.IN,Pin.PULL_UP)
KEY7=Pin('P7',Pin.IN,Pin.PULL_UP)
while 1:
if KEY9.value()==0: #留意不要漏了冒号
LED(3).on()
elif KEY8.value()==0:
LED(2).on()
elif KEY7.value()==0:
LED(1).on()
else:
LED(3).off()
LED(2).off()
LED(1).off()