#include "FastLED.h"
#define PIN 3
#define NUMPIXELS 36
CRGB strip[NUMPIXELS];
const int buttonPin = 4;
const int buttonPin2 = 5;
int buttonState = 0;
int buttonState2 = 0;
int k = 0;
void setup()
{
FastLED.addLeds<WS2812, PIN, GRB>(strip, NUMPIXELS);
pinMode(buttonPin, INPUT);
pinMode(buttonPin2, INPUT);
ledss();
}
void ledss(){
//{
//for (int i = 0; i < NUMPIXELS; i++)
FastLED.setBrightness(k);
strip[0] = CRGB::White; // Цвет по умолчанию.
strip[1] = CRGB::White;
strip[2] = CRGB::Red;
strip[3] = CRGB::White;
strip[4] = CRGB::White;
strip[5] = CRGB::Blue;
strip[6] = CRGB::White;
strip[7] = CRGB::Blue;
strip[8] = CRGB::White;
strip[9] = CRGB::Blue;
strip[10] = CRGB::White;
strip[11] = CRGB::White;
strip[12] = CRGB::White;
strip[13] = CRGB::White;
strip[14] = CRGB::White;
strip[15] = CRGB::Red;
strip[16] = CRGB::White;
strip[17] = CRGB::Blue;
strip[18] = CRGB::White;
strip[19] = CRGB::White;
strip[20] = CRGB::White;
strip[21] = CRGB::White;
strip[22] = CRGB::Blue;
strip[23] = CRGB::White;
strip[24] = CRGB::White;
strip[25] = CRGB::Red;
strip[26] = CRGB::White;
strip[27] = CRGB::White;
strip[28] = CRGB::Blue;
strip[29] = CRGB::White;
strip[30] = CRGB::White;
strip[31] = CRGB::Red;
strip[32] = CRGB::White;
strip[33] = CRGB::White;
strip[34] = CRGB::Blue;
strip[35] = CRGB::White;
// }
FastLED.show();
if(k == 0) //и если свет не был включен
{
for(int k=0; k<=255; k++) //то плавно включаем свет
{
FastLED.setBrightness(k);
FastLED.show();
delay(1000); //каждые 10мс увелияение на 1
}
}
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH){
int f = random(0, 255);
// turn LED on:
for (int i = 0; i < NUMPIXELS; i++)
{
//strip[i] = CHSV(random8(),255,255);
strip[i] = CHSV(f,255,255);
}
// Передаем цвета ленте.
FastLED.show();
delay(1000);
}
if (buttonState2 == HIGH)
//{
// turn LED on:
//for (int i = 0; i < NUMPIXELS; i++)
{
strip[0] = CRGB::White; // Цвет по умолчанию.
strip[1] = CRGB::White;
strip[2] = CRGB::Red;
strip[3] = CRGB::White;
strip[4] = CRGB::White;
strip[5] = CRGB::Blue;
strip[6] = CRGB::White;
strip[7] = CRGB::Blue;
strip[8] = CRGB::White;
strip[9] = CRGB::Blue;
strip[10] = CRGB::White;
strip[11] = CRGB::White;
strip[12] = CRGB::White;
strip[13] = CRGB::White;
strip[14] = CRGB::White;
strip[15] = CRGB::Red;
strip[16] = CRGB::White;
strip[17] = CRGB::Blue;
strip[18] = CRGB::White;
strip[19] = CRGB::White;
strip[20] = CRGB::White;
strip[21] = CRGB::White;
strip[22] = CRGB::Blue;
strip[23] = CRGB::White;
strip[24] = CRGB::White;
strip[25] = CRGB::Red;
strip[26] = CRGB::White;
strip[27] = CRGB::White;
strip[28] = CRGB::Blue;
strip[29] = CRGB::White;
strip[30] = CRGB::White;
strip[31] = CRGB::Red;
strip[32] = CRGB::White;
strip[33] = CRGB::White;
strip[34] = CRGB::Blue;
strip[35] = CRGB::White;
//}
// Передаем цвета ленте.
FastLED.show();
delay(1000);
}
}