#include <Adafruit_NeoPixel.h>
#define LED_PIN 4
#define NUM_LEDS 8
Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show(); // Очистить ленту (выключить все светодиоды)
strip.setBrightness(255); // Установить яркость (0-255)
}
void loop() {
//rainbow();
//fire();
//random_color();
//color_switch();
//pulseEffect(255, 0, 0); // Красный цвет
//meteorEffect(255, 0, 0, 10, 64);
//confettiEffect();
//colorCycle();
//custom();
//starryNight();
//colorExplosion();
}
void colorExplosion() {
int pos = random(NUM_LEDS);
int r = random(256);
int g = random(256);
int b = random(256);
strip.setPixelColor(pos, strip.Color(r, g, b));
strip.show();
delay(50);
// Затухание всех светодиодов
for (int i = 0; i < NUM_LEDS; i++) {
uint32_t color = strip.getPixelColor(i);
uint8_t r = (color >> 16) & 0xFF;
uint8_t g = (color >> 8) & 0xFF;
uint8_t b = color & 0xFF;
if (r > 10) r -= 10; else r = 0;
if (g > 10) g -= 10; else g = 0;
if (b > 10) b -= 10; else b = 0;
strip.setPixelColor(i, strip.Color(r, g, b));
}
}
void starryNight() {
// Зажигаем случайные светодиоды
for (int i = 0; i < NUM_LEDS / 10; i++) {
int pos = random(NUM_LEDS);
int brightness = random(50, 255);
strip.setPixelColor(pos, strip.Color(brightness, brightness, brightness));
}
strip.show();
delay(100);
// Постепенное затухание всех светодиодов
for (int i = 0; i < NUM_LEDS; i++) {
uint32_t color = strip.getPixelColor(i);
uint8_t r = (color >> 16) & 0xFF;
uint8_t g = (color >> 8) & 0xFF;
uint8_t b = color & 0xFF;
if (r > 10) r -= 10; else r = 0;
if (g > 10) g -= 10; else g = 0;
if (b > 10) b -= 10; else b = 0;
strip.setPixelColor(i, strip.Color(r, g, b));
}
}
void colorCycle() {
static uint8_t hue = 0;
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, strip.ColorHSV(hue * 256, 255, 255)); // Используем HSV для плавного перехода
}
strip.show();
hue++;
delay(20);
}
void rainbow() {
for (int j = 0; j < 256; j++) {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, Wheel((i + j) & 255));
}
strip.show();
delay(20);
}
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void rainbow_() {
static uint16_t hue = 0;
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, strip.ColorHSV(hue + (i * 65536 / NUM_LEDS), 255, 255));
}
strip.show();
hue += 256; // Изменяем оттенок для плавного перехода
delay(20);
}
void fire() {
for (int i = 0; i < NUM_LEDS; i++) {
int flicker = random(0, 150);
int r = 255 - flicker;
int g = 100 - flicker / 2;
int b = 0;
strip.setPixelColor(i, strip.Color(r, g, b));
}
strip.show();
delay(random(50, 150));
}
void random_color() {
int index = random(NUM_LEDS);
strip.setPixelColor(index, strip.Color(random(255), random(255), random(255)));
strip.show();
delay(100);
}
void color_switch() {
static uint16_t hue = 0;
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, strip.ColorHSV(hue, 255, 255));
}
strip.show();
hue += 256; // Меняем оттенок
delay(50);
}
void pulseEffect(uint8_t r, uint8_t g, uint8_t b) {
for (int brightness = 0; brightness < 256; brightness++) {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, strip.Color(r * brightness / 255, g * brightness / 255, b * brightness / 255));
}
strip.show();
delay(10);
}
for (int brightness = 255; brightness >= 0; brightness--) {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, strip.Color(r * brightness / 255, g * brightness / 255, b * brightness / 255));
}
strip.show();
delay(10);
}
}
void confettiEffect() {
int pos = random(NUM_LEDS);
int r = random(256);
int g = random(256);
int b = random(256);
strip.setPixelColor(pos, strip.Color(r, g, b));
strip.show();
delay(50);
// Постепенное затухание всех светодиодов
for (int i = 0; i < NUM_LEDS; i++) {
uint32_t color = strip.getPixelColor(i);
uint8_t r = (color >> 16) & 0xFF;
uint8_t g = (color >> 8) & 0xFF;
uint8_t b = color & 0xFF;
if (r > 10) r -= 10; else r = 0;
if (g > 10) g -= 10; else g = 0;
if (b > 10) b -= 10; else b = 0;
strip.setPixelColor(i, strip.Color(r, g, b));
}
}
void meteorEffect(uint8_t r, uint8_t g, uint8_t b, uint8_t meteorSize, uint8_t decay) {
for (int i = 0; i < NUM_LEDS + meteorSize; i++) {
// Зажигаем новый светодиод
if (i < NUM_LEDS) {
strip.setPixelColor(i, strip.Color(r, g, b));
}
// Затухание хвоста
for (int j = 0; j < meteorSize; j++) {
if (i - j >= 0 && i - j < NUM_LEDS) {
int brightness = (255 * (meteorSize - j)) / meteorSize;
strip.setPixelColor(i - j, strip.Color(r * brightness / 255, g * brightness / 255, b * brightness / 255));
}
}
strip.show();
delay(30);
// Выключаем светодиоды за пределами ленты
if (i - meteorSize >= 0 && i - meteorSize < NUM_LEDS) {
strip.setPixelColor(i - meteorSize, strip.Color(0, 0, 0));
}
}
}
void custom() {
}
/*
#include <FastLED.h>
#define LED_PIN 4
#define CHIPSET WS2811
#define NUM_LEDS 8
CRGB leds[NUM_LEDS];
byte heat[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
}
void loop() {
//fill_solid(leds, NUM_LEDS, CRGB::Red); // Красный цвет для всех
//fill_rainbow(leds, NUM_LEDS, 0, 10);
//FastLED.show();
//rainbow();
//fire();
//randcolor();
//color_switch();
custom();
}
void rainbow() {
static uint8_t hue = 0;
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(hue + (i * 10), 255, 255);
}
FastLED.show();
hue++; // Меняем оттенок
delay(20);
}
void fire() {
for (int i = NUM_LEDS - 1; i > 0; i--) {
leds[i] = leds[i - 1]; // Смещение цвета вверх
}
leds[0] = CRGB(random8(200, 255), random8(50, 150), 0); // Новый "огненный" пиксель
FastLED.show();
delay(100); // Скорость анимации
}
void randcolor() {
leds[random(NUM_LEDS)] = CRGB(random(255), random(255), random(255));
FastLED.show();
delay(100);
}
void color_switch() {
static uint8_t hue = 0;
fill_rainbow(leds, NUM_LEDS, hue, 7);
FastLED.show();
hue++;
delay(20);
}
void custom() {
leds[NUM_LEDS] = CRGB(100, 100, 100);
FastLED.show();
delay(100);
}
*/