height
width
   
< и >
&lt; и &gt;
<ul>
<li></li>
<li></li>
<ul>
  • hidden-desktop - скрыть на DeskTop
  • hidden-phone - скрыть на Mobile
<div class="container border"></div>
<pre><code class="language-html">...</code></pre>

WS2812b LED ленты примеры рабочих sketch

🎈⛓📲🪔
//один бегающий светодиод: каждый раз очищать ленту и
//красить светодиод под номером, который задаётся счётчиком.
//Изменение счётчика закольцевать от 0 до количества светодиодов

#define LED_PIN 6
#define LED_NUM 23
#include <FastLED.h>
CRGB leds[LED_NUM];

void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, LED_NUM);
  FastLED.setBrightness(50);
}

byte counter;
void loop() {
  FastLED.clear();
  leds[counter] = CRGB::Red;
  if (++counter >= LED_NUM) counter = 0;
//  FastLED.show();
  delay(30);
  leds[counter] = CRGB::White;
  if (++counter >= LED_NUM) counter = 0;
  for(int i = 0; i < LED_NUM/2; i++) {
    leds[LED_NUM - 1 - i] = leds[i];
}
  FastLED.show();
  delay(30);
}

count++ увеличивает переменную count на единицу...
count - считать
counter - счетчик

Sketch 2 Red and White Leds run center

Красный и белый цвета бегут в центр от левого и правого краев.


#define LED_PIN 6
#define LED_NUM 23
#include <FastLED.h>
CRGB leds[LED_NUM];

void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, LED_NUM);
  FastLED.setBrightness(50);
}

byte counter;
void loop() {
  FastLED.clear();
  leds[counter] = CRGB::Red;
  if (++counter >= LED_NUM) counter = 0;
//  FastLED.show();
  delay(30);
  leds[counter] = CRGB::White;
  if (++counter >= LED_NUM) counter = 0;
  for(int i = 0; i < LED_NUM/2; i++) {
    leds[LED_NUM - 1 - i] = leds[i];
}
  FastLED.show();
  delay(30);
}

Sketch 3 Fire2012


/// @file    Fire2012.ino
/// @brief   Simple one-dimensional fire animation
/// @example Fire2012.ino

#include <FastLED.h>

#define LED_PIN     6
#define COLOR_ORDER GRB
#define CHIPSET     WS2812
#define NUM_LEDS    23

#define BRIGHTNESS  200
#define FRAMES_PER_SECOND 60

bool gReverseDirection = false;

CRGB leds[NUM_LEDS];

// Forward declaration
void Fire2012();

void setup() {
  delay(3000); // sanity delay
  FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.setBrightness( BRIGHTNESS );
}

void loop()
{
  // Add entropy to random number generator; we use a lot of it.
  random16_add_entropy( random16());

  Fire2012(); // run simulation frame
  
  FastLED.show(); // display this frame
  FastLED.delay(1000 / FRAMES_PER_SECOND);
}

// COOLING: How much does the air cool as it rises?
// Less cooling = taller flames.  More cooling = shorter flames.
// Default 50, suggested range 20-100 
#define COOLING  55

// SPARKING: What chance (out of 255) is there that a new spark will be lit?
// Higher chance = more roaring fire.  Lower chance = more flickery fire.
// Default 120, suggested range 50-200.
#define SPARKING 120


void Fire2012()
{
// Array of temperature readings at each simulation cell
  static uint8_t heat[NUM_LEDS];

  // Step 1.  Cool down every cell a little
    for( int i = 0; i < NUM_LEDS; i++) {
      heat[i] = qsub8( heat[i],  random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
    }
  
    // Step 2.  Heat from each cell drifts 'up' and diffuses a little
    for( int k= NUM_LEDS - 1; k >= 2; k--) {
      heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
    }
    
    // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
    if( random8() < SPARKING ) {
      int y = random8(7);
      heat[y] = qadd8( heat[y], random8(160,255) );
    }

    // Step 4.  Map from heat cells to LED colors
    for( int j = 0; j < NUM_LEDS; j++) {
      CRGB color = HeatColor( heat[j]);
      int pixelnumber;
      if( gReverseDirection ) {
        pixelnumber = (NUM_LEDS-1) - j;
      } else {
        pixelnumber = j;
      }
      leds[pixelnumber] = color;
    }
}

В FastLED "в обратную сторону" обычно означает изменение направления, в котором светодиоды получают данные (инвертирование потока) или реверс порядка обхода светодиодов в эффекте, а не физическое подключение наоборот (что не работает для адресных лент). Это достигается либо программно с помощью функций вроде mirror()(если доступно), либо через изменение индексации в коде (например, от NUM_LEDS(LED_NUM)-1 до 0) для эффектов, а не физическим переподключением.

Password Generator

Generated Password
click to copy
copied
CLICK GENERATE
length:
settings
Яндекс.Метрика