/*
* Created by ArduinoGetStarted.com
*
* This example code is in the public domain
*
* Tutorial page: https://arduinogetstarted.com/tutorials/arduino-neopixel-led-strip
*/
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define PIN_NEO_PIXEL 2 // Arduino pin that connects to NeoPixel
#define NUM_PIXELS 9 // The number of LEDs (pixels) on NeoPixel
#define DELAY_INTERVAL 1000 // 250ms pause between each pixel
Adafruit_NeoPixel NeoPixel(NUM_PIXELS, PIN_NEO_PIXEL, NEO_GRB + NEO_KHZ800);
void randomlyLightUpPixelWithBrightness(int delayTime) {
int randomPixel = random(0, NUM_PIXELS); // Вибір випадкового індексу світлодіода
// Генеруємо випадковий колір (R, G, B)
int r = random(0, 256);
int g = random(0, 256);
int b = random(0, 256);
// Вибір випадкової яскравості від 0 до 255
float brightness = random(50, 256) / 255.0; // Масштабуємо до [0.0, 1.0]
// Масштабуємо значення кольору відповідно до яскравості
r = r * brightness;
g = g * brightness;
b = b * brightness;
NeoPixel.clear(); // Вимикаємо всі попередні світлодіоди
NeoPixel.setPixelColor(randomPixel, NeoPixel.Color(r, g, b)); // Задаємо колір зі зміненою яскравістю
NeoPixel.show(); // Оновлення стрічки
delay(delayTime); // Затримка перед наступним вибором
}
void setup() {
NeoPixel.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
//NeoPixel.setBrightness(100);
}
void loop() {
NeoPixel.clear(); // set all pixel colors to 'off'. It only takes effect if pixels.show() is called
int br=0;
randomlyLightUpPixelWithBrightness(1000);
// turn pixels to green one by one with delay between each pixel
for (int pixel = 0; pixel < NUM_PIXELS; pixel++) { // for each pixel
NeoPixel.setPixelColor(pixel, NeoPixel.Color(255, 255, 0)); // it only takes effect if pixels.show() is called
NeoPixel.show(); // send the updated pixel colors to the NeoPixel hardware.
NeoPixel.setBrightness(br+=32);
delay(DELAY_INTERVAL); // pause between each pixel
}
// turn off all pixels for two seconds
NeoPixel.clear();
NeoPixel.show(); // send the updated pixel colors to the NeoPixel hardware.
delay(2000); // off time
// turn on all pixels to red at the same time for two seconds
for (int pixel = 0; pixel < NUM_PIXELS; pixel++) { // for each pixel
NeoPixel.setPixelColor(pixel, NeoPixel.Color(255, 0, 0)); // it only takes effect if pixels.show() is called
}
NeoPixel.show(); // send the updated pixel colors to the NeoPixel hardware.
delay(2000); // on time
// turn off all pixels for one seconds
NeoPixel.clear();
NeoPixel.show(); // send the updated pixel colors to the NeoPixel hardware.
delay(2000); // off time
}