LoginSignup
1
2

電池で駆動するNeoPixel制御ボードのサンプルプログラム①

Last updated at Posted at 2024-05-01

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)
    }    
  }

  
}
1
2
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2