RP2040-ZEROを使ってNeoPixelを制御するサンプルプログラム①です。
NeoPixelカラーLED(6x6)の点灯チェックプログラムです。
組み立て後チェックで使用。
ArduinoIDE バージョン:2.2.1
使用ライブラリAdafruit NeoPixel Library 1.12.0
マイコン:PR2040-ZERO
NeoPixel接続ピン GPIO8
乾電池2本でお外へ持ち出し可能。
//全LEDを徐々に明るくする
//色は6色
#include <Adafruit_NeoPixel.h>
#define LED_PIN 8
#define LED_COUNT 36
// Initialize NeoPixel strip object with LED_COUNT and LED_PIN
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
strip.setBrightness(64); // 明るさ倍率設定 (RGB設定値 * 明るさ倍率、最大255)
}
void loop() {
// Loop through the range of red values from 0 to 255
for (int redValue = 0; redValue <= 96; redValue=redValue+8) {
// Set the color of each LED in the strip
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(redValue, 0, 0));
strip.show(); // Update the LED strip with the new colors
delay(5); // Delay for smoother transition (adjust as needed)
}
}
for (int greenValue = 0; greenValue <= 96; greenValue=greenValue+8) {
// Set the color of each LED in the strip
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(0, greenValue, 0));
strip.show(); // Update the LED strip with the new colors
delay(5); // Delay for smoother transition (adjust as needed)
}
}
for (int blueValue = 0; blueValue <= 96; blueValue=blueValue+8) {
// Set the color of each LED in the strip
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(0, 0, blueValue));
strip.show(); // Update the LED strip with the new colors
delay(5); // Delay for smoother transition (adjust as needed)
}
}
for (int rgValue = 0; rgValue <= 96; rgValue=rgValue+8) {
// Set the color of each LED in the strip
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(rgValue, rgValue, 0));
strip.show(); // Update the LED strip with the new colors
delay(5); // Delay for smoother transition (adjust as needed)
}
}
for (int gbValue = 0; gbValue <= 96; gbValue=gbValue+8) {
// Set the color of each LED in the strip
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(0, gbValue, gbValue));
strip.show(); // Update the LED strip with the new colors
delay(5); // Delay for smoother transition (adjust as needed)
}
}
for (int rbValue = 0; rbValue <= 96; rbValue=rbValue+8) {
// Set the color of each LED in the strip
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(rbValue, 0, rbValue));
strip.show(); // Update the LED strip with the new colors
delay(5); // Delay for smoother transition (adjust as needed)
}
}
}