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>
#include
Директива, позволяющая подключать в проект дополнительные файлы с кодом.
#include <Servo.h> // подключает библиотеку Servo.h
#include "Servo.h" // подключает библиотеку Servo.h
В чём отличие <Servo.h> и "Servo.h"? Когда указываем название "в кавычках", компилятор сначала ищет файл в папке со скетчем, а затем в папке с библиотеками. При использовании <галочек> компилятор ищет файл только в папке с библиотеками

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

Sketch 4 With Fading Tail

Движется либо вперед (работает) и назад (не работает!) с хвостиком, либо только вперед с хвостиком



// Knight Rider Type Patterns by Chemdoc77
// Based on the DemoReel100 example of the FastLED library.
// Goes either back and forth with a tail or goes only forward with a tail.

#include "FastLED.h"
#define NUM_LEDS 23
#define chipset NEOPIXEL //use WS2812B if not using NEOPIXEL products.
#define Data_pin 6

#define BRIGHTEST 40  // the BRIGHTEST range is from 0 to 255. Диапазон максимальной яркости — от 0 до 255.

CRGB leds[NUM_LEDS];

//pre-declaration of functions
void cd77_sinelon_oneway();
//void cd77_sinelon();


void setup() {
  delay(2000); // power-up safety delay
  FastLED.addLeds(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); // uncomment ",GRB" if you use the WS2812B chipset.
  FastLED.setBrightness(BRIGHTEST);

}

void loop () {

  cd77_sinelon_oneway(30, CRGB::Red);
  //cd77_sinelon(30, CRGB::Red);
}

// Functions ======================

void cd77_sinelon_oneway(uint8_t BPM, CRGB color)
{
  // a colored dot going in one direction with fading tail
  // Цветная точка, движущаяся в одном направлении с затухающим хвостом 
  fadeToBlackBy( leds, NUM_LEDS, 10);  //change 10 to smaller or larger number to adjust the length of the tail.
  uint8_t u = beat8(BPM, 0); //BPM will allow you to adjust the speed the dot is moving.
  uint8_t pos = map(u, 0, 255, 0, NUM_LEDS);
  leds[pos] = color;
  FastLED.show();
}

void cd77_sinelon(uint8_t BPM, CRGB color )
{
  // a colored dot sweeping back and forth, with fading tail
  // Цветная точка, движущаяся вперед и назад, с затухающим хвостом
  fadeToBlackBy( leds, NUM_LEDS, 20); //change 20 to smaller or larger number to adjust the length of the tail. чтобы отрегулировать длину хвоста
  uint8_t pos = beatsin16(BPM, 0, NUM_LEDS); //BPM will allow you to adjust the speed the dot is moving.
  //uint8_t u = beat8(BPM, 0); //BPM will allow you to adjust the speed the dot is moving.BPM позволит вам регулировать скорость перемещения точки.
  //uint8_t pos = map(u, 0, 255, 0, NUM_LEDS);
  leds[pos] = color;
  FastLED.show();
}

Sketch 5 CD77_police_lights

На крышу полицейского бобика, не хуже заводских.
https://github.com/chemdoc77/CD77_FastLED/tree/master
нужно установить дополнительные библиотеки и комментируем лишние эффекты в Time_performance.h


//Police_Lights by Chemdoc77
// This code is based on the police_lightsONE and police_lightsALL code:
//in Funkboxing by Teldredge 
//at http://funkboxing.com/wordpress/wp-content/_postfiles/sk_qLEDFX_POST.ino
// uses the color array concept in color bar chase code by Richard Bailey 
//at https://gist.github.com/brencerddwr/85cc31227d2fcb0fc3818ab6a488c836
//uses the Time Performance code by Mark Kriegsman
//at https://gist.github.com/kriegsman/a916be18d32ec675fea8
 

#include "FastLED.h"

#define NUM_LEDS 23
#define Data_Pin 6

#define chipset NEOPIXEL 
#define BRIGHTNESS  50

 CRGB leds[NUM_LEDS];   

//Palette Code 
CRGBPalette16 currentPalette;
TBlendType    currentBlending;
//extern const TProgmemRGBGradientPalettePtr gGradientPalettes[]; //так не скомпилировалось
extern const TProgmemRGBGradientPaletteRef gGradientPalettes[];

//Time Performance code

uint32_t gTimeCodeBase = 0;
uint32_t gTimeCode = 0;
uint32_t gLastTimeCodeDoneAt = 0;
uint32_t gLastTimeCodeDoneFrom = 0;

#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

//random function variables
int  random_carray=0; 
int random_segment = 2;

#include "Police_lights.h"
#include "Time_performance.h"



void setup() { 
 delay(2000); // power-up safety delay 
 FastLED.addLeds(leds, NUM_LEDS); 
 FastLED.setBrightness(BRIGHTNESS);
 FastLED.setMaxPowerInVoltsAndMilliamps(5,1500); // sets max amperage to 1500 milliamps (1.5 amps)
 set_max_power_indicator_LED(13);

 //Time Performance code
 RestartPerformance();
 }

void loop(){  
   gTimeCode = millis() - gTimeCodeBase;   
   Performance();

}

Sketch 6 Kludgeware

Turn lights from green to blue from left too right and Turn lights from blue to magenta from right to left
https://youtu.be/rPvGLSuMaLA?si=sb7d8hcAM2xz-Q00
https://github.com/hendog993/Youtube_arduino/blob/master/LEDStrip.ino


#include <FastLED.h>
#define LED_PIN 6
#define NUM_LEDS 23

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2812, LED_PIN, RGB> (leds, NUM_LEDS);
  FastLED.setMaxPowerInVoltsAndMilliamps(5, 500);
  FastLED.clear();
  FastLED.show();

}

void loop() {
  // Turn lights from green to blue from left too right
  for (int i=0; i<NUM_LEDS; i++){
    leds[i] = CRGB(0, 255 - 20*i, 20*i);
    FastLED.setBrightness(6*i);
    FastLED.show();
    delay(50);
  }
  // Turn lights from blue to magenta from right to left
  for (int i=NUM_LEDS; i>0; i--){
    leds[i] = CRGB(20*i, 0, 255-20*i);
    FastLED.setBrightness(60-2*i);
    FastLED.show();
    delay(50);
  }
}

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

Random Password Generator

Generate Password
Яндекс.Метрика