Загрузка данных


#include <Adafruit_NeoPixel.h>

#define LED_PIN 2
#define LED_COUNT 6
#define BUTTON_PIN 4

Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

int mode = 0;

bool lastButton = HIGH;
unsigned long lastPress = 0;

void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP);

  strip.begin();
  strip.setBrightness(100);
  strip.clear();
  strip.show();
}

void loop() {

  bool button = digitalRead(BUTTON_PIN);

  // Кнопка нажата
  if (button == LOW && lastButton == HIGH) {

    // Защита от дребезга
    if (millis() - lastPress > 200) {

      mode++;

      if (mode > 4) {
        mode = 0;
      }

      showMode();

      lastPress = millis();
    }
  }

  lastButton = button;
}


// ================================
// ПОКАЗ ТЕКУЩЕГО РЕЖИМА
// ================================

void showMode() {

  strip.clear();

  if (mode == 0) {
    // Красный
    setAll(255, 0, 0);
  }

  if (mode == 1) {
    // Зелёный
    setAll(0, 255, 0);
  }

  if (mode == 2) {
    // Синий
    setAll(0, 0, 255);
  }

  if (mode == 3) {
    // Фиолетовый
    setAll(255, 0, 255);
  }

  if (mode == 4) {
    // Жёлтый
    setAll(255, 100, 0);
  }

  strip.show();
}


// ================================
// ЗАЖЕЧЬ ВСЕ LED
// ================================

void setAll(byte r, byte g, byte b) {

  for (int i = 0; i < LED_COUNT; i++) {
    strip.setPixelColor(i, strip.Color(r, g, b));
  }
}