« UNIT_IR_REMOTE 受信編 | トップページ | UNIT_ENV_III「M5Stack用温湿度気圧センサユニット Ver.3(ENV Ⅲ)」を動かす »

2021年12月30日 (木)

UNIT_RGB_LED「M5Stack用RGB LEDユニット(SK6812)」を動かす

2021/12/30
初版

UNIT_RGB_LED

UNIT_RGB_LED

概要

UNIT_RGB_LED「M5Stack用RGB LEDユニット(SK6812)」を動かす。
ソースは共通になっており、ターゲットのM5Atom,M5StickCPlus,M5Core2をplatformio.iniの内容で切り替えてビルドする。

ソース

src/RGB_SK6812.ino

/* ******************************************************************************* * Copyright (c) 2021 by M5Stack * Equipped with M5Core2 sample source code * 配套 M5Core2 示例源代码 * Visit the website for more information:https://docs.m5stack.com/en/core/core2 * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/core2 * * describe:RGB. 多彩灯 * date:2021/8/11 ******************************************************************************* Please connect to Port B,Control RGB Unit to scroll through three colors of red, green and blue 请连接端口B,控制RGB单元滚动红、绿、蓝三种颜色. */ #ifdef M5C2 #include <M5Core2.h> #endif #ifdef M5STICK_CP #include <M5StickCPlus.h> #endif #ifdef M5ATOM #include <M5Atom.h> #endif #include <Adafruit_NeoPixel.h> #ifdef M5C2 #define PIN 32 #define NUMPIXELS 3 #endif #ifdef M5STICK_CP #define PIN 32 #define NUMPIXELS 3 #endif #ifdef M5ATOM #define PIN 26 #define NUMPIXELS 3 #endif Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); //set number of LEDs, pin number, LED type. 设置灯的数量,控制引脚编号,灯灯类型 void setup() { #ifndef M5ATOM M5.begin(); //Init M5Core2. 初始化 M5Core2 pixels.begin(); //Init the NeoPixel library. 初始化NeoPixel库 M5.Lcd.println(("RGB Example")); #endif #ifdef M5ATOM pixels.begin(); //Init the NeoPixel library. #endif } int i=0,j=1,k=2; void loop() { pixels.setPixelColor(i++, pixels.Color(100, 0, 0)); // Bright red pixels.setPixelColor(j++, pixels.Color(0,100,0)); // Bright green pixels.setPixelColor(k++, pixels.Color(0,0,100)); // Bright blue pixels.show(); //sends the updated color to the hardware. 将更新后的颜色发送到硬件。 delay(100); if(i==3) i=0; else if(j==3) j=0; else if(k==3) k=0; }

platformio.ini

M5Atom用

[env:M5ATOM] platform = espressif32 board = m5stick-c framework = arduino build_flags = -DM5ATOM upload_poert = /dev/ttyUSB0 monitor_speed = 115200 lib_deps = m5stack/M5Atom @ ^0.0.7 fastled/FastLED @ ^3.4.0 adafruit/Adafruit NeoPixel @ ^1.10.3 lib_ldf_mode = deep+

M5Core2用

[env:m5core2] platform = espressif32 board = m5stack-core2 framework = arduino upload_speed = 2000000 monitor_speed = 115200 board_build.partitions = default_16MB.csv build_flags = -DM5C2 -DCORE_DEBUG_LEVEL=4 -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue lib_deps = https://github.com/m5stack/M5Core2.git https://github.com/FastLED/FastLED ;https://github.com/m5stack/M5Core2/blob/master/examples/core2_for_aws/ArduinoECCX08.zip lovyan03/LovyanGFX adafruit/Adafruit BMP280 Library @ ^2.5.0 adafruit/Adafruit Unified Sensor @ ^1.1.4 m5stack/UNIT_ENV @ ^0.0.2 adafruit/Adafruit NeoPixel @ ^1.10.3 lib_ldf_mode = deep+

M5StickCPlus用

[env:M5StickCPlus] platform = espressif32 board = m5stick-c framework = arduino build_flags = -DM5STICK_CP monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = m5stack/M5StickCPlus @ ^0.0.5 tinyu-zhao/FFT @ ^0.0.1 m5stack/UNIT_ENV @ ^0.0.2 adafruit/Adafruit BMP280 Library @ ^2.5.0 adafruit/Adafruit Unified Sensor @ ^1.1.4 adafruit/Adafruit NeoPixel @ ^1.10.3

動作

UNITの3つのLEDが光る。

参考情報

terminal関連:
Bootterm – a developer-friendly serial terminal program

platformio関連:
arduinoフレームワーク用platformio.ini集
Building Core2 FactoryDemo in PlatformIO
VSCodeとPlatformIOでM5Stack Core2開発
M5Stack Core2とVSCode + PlatformIOとでM5Stackプログラミングを始めてみた。

Arduino-IDE関連:
Arduino IDE environment - M5Paper
Arduino IDEのインストールと設定 (Windows, Mac, Linux対応)

M5Stackファミリ関連:
M5Core2 Arduino Install
M5Paper Arduino Install
M5CoreInk Arduino Install
M5Stamp-PICO Arduino Install
M5Stamp-C3 Arduino Install
Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(NTP-CLIENT編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(STARWARS編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(MQTT編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(REST-API編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(OSC編)

以上

|

« UNIT_IR_REMOTE 受信編 | トップページ | UNIT_ENV_III「M5Stack用温湿度気圧センサユニット Ver.3(ENV Ⅲ)」を動かす »

PlatformIO」カテゴリの記事

コメント

この記事へのコメントは終了しました。