#include <Adafruit_NeoPixel.h>
#define PIN_LED 13
#define NUM_LEDS 12
#define BTN_MODE 14
#define BTN_LUXE_UP 27
#define BTN_LUXE_DOWN 26
#define BTN_ON_OFF 25
Adafruit_NeoPixel strip(NUM_LEDS, PIN_LED, NEO_GRB + NEO_KHZ800);
// Төлөв хадгалах хувьсагчууд
uint8_t brightness = 128; // 0 - 255
uint8_t mode = 0;
bool isOn = true;
void setup() {
Serial.begin(115200);
strip.begin();
strip.setBrightness(brightness);
strip.show();
pinMode(BTN_MODE, INPUT_PULLUP);
pinMode(BTN_LUXE_UP, INPUT_PULLUP);
pinMode(BTN_LUXE_DOWN, INPUT_PULLUP);
pinMode(BTN_ON_OFF, INPUT_PULLUP);
}
void loop() {
if (digitalRead(BTN_MODE) == LOW) {
delay(200); // debounce
mode = (mode + 1) % 5;
Serial.println("Mode changed");
}
if (digitalRead(BTN_LUXE_UP) == LOW) {
delay(200);
brightness = min(255, brightness + 25);
strip.setBrightness(brightness);
Serial.println("Brightness up");
}
if (digitalRead(BTN_LUXE_DOWN) == LOW) {
delay(200);
brightness = max(0, brightness - 25);
strip.setBrightness(brightness);
Serial.println("Brightness down");
}
if (digitalRead(BTN_ON_OFF) == LOW) {
delay(200);
isOn = !isOn;
Serial.println(isOn ? "LED ON" : "LED OFF");
}
if (isOn) {
showColorMode(mode);
} else {
strip.clear();
strip.show();
}
delay(100);
}
void showColorMode(int mode) {
uint32_t color;
switch (mode) {
case 0: color = strip.Color(255, 0, 0); break; // Red
case 1: color = strip.Color(0, 255, 0); break; // Green
case 2: color = strip.Color(0, 0, 255); break; // Blue
case 3: color = strip.Color(255, 255, 0); break; // Yellow
case 4: color = strip.Color(255, 0, 255); break; // Purple
}
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, color);
}
strip.show();
}