【Smart network desk lamp】8. Maix bit driver RGB
[Copy link]
Past Sharing
[2022 Digi-Key Innovation Design Competition] Latest unboxing post
[2022 Digi-Key Innovation Design Competition] 1. ESP32-S2 environment construction and lighting
[Smart Network Desk Lamp] 2. Setting system time and printing
[Smart Network Desk Lamp] 3. ESP32-S2 + lvgl use
[Smart Network Desk Lamp] 4. ESP32-S2 onboard button use
[Smart Network Desk Lamp] 5. ESP32-S2 uses sntp for network time synchronization
[Smart Network Desk Lamp] 6. ESP32-S2 solves the problem of excessive RAM space overhead
Preface
It has been a long time since I updated it. The main reason is that it took a long time to add Alibaba Cloud function to ESP32S2. The resources were not enough. There were many problems when ESP32S2 used lvgl + Alibaba Cloud service at the same time, which wasted some time. This post will not explain it for the time being, but mainly record the process of learning maix bit driver RGB.
This post does not explain the environment setup. The official tutorial is very detailed. See https://wiki.sipeed.com/soft/maixpy/zh/get_started/env_install_driver.html
Driving Process
1. View the schematic
As shown below, the green, red and blue RGB LEDs are connected to IO12, 13 and 14 respectively, and the LED turns on when the pin is pulled low, and turns off when the pin is pulled high.
2. Code Implementation
Open MaixPy IDE, click Tools->Open Terminal in the menu bar, enter our code in the interrupt, and debug.
The code is implemented as follows. The meaning of each sentence can be found in the official API manual:
from fpioa_manager import fm
from Maix import GPIO
import utime
io_led_green = 12
io_led_red = 13
io_led_blue = 14
fm.register(io_led_green, fm.fpioa.GPIO0)
fm.register(io_led_red, fm.fpioa.GPIO1)
fm.register(io_led_blue, fm.fpioa.GPIO2)
led_g=GPIO(GPIO.GPIO0, GPIO.OUT)
led_r=GPIO(GPIO.GPIO1, GPIO.OUT)
led_b=GPIO(GPIO.GPIO2, GPIO.OUT)
while(True):
led_r.value(0)
utime.sleep_ms(500)
led_r.value(1)
utime.sleep_ms(500)
led_g.value(0)
utime.sleep_ms(500)
led_g.value(1)
utime.sleep_ms(500)
led_b.value(0)
utime.sleep_ms(500)
led_b.value(1)
utime.sleep_ms(500)
The meaning of the above code is briefly described as follows: IO12 is mapped to GPIO0, IO13 is mapped to GPIO1, and IO14 is mapped to GPIO2, and then all are set to output mode, and the green, red, and blue LED running lights are controlled to flash periodically in an infinite loop.
Achieve results
As shown below:
点击上图查看Gif动图
|