Skip to content

Commit 4958007

Browse files
committed
Add Unit RGB example
1 parent fdbb037 commit 4958007

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2023 by M5Stack
4+
* Equipped with M5CoreS3 sample source code
5+
* 配套 M5CoreS3 示例源代码
6+
* Visit for more information: https://docs.m5stack.com/en/unit/rgb
7+
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/rgb
8+
*
9+
* Describe: RGB. 多彩灯
10+
* Date: 2023/8/24
11+
*******************************************************************************
12+
Please connect to Port B(8,9),Control RGB Unit to scroll through three
13+
colors of red, green and blue.
14+
请连接端口B(8,9),控制RGB单元滚动红、绿、蓝三种颜色.
15+
*/
16+
17+
#include <M5CoreS3.h>
18+
#include <Adafruit_NeoPixel.h>
19+
20+
#define PIN 9 //定义NeoPixel的控制引脚
21+
#define NUMPIXELS 3 //定义NeoPixel控制灯灯数量
22+
23+
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(
24+
NUMPIXELS, PIN,
25+
NEO_GRB + NEO_KHZ800); // set number of LEDs, pin number, LED type.
26+
// 设置灯的数量,控制引脚编号,灯灯类型
27+
28+
void setup() {
29+
M5.begin(); // Init M5CoreS3. 初始化M5CoreS3
30+
M5.Axp.powerModeSet(POWER_MODE_USB_IN_BUS_OUT);
31+
pixels.begin(); // Init the NeoPixel. 初始化NeoPixel
32+
M5.Lcd.setTextSize(2);
33+
M5.Lcd.setCursor(90, 0);
34+
M5.Lcd.println(("RGB Example"));
35+
}
36+
37+
int i = 0, j = 1, k = 2;
38+
39+
void loop() {
40+
pixels.setPixelColor(i++, pixels.Color(100, 0, 0)); // Bright red
41+
pixels.setPixelColor(j++, pixels.Color(0, 100, 0)); // Bright green
42+
pixels.setPixelColor(k++, pixels.Color(0, 0, 100)); // Bright blue
43+
pixels.show(); // sends the updated color to the hardware.
44+
// 将更新后的颜色发送到硬件。
45+
delay(100);
46+
if (i == 3)
47+
i = 0;
48+
else if (j == 3)
49+
j = 0;
50+
else if (k == 3)
51+
k = 0;
52+
}

src/M5CoreS3.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ void M5CoreS3::begin(bool LCDEnable, bool USBSerialEnable, bool I2CEnable) {
2222

2323
if (LCDEnable) {
2424
Axp.coreS3_init();
25-
Lcd.clear();
2625
Lcd.begin();
26+
Lcd.clear();
2727
}
2828

2929
if (I2CEnable) {

0 commit comments

Comments
 (0)