새글

    최근 30일 이내 등록된 새글 이에요.
  • 응용[code]#include <FastLED.h>#define LED_PIN     6  // WS2812B 데이터 핀이 연결된 아두이노 핀 번호#define NUM_LEDS    64 // 8x8 매트릭스의 총 LED 개수#define MATRIX_SIZE 8  // 매트릭스 크기 (8x8)// LED 배열 선언CRGB leds[NUM_LEDS];// 웜 화이트 색상 정의: CRGB(R, G, B)// 255, 160, 40은 따뜻한 느낌을 주는 예시 값입니다.const CRGB WARM_WHITE = CRGB(255, 160, 40); // =======================================================// 매트릭스 좌표를 LED 인덱스로 변환하는 함수 (Zig-zag)// =======================================================int XY(int x, int y) {  if (x >= MATRIX_SIZE) x = MATRIX_SIZE - 1;  if (y >= MATRIX_SIZE) y = MATRIX_SIZE - 1;  if (y % 2 == 0) {    return y * MATRIX_SIZE + x;  } else {    return (y + 1) * MATRIX_SIZE - 1 - x;  }}// 폰트 데이터 및 draw_hi 함수는 이전과 동일합니다.// (코드의 간결함을 위해 아래 예시에서는 생략합니다.)byte font_h[] = {  0b10001,   0b10001,   0b11111,   0b10001,   0b10001};byte font_i[] = {  0b11111,   0b00100,   0b00100,   0b00100,   0b11111};void draw_hi(CRGB color) {  FastLED.clear();  // 'h' 그리기 (시작 x=1, y=1)  for (int y = 0; y < 5; y++) {    for (int x = 0; x < 5; x++) {      if ((font_h[y] >> (4 - x)) & 0x01) {        leds[XY(x + 1, y + 1)] = color;      }    }  }  // 'i' 그리기 (시작 x=5, y=1)  for (int y = 0; y < 5; y++) {    for (int x = 0; x < 5; x++) {      if ((font_i[y] >> (4 - x)) & 0x01) {        leds[XY(x + 5, y + 1)] = color;       }    }  }}// =======================================================// Arduino Setup// =======================================================void setup() {  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);  FastLED.setCorrection(TypicalLEDStrip);  FastLED.setBrightness(255); // 기본 밝기 최대 설정  FastLED.clear();  FastLED.show();}// =======================================================// Arduino Loop// =======================================================void loop() {    // 1단계: "hi" 출력 및 2단계: 심박수 효과 (이전 코드와 동일)  CRGB hi_color = CRGB::Cyan;  draw_hi(hi_color);    int heart_beat_count = 5;  for (int beat = 0; beat < heart_beat_count; beat++) {    for (int brightness = 0; brightness <= 255; brightness += 5) {      FastLED.setBrightness(brightness);      FastLED.show();      delay(10);    }    for (int brightness = 255; brightness >= 0; brightness -= 5) {      FastLED.setBrightness(brightness);      FastLED.show();      delay(10);    }  }  // 텍스트를 다시 최대 밝기로 띄워 놓음  FastLED.setBrightness(255);   FastLED.show();  delay(500);  // ------------------------------------------------  // 3단계: 픽셀 흩어짐 효과 (Pixel Scatter)  // ------------------------------------------------  int lit_pixels[NUM_LEDS];  int lit_count = 0;  for(int i = 0; i < NUM_LEDS; i++) {    // 켜져 있는 픽셀만 계산 (색상이 0,0,0이 아닌 경우)    if (leds[i].r > 0 || leds[i].g > 0 || leds[i].b > 0) {      lit_pixels[lit_count++] = i;    }  }    while(lit_count > 0) {    int rand_index = random(lit_count);    int led_index_to_turn_off = lit_pixels[rand_index];    // 해당 픽셀 끄기    leds[led_index_to_turn_off] = CRGB::Black;    FastLED.show();    // 배열에서 제거    lit_pixels[rand_index] = lit_pixels[lit_count - 1];    lit_count--;        delay(50);   }  // ------------------------------------------------  // 4단계: 웜 화이트로 유지  // ------------------------------------------------    // 매트릭스 전체를 WARM_WHITE 색상으로 설정  FastLED.showColor(WARM_WHITE);  FastLED.show();    // 설정된 색상을 무기한 유지합니다.   // Loop가 반복되지 않도록 while(true)로 무한 대기합니다.  while(true) {    // 매트릭스가 웜 화이트 상태를 유지하도록 대기    delay(100);   }}[/code]
    mr_maker 2025-10-14 아두이노 연습스케치
  • [code]#include <FastLED.h>#define LED_PIN     6  // WS2812B 데이터 핀이 연결된 아두이노 핀 번호#define NUM_LEDS    64 // 8x8 매트릭스의 총 LED 개수// FastLED는 LED 배열을 CRGB 타입으로 CRGB leds[NUM_LEDS];void setup() {  // WS2812B LED 배열 설정 (LED 타입, 핀 번호, 색상 순서)  // 대부분의 WS2812B는 GRB 색상 순서를 사용.  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);  // 밝기 설정 (0-255)  FastLED.setBrightness(50); }void loop() {  // 모든 LED를 빨간색으로 on   for (int i = 0; i < NUM_LEDS; i++) {    leds[i] = CRGB::Red; // i번째 LED를 빨간색으로 설정  }  FastLED.show();        // 설정된 색상을 LED에 반영  delay(1000);           // 1초 대기  // 모든 LED를 파란색으로 켜기  for (int i = 0; i < NUM_LEDS; i++) {    leds[i] = CRGB::Blue; // i번째 LED를 파란색으로 설정  }  FastLED.show();  delay(1000);  // 모든 LED 끄기 (검은색)  FastLED.clear(); // 모든 LED를 검은색으로 설정  FastLED.show();  delay(1000);}[/code]https://youtu.be/kBXYnpznscc?si=swvHTF9gbyAFtYqI
    mr_maker 2025-10-14 아두이노 연습스케치
  • [code] #include <Adafruit_NeoPixel.h>#define LED_PIN 6      // 데이터 핀 (D6)#define LED_COUNT 64   // 8x8 = 64개 LEDAdafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);void setup() {  strip.begin();  strip.setBrightness(25); // 무드등용 밝기 (0~255 중)  strip.show(); // 모든 LED를 꺼둠}void loop() {  // 1️⃣ 무지개 색상 순환 (천천히, 부드럽게)  for (int cycle = 0; cycle < 2; cycle++) { // 2바퀴 정도만 돌고    for (int j = 0; j < 256; j++) {      for (int i = 0; i < strip.numPixels(); i++) {        strip.setPixelColor(i, Wheel((i + j) & 255));      }      strip.show();      delay(20); // 속도 조절 (커질수록 느림)    }  }  // 2️⃣ 서서히 흰색(주광빛)으로 전환  fadeToWhite();    // 3️⃣ 유지 (무드등 상태)  delay(10000); // 10초 유지 (원하면 계속 켜두기)}// --- 부드러운 흰색 전환 함수 ---void fadeToWhite() {  for (int b = 0; b <= 255; b++) {    uint8_t r = map(b, 0, 255, 255, 255); // 흰색 R    uint8_t g = map(b, 0, 255, 255, 255); // 흰색 G    uint8_t bl = map(b, 0, 255, 255, 255); // 흰색 B    for (int i = 0; i < strip.numPixels(); i++) {      // 무지개색에서 흰색으로 서서히 이동      uint32_t currentColor = strip.getPixelColor(i);      uint8_t cr = (currentColor >> 16) & 0xFF;      uint8_t cg = (currentColor >> 8) & 0xFF;      uint8_t cb = currentColor & 0xFF;      uint8_t nr = cr + (r - cr) * b / 255.0;      uint8_t ng = cg + (g - cg) * b / 255.0;      uint8_t nb = cb + (bl - cb) * b / 255.0;      strip.setPixelColor(i, nr, ng, nb);    }    strip.show();    delay(20);  }}// --- 무지개 색상 생성 함수 ---uint32_t Wheel(byte WheelPos) {  WheelPos = 255 - WheelPos;  if (WheelPos < 85) {    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);  } else if (WheelPos < 170) {    WheelPos -= 85;    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);  } else {    WheelPos -= 170;    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);  }}[/code]
    mr_maker 2025-10-14 아두이노 연습스케치