k210 lights up the LED light

 The wiring of the 3 led lights on the development board is shown in the figure.

There are two main modules used to light up the LED lights, as follows:

fm.register(pin, function, force=False)
【pin】chip external IO
【function】chip function
【force】=True will force registration and clear the previous registration record

Example: fm.register(12, fm.fpioa.GPIO0,force=True)
means to register external IO12 to internal GPIO0

GPIO(ID,MODE,PULL,VALUE)
GPIO object
     [ID] internal GPIO number;
     [MODE] GPIO mode;
            GPIO.IN: input mode
            GPIO.OUT: output mode
     [PULL]
            GPIO.PULL_UP: pull up
            GPIO.PULL_DOWN: Pull-down
            GPIO.PULL_NONE: None
     [value] GPIO initialization level
            1: high level
            0: low level

There is also the use method after creating the led object:

Usage method:
GPIO.value([value])
      [value] GPIO output level value;
              1: high level
              0: low level
* When the parameter is empty in input mode, it means to obtain the current IO input level value.

 The following is the program to turn on the blue light, green light, and red light in a cycle. This program is relatively simple, and it has been tested in practice. If there is no problem, it can be copied and run directly.

from Maix import GPIO as gpio   # 导入maix中的GPIO取名为gpio
from fpioa_manager import fm    # 导入fpioa_manager中的fm注册小模块
import utime as t               # 导入时间模块命名为t

fm.register(12, fm.fpioa.GPIO0, force = True) # 注册外部12口到内部gpio0
fm.register(13, fm.fpioa.GPIO1, force = True) # 注册外部13口到内部gpio1
fm.register(14, fm.fpioa.GPIO2, force = True) # 注册外部14口到内部gpio2

led_b = gpio(gpio.GPIO0, gpio.OUT)  # 蓝灯为(内部gpio0口,输出模式)
led_g = gpio(gpio.GPIO1, gpio.OUT)  # 绿灯为(内部gpio1口,输出模式)
led_r = gpio(gpio.GPIO2, gpio.OUT)  # 红灯为(内部gpio2口,输出模式)

while(1):
    led_b.value(0)  # 蓝灯的值为0(点亮)
    t.sleep(1)      # 延时1秒
    led_b.value(1)  # 蓝灯的值为1(熄灭)
    t.sleep(1)      # 延时1秒
    led_g.value(0)  # 绿灯的值为0(点亮)
    t.sleep(1)      # 延时1秒
    led_g.value(1)  # 绿灯的值为0(熄灭)
    t.sleep(1)      # 延时1秒
    led_r.value(0)  # 红灯的值为0(点亮)
    t.sleep(1)      # 延时1秒
    led_r.value(1)  # 红灯的值为0(熄灭)
    t.sleep(1)      # 延时1秒

If there is something wrong with what I wrote here, I hope you can point it out directly. Thank you all for this! If you think it's okay, I hope you give a free like or forward it to more people in need. Thanks!

Guess you like

Origin blog.csdn.net/xingyuncao520025/article/details/130443014