LED strip ws2812b: Difference between revisions

From wikiluntti
Line 7: Line 7:
Simple code using FastLED package:
Simple code using FastLED package:


<syntaxhiglighting lang="C">
<syntaxhighlight lang="C">
#include <FastLED.h>
#include <FastLED.h>


#define NUM_LEDS 3
#define LED_PIN 5


#define NUM_LEDS 3
CRGB leds[NUM_LEDS];
#define LED_PIN 5


CRGB leds[NUM_LEDS];
void setup () {
 
void setup () {
   FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
   FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
   FastLED.setBrightness(50);
   FastLED.setBrightness(50);
   delay(2000);
   delay(2000);
}
}




void loop () {
void loop () {
   for (int i=0; i<NUM_LEDS; i++){
   for (int i=0; i<NUM_LEDS; i++){
     leds[i] = CRGB::Red;
     leds[i] = CRGB::Red;
Line 35: Line 34:
     FastLED.show();
     FastLED.show();
  }
  }
}
}
</syntaxhiglighting>
</syntaxhighlight>

Revision as of 18:01, 8 November 2024

Introduction

300 LEDs, 5m,

Programming

Simple code using FastLED package:

#include <FastLED.h>

#define NUM_LEDS 3
#define LED_PIN 5

CRGB leds[NUM_LEDS];

void setup () {
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(50);
  delay(2000);
}


void loop () {
  for (int i=0; i<NUM_LEDS; i++){
    leds[i] = CRGB::Red;
    FastLED.show();
    delay(500);
    leds[i] = CRGB::Green;
    FastLED.show();
    delay(500);

    leds[i] = CRGB::Black;
    FastLED.show();
 }
}