From e10e5932de63b1ecbf279970242f61cd578e9f30 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 26 Aug 2017 02:11:18 +0300 Subject: =?UTF-8?q?=D0=94=D0=B8=D0=BD=D0=B0=D0=BC=D0=B8=D1=87=D0=B5=D1=81?= =?UTF-8?q?=D0=BA=D0=B0=D1=8F=20=D0=BF=D0=BE=D0=B4=D1=81=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D0=BC=D0=BE=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Динамическая подсветка (Ambilight) для монитора компьютера на Ардуино --- AmbiBox_setup_2.1.7.exe | Bin 0 -> 10256517 bytes FastLED-master.zip | Bin 0 -> 270806 bytes Gyver_Ambilight/Gyver_Ambilight.ino | 87 ++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 AmbiBox_setup_2.1.7.exe create mode 100644 FastLED-master.zip create mode 100644 Gyver_Ambilight/Gyver_Ambilight.ino diff --git a/AmbiBox_setup_2.1.7.exe b/AmbiBox_setup_2.1.7.exe new file mode 100644 index 0000000..5e6cae5 Binary files /dev/null and b/AmbiBox_setup_2.1.7.exe differ diff --git a/FastLED-master.zip b/FastLED-master.zip new file mode 100644 index 0000000..f749554 Binary files /dev/null and b/FastLED-master.zip differ diff --git a/Gyver_Ambilight/Gyver_Ambilight.ino b/Gyver_Ambilight/Gyver_Ambilight.ino new file mode 100644 index 0000000..fe9d9a5 --- /dev/null +++ b/Gyver_Ambilight/Gyver_Ambilight.ino @@ -0,0 +1,87 @@ +/* + Управление лентой на WS2812 с компьютера + динамическая яркость + Создано не знаю кем, допилил и перевёл AlexGyver http://alexgyver.ru/ + 2017 +*/ +//----------------------НАСТРОЙКИ----------------------- +#define NUM_LEDS 98 // число светодиодов в ленте +#define DI_PIN 13 // пин, к которому подключена лента + +#define start_flashes 0 // проверка цветов при запуске (1 - включить, 0 - выключить) + +#define auto_bright 0 // автоматическая подстройка яркости от уровня внешнего освещения (1 - включить, 0 - выключить) +#define max_bright 150 // максимальная яркость (0 - 255) +#define min_bright 10 // минимальная яркость (0 - 255) +//----------------------НАСТРОЙКИ----------------------- + +int new_bright; +unsigned long bright_timer; +#define serialRate 115200 // скорость связи с ПК +uint8_t prefix[] = {'A', 'd', 'a'}, hi, lo, chk, i; // кодовое слово Ada для связи +#include +CRGB leds[NUM_LEDS]; // создаём ленту + +void setup() +{ + FastLED.addLeds(leds, NUM_LEDS); // инициализация светодиодов + + // вспышки красным синим и зелёным при запуске (можно отключить) + if (start_flashes) { + LEDS.showColor(CRGB(255, 0, 0)); + delay(500); + LEDS.showColor(CRGB(0, 255, 0)); + delay(500); + LEDS.showColor(CRGB(0, 0, 255)); + delay(500); + LEDS.showColor(CRGB(0, 0, 0)); + } + + Serial.begin(serialRate); + Serial.print("Ada\n"); // Связаться с компом +} + +void loop() { + if (auto_bright) { // если включена адаптивная яркость + if (millis() - bright_timer > 500) { // каждые полсекунды + bright_timer = millis(); // сброить таймер + new_bright = map(analogRead(6), 0, 1000, min_bright, max_bright); // считать показания с фоторезистора, перевести диапазон + constrain(new_bright, min_bright, max_bright); + LEDS.setBrightness(new_bright); // установить новую яркость + } + } + + for (i = 0; i < sizeof prefix; ++i) { +waitLoop: while (!Serial.available()) ;; + if (prefix[i] == Serial.read()) continue; + i = 0; + goto waitLoop; + } + + while (!Serial.available()) ;; + hi = Serial.read(); + while (!Serial.available()) ;; + lo = Serial.read(); + while (!Serial.available()) ;; + chk = Serial.read(); + if (chk != (hi ^ lo ^ 0x55)) + { + i = 0; + goto waitLoop; + } + + memset(leds, 0, NUM_LEDS * sizeof(struct CRGB)); + for (uint8_t i = 0; i < NUM_LEDS; i++) { + byte r, g, b; + // читаем данные для каждого цвета + while (!Serial.available()); + r = Serial.read(); + while (!Serial.available()); + g = Serial.read(); + while (!Serial.available()); + b = Serial.read(); + leds[i].r = r; + leds[i].g = g; + leds[i].b = b; + } + FastLED.show(); // записываем цвета в ленту +} -- cgit v1.2.3