mirror of
https://github.com/gunner47/GyverLamp.git
synced 2025-08-08 09:20:59 +03:00
add
This commit is contained in:
@@ -1,6 +1,25 @@
|
||||
/*
|
||||
Скетч к проекту "Многофункциональный RGB светильник"
|
||||
Страница проекта (схемы, описания): https://alexgyver.ru/GyverLamp/
|
||||
Исходники на GitHub: https://github.com/AlexGyver/GyverLamp/
|
||||
Нравится, как написан код? Поддержи автора! https://alexgyver.ru/support_alex/
|
||||
Автор: AlexGyver, AlexGyver Technologies, 2019
|
||||
https://AlexGyver.ru/
|
||||
*/
|
||||
|
||||
// Ссылка для менеджера плат:
|
||||
// http://arduino.esp8266.com/stable/package_esp8266com_index.json
|
||||
|
||||
// ============= НАСТРОЙКИ =============
|
||||
// ---------- МАТРИЦА ---------
|
||||
// -------- ВРЕМЯ -------
|
||||
#define GMT 3 // смещение (москва 3)
|
||||
#define NTP_ADDRESS "europe.pool.ntp.org" // сервер времени
|
||||
|
||||
// -------- РАССВЕТ -------
|
||||
#define DAWN_BRIGHT 200 // макс. яркость рассвета
|
||||
#define DAWN_TIMEOUT 1 // сколько рассвет светит после времени будильника, минут
|
||||
|
||||
// ---------- МАТРИЦА ---------
|
||||
#define BRIGHTNESS 40 // стандартная маскимальная яркость (0-255)
|
||||
#define CURRENT_LIMIT 2000 // лимит по току в миллиамперах, автоматически управляет яркостью (пожалей свой блок питания!) 0 - выключить лимит
|
||||
|
||||
@@ -15,28 +34,25 @@
|
||||
// при неправильной настрйоке матрицы вы получите предупреждение "Wrong matrix parameters! Set to default"
|
||||
// шпаргалка по настройке матрицы здесь! https://alexgyver.ru/matrix_guide/
|
||||
|
||||
#define LED_PIN 2 // пин ленты
|
||||
#define MODE_AMOUNT 14
|
||||
|
||||
// -------- ВРЕМЯ -------
|
||||
#define GMT 3 // смещение (москва 3)
|
||||
#define NTP_ADDRESS "europe.pool.ntp.org" // сервер времени
|
||||
|
||||
// --------- ESP --------
|
||||
#define ESP_MODE 1
|
||||
// 0 - точка доступа (192.168.4.1)
|
||||
// 1 - локальный (192.168.1.232)
|
||||
// 0 - точка доступа (192.168.4.1 или другой)
|
||||
// 1 - локальный (192.168.1.232 или другой)
|
||||
|
||||
// -------- Менеджер WiFi ---------
|
||||
#define AC_SSID "AutoConnectAP"
|
||||
#define AC_PASS "12345678"
|
||||
|
||||
// -------------- AP ---------------
|
||||
#define AP_SSID "GyverControl"
|
||||
#define AP_SSID "GyverLamp"
|
||||
#define AP_PASS "12345678"
|
||||
#define AP_PORT 8888
|
||||
|
||||
// ============= ДЛЯ РАЗРАБОТЧИКОВ =============
|
||||
#define LED_PIN 2 // пин ленты
|
||||
#define BTN_PIN 4
|
||||
#define MODE_AMOUNT 14
|
||||
|
||||
#define NUM_LEDS WIDTH * HEIGHT
|
||||
#define SEGMENTS 1 // диодов в одном "пикселе" (для создания матрицы из кусков ленты)
|
||||
// ---------------- БИБЛИОТЕКИ -----------------
|
||||
@@ -54,6 +70,7 @@
|
||||
#include <WiFiUdp.h>
|
||||
#include <EEPROM.h>
|
||||
#include <NTPClient.h>
|
||||
#include <GyverButton.h>
|
||||
|
||||
// ------------------- ТИПЫ --------------------
|
||||
CRGB leds[NUM_LEDS];
|
||||
@@ -62,6 +79,7 @@ WiFiUDP Udp;
|
||||
WiFiUDP ntpUDP;
|
||||
NTPClient timeClient(ntpUDP, NTP_ADDRESS, GMT * 3600, NTP_INTERVAL);
|
||||
timerMinim timeTimer(3000);
|
||||
GButton touch(BTN_PIN, LOW_PULL, NORM_OPEN);
|
||||
|
||||
// ----------------- ПЕРЕМЕННЫЕ ------------------
|
||||
const char* autoConnectSSID = AC_SSID;
|
||||
@@ -99,7 +117,16 @@ boolean settChanged = false;
|
||||
// Павлин 3D, Зебра 3D, Лес 3D, Океан 3D,
|
||||
|
||||
void setup() {
|
||||
ESP.wdtDisable();
|
||||
ESP.wdtEnable(WDTO_8S);
|
||||
delay(1000);
|
||||
// ЛЕНТА
|
||||
FastLED.addLeds<WS2812B, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS)/*.setCorrection( TypicalLEDStrip )*/;
|
||||
FastLED.setBrightness(BRIGHTNESS);
|
||||
if (CURRENT_LIMIT > 0) FastLED.setMaxPowerInVoltsAndMilliamps(5, CURRENT_LIMIT);
|
||||
FastLED.clear();
|
||||
FastLED.show();
|
||||
randomSeed(analogRead(0)); // пинаем генератор случайных чисел
|
||||
Serial.begin(115200);
|
||||
|
||||
// WI-FI
|
||||
@@ -154,14 +181,6 @@ void setup() {
|
||||
dawnMode = EEPROM.read(100);
|
||||
currentMode = EEPROM.read(101);
|
||||
|
||||
// ЛЕНТА
|
||||
FastLED.addLeds<WS2812B, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS)/*.setCorrection( TypicalLEDStrip )*/;
|
||||
FastLED.setBrightness(BRIGHTNESS);
|
||||
if (CURRENT_LIMIT > 0) FastLED.setMaxPowerInVoltsAndMilliamps(5, CURRENT_LIMIT);
|
||||
FastLED.clear();
|
||||
FastLED.show();
|
||||
randomSeed(analogRead(0)); // пинаем генератор случайных чисел
|
||||
|
||||
// отправляем настройки
|
||||
sendCurrent();
|
||||
char reply[inputBuffer.length() + 1];
|
||||
@@ -171,6 +190,7 @@ void setup() {
|
||||
Udp.endPacket();
|
||||
|
||||
timeClient.begin();
|
||||
touch.setStepTimeout(100);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@@ -178,6 +198,8 @@ void loop() {
|
||||
effectsTick();
|
||||
eepromTick();
|
||||
timeTick();
|
||||
buttonTick();
|
||||
ESP.wdtFeed(); // пнуть собаку
|
||||
}
|
||||
|
||||
void eeWriteInt(int pos, int val) {
|
||||
|
42
firmware/GyverLamp_v1.0/button.ino
Normal file
42
firmware/GyverLamp_v1.0/button.ino
Normal file
@@ -0,0 +1,42 @@
|
||||
boolean brightDirection;
|
||||
|
||||
void buttonTick() {
|
||||
touch.tick();
|
||||
if (touch.isSingle()) {
|
||||
if (dawnFlag) {
|
||||
manualOff = true;
|
||||
dawnFlag = false;
|
||||
} else {
|
||||
if (ONflag) {
|
||||
ONflag = false;
|
||||
changePower();
|
||||
} else {
|
||||
ONflag = true;
|
||||
changePower();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (touch.isDouble()) {
|
||||
if (++currentMode >= MODE_AMOUNT) currentMode = 0;
|
||||
loadingFlag = true;
|
||||
settChanged = true;
|
||||
eepromTimer = millis();
|
||||
}
|
||||
|
||||
if (touch.isHolded()) {
|
||||
brightDirection = !brightDirection;
|
||||
}
|
||||
if (touch.isStep()) {
|
||||
if (brightDirection) {
|
||||
if (modes[currentMode].brightness < 250) modes[currentMode].brightness += 5;
|
||||
else modes[currentMode].brightness = 255;
|
||||
} else {
|
||||
if (modes[currentMode].brightness >= 5) modes[currentMode].brightness -= 5;
|
||||
else modes[currentMode].brightness = 0;
|
||||
}
|
||||
FastLED.setBrightness(modes[currentMode].brightness);
|
||||
settChanged = true;
|
||||
eepromTimer = millis();
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
void saveEEPROM() {
|
||||
EEPROM.put(3 * currentMode, modes[currentMode]);
|
||||
EEPROM.put(3 * currentMode, modes[currentMode]);
|
||||
EEPROM.commit();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ void eepromTick() {
|
||||
settChanged = false;
|
||||
eepromTimer = millis();
|
||||
saveEEPROM();
|
||||
if (EEPROM.read(100) != currentMode) EEPROM.write(501, currentMode);
|
||||
if (EEPROM.read(101) != currentMode) EEPROM.write(101, currentMode);
|
||||
EEPROM.commit();
|
||||
}
|
||||
}
|
||||
|
@@ -8,11 +8,12 @@ void timeTick() {
|
||||
|
||||
// проверка рассвета
|
||||
if (alarm[thisDay].state && // день будильника
|
||||
thisTime >= alarm[thisDay].time - dawnOffsets[dawnMode] && // позже начала
|
||||
thisTime < alarm[thisDay].time) { // раньше конца
|
||||
if (!manualOff) {
|
||||
thisTime >= (alarm[thisDay].time - dawnOffsets[dawnMode]) && // позже начала
|
||||
thisTime < (alarm[thisDay].time + DAWN_TIMEOUT) ) { // раньше конца + минута
|
||||
if (!manualOff && ONflag) {
|
||||
// величина рассвета 0-255
|
||||
int dawnPosition = 255 * ((float)(thisTime - (alarm[thisDay].time - dawnOffsets[dawnMode])) / dawnOffsets[dawnMode]);
|
||||
dawnPosition = constrain(dawnPosition, 0, 255);
|
||||
CHSV dawnColor = CHSV(map(dawnPosition, 0, 255, 10, 35),
|
||||
map(dawnPosition, 0, 255, 255, 170),
|
||||
map(dawnPosition, 0, 255, 10, DAWN_BRIGHT));
|
||||
|
Reference in New Issue
Block a user