Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

M5stamp S3でNeoPixel対応LEDテープを光らせる

実際のところ

レインボーカラーで段階的に色が変わっていくサンプル
後々のため、I2Cでステータスを出すコードもコメントアウトで残しておきます

#include <M5Unified.h>
#include <FastLED.h>
//#include <Wire.h>

// LED Strip Configuration
#define LED_PIN 3       // GPIO pin for LED data (change as needed)
#define NUM_LEDS 24     // Number of LEDs in your strip
#define BRIGHTNESS 50   // LED brightness (0-255)

// I2C Pin Configuration
#define I2C_SDA 13
#define I2C_SCL 15

CRGB leds[NUM_LEDS];

void setup() {
  auto cfg = M5.config();
  M5.begin(cfg);
  
  // Initialize LED strip
  FastLED.addLeds<SK6812, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
  
  // Initialize I2C (not used in this example, but ready for future use)
  //Wire.begin(I2C_SDA, I2C_SCL);
  
  Serial.println("M5Stamp S3 SK6812 LED Strip Test");
  Serial.printf("LED Data Pin: %d\n", LED_PIN);
  Serial.printf("I2C Pins: SDA=%d, SCL=%d\n", I2C_SDA, I2C_SCL);
}

void loop() {
  // Rainbow effect for LED strip
  static uint8_t hue = 0;
  for(int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CHSV(hue + (i * 10), 255, 255);
  }
  FastLED.show();
  
  // Gradually change hue
  EVERY_N_MILLISECONDS(20) {
    hue++;
  }

  // Print status message every second
  EVERY_N_SECONDS(1) {
    Serial.println("LED animation running...");
  }

  // Example of I2C usage (commented out)
  // EVERY_N_SECONDS(5) {
  //   // Perform I2C communication here
  //   // For example: read from an I2C sensor
  //   // Wire.beginTransmission(SENSOR_ADDRESS);
  //   // Wire.write(REGISTER_ADDRESS);
  //   // Wire.endTransmission();
  //   // Wire.requestFrom(SENSOR_ADDRESS, 2);
  //   // if (Wire.available()) {
  //   //   int sensorData = Wire.read() << 8 | Wire.read();
  //   //   Serial.printf("Sensor data: %d\n", sensorData);
  //   // }
  // }
}