GY-33
added changes from original repository. added support for color sensor GY-33.
This commit is contained in:
@@ -0,0 +1,240 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file GY33_MCU.h
|
||||
@author BPoHVoodoo (FabLab Luenen)
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2018,
|
||||
All rights reserved.
|
||||
|
||||
Driver for the GY-33 MCU digital color sensors.
|
||||
|
||||
@section HISTORY
|
||||
|
||||
v1.0 - First release
|
||||
*/
|
||||
/**************************************************************************/
|
||||
#ifdef __AVR
|
||||
#include <avr/pgmspace.h>
|
||||
#elif defined(ESP8266)
|
||||
#include <pgmspace.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "GY33_MCU.h"
|
||||
|
||||
/*========================================================================*/
|
||||
/* PRIVATE FUNCTIONS */
|
||||
/*========================================================================*/
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Implements missing powf function
|
||||
*/
|
||||
/**************************************************************************/
|
||||
float powf(const float x, const float y)
|
||||
{
|
||||
return (float)(pow((double)x, (double)y));
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Writes a register and an 8 bit value over I2C
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void GY33_MCU::write8 (uint8_t reg, uint32_t val)
|
||||
{
|
||||
uint8_t buf[2];
|
||||
brzo_i2c_start_transaction(MCU_ADDRESS, SCL_SPEED);
|
||||
buf[0]=reg;
|
||||
buf[1]=val;
|
||||
brzo_i2c_write(buf, 2, true);
|
||||
brzo_i2c_end_transaction();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Reads an 8 bit value over I2C
|
||||
*/
|
||||
/**************************************************************************/
|
||||
uint8_t GY33_MCU::read8(uint8_t reg)
|
||||
{
|
||||
uint8_t buf[2];
|
||||
brzo_i2c_start_transaction(MCU_ADDRESS, SCL_SPEED);
|
||||
buf[0]=reg;
|
||||
brzo_i2c_write(buf,1, true);
|
||||
brzo_i2c_read(buf, 1, false);
|
||||
brzo_i2c_end_transaction();
|
||||
return buf[0];
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Reads a 16 bit values over I2C
|
||||
*/
|
||||
/**************************************************************************/
|
||||
uint16_t GY33_MCU::read16(uint8_t reg)
|
||||
{
|
||||
uint16_t x; uint16_t t;
|
||||
uint8_t buf[2];
|
||||
brzo_i2c_start_transaction(MCU_ADDRESS, SCL_SPEED);
|
||||
buf[0]=reg;
|
||||
brzo_i2c_write(buf, 1, true);
|
||||
brzo_i2c_read(buf, 2, false);
|
||||
brzo_i2c_end_transaction();
|
||||
x = buf[0];
|
||||
t = buf[1];
|
||||
x <<= 8;
|
||||
x |= t;
|
||||
return buf[0] << 8 | buf[1];
|
||||
}
|
||||
|
||||
|
||||
/*========================================================================*/
|
||||
/* CONSTRUCTORS */
|
||||
/*========================================================================*/
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
Constructor
|
||||
*/
|
||||
/**************************************************************************/
|
||||
GY33_MCU::GY33_MCU()
|
||||
{
|
||||
_MCUInitialised = false;
|
||||
}
|
||||
|
||||
/*========================================================================*/
|
||||
/* PUBLIC FUNCTIONS */
|
||||
/*========================================================================*/
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
Initializes I2C and configures the sensor (call this function before
|
||||
doing anything else)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
boolean GY33_MCU::begin(void)
|
||||
{
|
||||
brzo_i2c_setup(SDA, SCL, SCL_STRETCH_TIMEOUT);
|
||||
|
||||
/* Make sure we're actually connected */
|
||||
uint8_t x = read8(MCU_CONFIG);
|
||||
Serial.println(x, HEX);
|
||||
if ((x != 0x00) && (x != 0xFF))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_MCUInitialised = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Reads the raw red, green, blue and clear channel values
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void GY33_MCU::getRawData (uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c, uint16_t *ct)
|
||||
{
|
||||
if (!_MCUInitialised) begin();
|
||||
|
||||
*r = read16(MCU_RDATAH);
|
||||
*g = read16(MCU_GDATAH);
|
||||
*b = read16(MCU_BDATAH);
|
||||
*c = read16(MCU_CDATAH);
|
||||
*ct = read16(MCU_CTDATAH);
|
||||
}
|
||||
|
||||
|
||||
void GY33_MCU::getData (uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *c)
|
||||
{
|
||||
if (!_MCUInitialised) begin();
|
||||
|
||||
*r = read8(MCU_RDATA);
|
||||
*g = read8(MCU_GDATA);
|
||||
*b = read8(MCU_BDATA);
|
||||
*c = read8(MCU_COLDATA);
|
||||
}
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Converts the raw R/G/B values to color temperature in degrees
|
||||
Kelvin
|
||||
*/
|
||||
/**************************************************************************/
|
||||
uint16_t GY33_MCU::calculateColorTemperature(uint16_t r, uint16_t g, uint16_t b)
|
||||
{
|
||||
float X, Y, Z; /* RGB to XYZ correlation */
|
||||
float xc, yc; /* Chromaticity co-ordinates */
|
||||
float n; /* McCamy's formula */
|
||||
float cct;
|
||||
|
||||
/* 1. Map RGB values to their XYZ counterparts. */
|
||||
/* Based on 6500K fluorescent, 3000K fluorescent */
|
||||
/* and 60W incandescent values for a wide range. */
|
||||
/* Note: Y = Illuminance or lux */
|
||||
X = (-0.14282F * r) + (1.54924F * g) + (-0.95641F * b);
|
||||
Y = (-0.32466F * r) + (1.57837F * g) + (-0.73191F * b);
|
||||
Z = (-0.68202F * r) + (0.77073F * g) + ( 0.56332F * b);
|
||||
|
||||
/* 2. Calculate the chromaticity co-ordinates */
|
||||
xc = (X) / (X + Y + Z);
|
||||
yc = (Y) / (X + Y + Z);
|
||||
|
||||
/* 3. Use McCamy's formula to determine the CCT */
|
||||
n = (xc - 0.3320F) / (0.1858F - yc);
|
||||
|
||||
/* Calculate the final CCT */
|
||||
cct = (449.0F * powf(n, 3)) + (3525.0F * powf(n, 2)) + (6823.3F * n) + 5520.33F;
|
||||
|
||||
/* Return the results in degrees Kelvin */
|
||||
return (uint16_t)cct;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Converts the raw R/G/B values to lux
|
||||
*/
|
||||
/**************************************************************************/
|
||||
uint16_t GY33_MCU::calculateLux(uint16_t r, uint16_t g, uint16_t b)
|
||||
{
|
||||
float illuminance;
|
||||
|
||||
/* This only uses RGB ... how can we integrate clear or calculate lux */
|
||||
/* based exclusively on clear since this might be more reliable? */
|
||||
illuminance = (-0.32466F * r) + (1.57837F * g) + (-0.73191F * b);
|
||||
|
||||
return (uint16_t)illuminance;
|
||||
}
|
||||
|
||||
|
||||
/*void GY33_MCU::setInterrupt(boolean i) {
|
||||
uint8_t r = read8(MCU_ENABLE);
|
||||
if (i) {
|
||||
r |= MCU_ENABLE_AIEN;
|
||||
} else {
|
||||
r &= ~MCU_ENABLE_AIEN;
|
||||
}
|
||||
write8(MCU_ENABLE, r);
|
||||
}
|
||||
|
||||
void GY33_MCU::clearInterrupt(void) {
|
||||
Wire.beginTransmission(MCU_ADDRESS);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(MCU_COMMAND_BIT | 0x66);
|
||||
#else
|
||||
Wire.send(MCU_COMMAND_BIT | 0x66);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
}
|
||||
*/
|
||||
|
||||
void GY33_MCU::setConfig(uint8_t high, uint8_t low) {
|
||||
// write8(MCU_CONFIG, high | low);
|
||||
write8(MCU_CONFIG, 0x11);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
#include <brzo_i2c.h>
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file GY33_MCU.h
|
||||
@author BPoHVoodoo (FabLab Luenen)
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2018,
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
#ifndef _MCU_H_
|
||||
#define _MCU_H_
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#include <WProgram.h>
|
||||
#endif
|
||||
|
||||
#include <brzo_i2c.h>
|
||||
|
||||
#define MCU_ADDRESS (0x5A)
|
||||
|
||||
#define SCL_SPEED 100
|
||||
#define SCL_STRETCH_TIMEOUT 50000
|
||||
|
||||
#define MCU_LED_OFF (0x00)
|
||||
#define MCU_LED_1 (0x10)
|
||||
#define MCU_LED_2 (0x20)
|
||||
#define MCU_LED_3 (0x30)
|
||||
#define MCU_LED_4 (0x40)
|
||||
#define MCU_LED_5 (0x50)
|
||||
#define MCU_LED_6 (0x60)
|
||||
#define MCU_LED_7 (0x70)
|
||||
#define MCU_LED_8 (0x80)
|
||||
#define MCU_LED_9 (0x90)
|
||||
#define MCU_LED_10 (0xA0)
|
||||
#define MCU_WHITE_OFF (0x00) /* No Whitebalance */
|
||||
#define MCU_WHITE_ON (0x01) /* Whitebalance */
|
||||
|
||||
#define MCU_RDATAH (0x00) /* Raw Red channel data */
|
||||
#define MCU_RDATAL (0x01)
|
||||
#define MCU_GDATAH (0x02) /* Raw Green channel data */
|
||||
#define MCU_GDATAL (0x03)
|
||||
#define MCU_BDATAH (0x04) /* Raw Blue channel data */
|
||||
#define MCU_BDATAL (0x05)
|
||||
#define MCU_CDATAH (0x06) /* Clear channel data */
|
||||
#define MCU_CDATAL (0x07)
|
||||
#define MCU_LDATAH (0x08) /* Lux channel data */
|
||||
#define MCU_LDATAL (0x09)
|
||||
#define MCU_CTDATAH (0x0A) /* Colortemperature channel data */
|
||||
#define MCU_CTDATAL (0x0B)
|
||||
#define MCU_RDATA (0x0C) /* Red channel data */
|
||||
#define MCU_GDATA (0x0D) /* Green channel data */
|
||||
#define MCU_BDATA (0x0E) /* Blue channel data */
|
||||
#define MCU_COLDATA (0x0F) /* Blue channel data */
|
||||
#define MCU_CONFIG (0x10)
|
||||
|
||||
class GY33_MCU {
|
||||
public:
|
||||
GY33_MCU();
|
||||
|
||||
boolean begin(void);
|
||||
void getRawData(uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c, uint16_t *ct);
|
||||
void getData(uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *c);
|
||||
uint16_t calculateColorTemperature(uint16_t r, uint16_t g, uint16_t b);
|
||||
uint16_t calculateLux(uint16_t r, uint16_t g, uint16_t b);
|
||||
void write8 (uint8_t reg, uint32_t val);
|
||||
uint8_t read8 (uint8_t reg);
|
||||
uint16_t read16 (uint8_t reg);
|
||||
/* void setInterrupt(boolean flag);
|
||||
void clearInterrupt(void);*/
|
||||
void setConfig(uint8_t h, uint8_t l);
|
||||
|
||||
private:
|
||||
boolean _MCUInitialised;
|
||||
|
||||
void disable(void);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -18,20 +18,50 @@
|
||||
#include <WebSockets.h> //https://github.com/Links2004/arduinoWebSockets
|
||||
#include <WebSocketsServer.h>
|
||||
|
||||
#ifdef ENABLE_BUTTON2
|
||||
// needed for MCU
|
||||
#include "GY33_MCU.h"
|
||||
// ***************************************************************************
|
||||
// Initialize Color Sensor
|
||||
// ***************************************************************************
|
||||
byte gammatable[256];
|
||||
GY33_MCU tcs;
|
||||
#endif
|
||||
|
||||
// OTA
|
||||
#ifdef ENABLE_OTA
|
||||
#include <WiFiUdp.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#endif
|
||||
|
||||
//SPIFFS Save
|
||||
#if !defined(ENABLE_HOMEASSISTANT) and defined(ENABLE_STATE_SAVE_SPIFFS)
|
||||
#include <ArduinoJson.h> //
|
||||
#endif
|
||||
|
||||
// MQTT
|
||||
#ifdef ENABLE_MQTT
|
||||
#include <PubSubClient.h>
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
#include <ArduinoJson.h>
|
||||
#endif
|
||||
|
||||
WiFiClient espClient;
|
||||
PubSubClient mqtt_client(espClient);
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_AMQTT
|
||||
#include <AsyncMqttClient.h> //https://github.com/marvinroger/async-mqtt-client
|
||||
//https://github.com/me-no-dev/ESPAsyncTCP
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
#include <ArduinoJson.h>
|
||||
#endif
|
||||
|
||||
AsyncMqttClient amqttClient;
|
||||
WiFiEventHandler wifiConnectHandler;
|
||||
WiFiEventHandler wifiDisconnectHandler;
|
||||
#endif
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
// Instanciate HTTP(80) / WebSockets(81) Server
|
||||
@@ -39,7 +69,37 @@
|
||||
ESP8266WebServer server(80);
|
||||
WebSocketsServer webSocket = WebSocketsServer(81);
|
||||
|
||||
#ifdef HTTP_OTA
|
||||
#include <ESP8266HTTPUpdateServer.h>
|
||||
ESP8266HTTPUpdateServer httpUpdater;
|
||||
#endif
|
||||
|
||||
#ifdef USE_NEOANIMATIONFX
|
||||
// ***************************************************************************
|
||||
// Load libraries / Instanciate NeoAnimationFX library
|
||||
// ***************************************************************************
|
||||
// https://github.com/debsahu/NeoAnimationFX
|
||||
#include <NeoAnimationFX.h>
|
||||
#define NEOMETHOD NeoPBBGRB800
|
||||
|
||||
NEOMETHOD neoStrip(NUMLEDS);
|
||||
NeoAnimationFX<NEOMETHOD> strip(neoStrip);
|
||||
|
||||
// Uses Pin RX / GPIO3 (Only pin that is supported, due to hardware limitations)
|
||||
// NEOMETHOD NeoPBBGRB800 uses GRB config 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||
// NEOMETHOD NeoPBBGRB400 uses GRB config 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||
// NEOMETHOD NeoPBBRGB800 uses RGB config 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||
// NEOMETHOD NeoPBBRGB400 uses RGB config 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||
|
||||
// Uses Pin D4 / GPIO2 (Only pin that is supported, due to hardware limitations)
|
||||
// NEOMETHOD NeoPBBGRBU800 uses GRB config 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||
// NEOMETHOD NeoPBBGRBU400 uses GRB config 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||
// NEOMETHOD NeoPBBRGBU800 uses RGB config 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||
// NEOMETHOD NeoPBBRGBU400 uses RGB config 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef USE_WS2812FX
|
||||
// ***************************************************************************
|
||||
// Load libraries / Instanciate WS2812FX library
|
||||
// ***************************************************************************
|
||||
@@ -59,14 +119,23 @@ WS2812FX strip = WS2812FX(NUMLEDS, PIN, NEO_GRBW + NEO_KHZ800);
|
||||
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
|
||||
// and minimize distance between Arduino and first pixel. Avoid connecting
|
||||
// on a live circuit...if you must, connect GND first.
|
||||
|
||||
#endif
|
||||
|
||||
// ***************************************************************************
|
||||
// Load library "ticker" for blinking status led
|
||||
// ***************************************************************************
|
||||
#include <Ticker.h>
|
||||
Ticker ticker;
|
||||
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
Ticker ha_send_data;
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
Ticker mqttReconnectTimer;
|
||||
Ticker wifiReconnectTimer;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
Ticker spiffs_save_state;
|
||||
#endif
|
||||
void tick()
|
||||
{
|
||||
//toggle state
|
||||
@@ -74,7 +143,7 @@ void tick()
|
||||
digitalWrite(BUILTIN_LED, !state); // set pin to the opposite state
|
||||
}
|
||||
|
||||
|
||||
#ifdef ENABLE_STATE_SAVE_EEPROM
|
||||
// ***************************************************************************
|
||||
// EEPROM helper
|
||||
// ***************************************************************************
|
||||
@@ -100,7 +169,7 @@ void writeEEPROM(int offset, int len, String value) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// ***************************************************************************
|
||||
// Saved state handling
|
||||
@@ -123,7 +192,6 @@ String getValue(String data, char separator, int index)
|
||||
return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
// Callback for WiFiManager library when config mode is entered
|
||||
// ***************************************************************************
|
||||
@@ -164,12 +232,12 @@ void saveConfigCallback () {
|
||||
// ***************************************************************************
|
||||
#include "colormodes.h"
|
||||
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
// MAIN
|
||||
// ***************************************************************************
|
||||
void setup() {
|
||||
// system_update_cpu_freq(160);
|
||||
|
||||
DBG_OUTPUT_PORT.begin(115200);
|
||||
EEPROM.begin(512);
|
||||
|
||||
@@ -179,9 +247,44 @@ void setup() {
|
||||
#ifdef ENABLE_BUTTON
|
||||
pinMode(BUTTON, INPUT_PULLUP);
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_BUTTON2
|
||||
pinMode(BUTTON2, INPUT_PULLUP);
|
||||
for (int i=0; i<256; i++) {
|
||||
float x = i;
|
||||
x /= 255;
|
||||
x = pow(x, 2.5);
|
||||
x *= 255;
|
||||
gammatable[i] = x;
|
||||
}
|
||||
if (tcs.begin()) {
|
||||
DBG_OUTPUT_PORT.println("Found GY33 sensor");
|
||||
tcs.setConfig(MCU_LED_OFF,MCU_LED_OFF);
|
||||
} else {
|
||||
DBG_OUTPUT_PORT.println("No GY33 sensor found ... check your connections");
|
||||
}
|
||||
#endif
|
||||
|
||||
// start ticker with 0.5 because we start in AP mode and try to connect
|
||||
ticker.attach(0.5, tick);
|
||||
|
||||
// ***************************************************************************
|
||||
// Setup: SPIFFS
|
||||
// ***************************************************************************
|
||||
SPIFFS.begin();
|
||||
{
|
||||
Dir dir = SPIFFS.openDir("/");
|
||||
while (dir.next()) {
|
||||
String fileName = dir.fileName();
|
||||
size_t fileSize = dir.fileSize();
|
||||
DBG_OUTPUT_PORT.printf("FS File: %s, size: %s\n", fileName.c_str(), formatBytes(fileSize).c_str());
|
||||
}
|
||||
|
||||
FSInfo fs_info;
|
||||
SPIFFS.info(fs_info);
|
||||
DBG_OUTPUT_PORT.printf("FS Usage: %d/%d bytes\n\n", fs_info.usedBytes, fs_info.totalBytes);
|
||||
}
|
||||
|
||||
wifi_station_set_hostname(const_cast<char*>(HOSTNAME));
|
||||
|
||||
// ***************************************************************************
|
||||
@@ -200,7 +303,10 @@ void setup() {
|
||||
// The extra parameters to be configured (can be either global or just in the setup)
|
||||
// After connecting, parameter.getValue() will get you the configured value
|
||||
// id/name placeholder/prompt default length
|
||||
#ifdef ENABLE_MQTT
|
||||
#if defined(ENABLE_MQTT) or defined(ENABLE_AMQTT)
|
||||
#if defined(ENABLE_STATE_SAVE_SPIFFS) and (defined(ENABLE_MQTT) or defined(ENABLE_AMQTT))
|
||||
(readConfigFS()) ? DBG_OUTPUT_PORT.println("WiFiManager config FS Read success!"): DBG_OUTPUT_PORT.println("WiFiManager config FS Read failure!");
|
||||
#else
|
||||
String settings_available = readEEPROM(134, 1);
|
||||
if (settings_available == "1") {
|
||||
readEEPROM(0, 64).toCharArray(mqtt_host, 64); // 0-63
|
||||
@@ -212,7 +318,7 @@ void setup() {
|
||||
DBG_OUTPUT_PORT.printf("MQTT user: %s\n", mqtt_user);
|
||||
DBG_OUTPUT_PORT.printf("MQTT pass: %s\n", mqtt_pass);
|
||||
}
|
||||
|
||||
#endif
|
||||
WiFiManagerParameter custom_mqtt_host("host", "MQTT hostname", mqtt_host, 64);
|
||||
WiFiManagerParameter custom_mqtt_port("port", "MQTT port", mqtt_port, 6);
|
||||
WiFiManagerParameter custom_mqtt_user("user", "MQTT user", mqtt_user, 32);
|
||||
@@ -227,7 +333,7 @@ void setup() {
|
||||
//set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
|
||||
wifiManager.setAPCallback(configModeCallback);
|
||||
|
||||
#ifdef ENABLE_MQTT
|
||||
#if defined(ENABLE_MQTT) or defined(ENABLE_AMQTT)
|
||||
//set config save notify callback
|
||||
wifiManager.setSaveConfigCallback(saveConfigCallback);
|
||||
|
||||
@@ -238,6 +344,8 @@ void setup() {
|
||||
wifiManager.addParameter(&custom_mqtt_pass);
|
||||
#endif
|
||||
|
||||
WiFi.setSleepMode(WIFI_NONE_SLEEP);
|
||||
|
||||
//fetches ssid and pass and tries to connect
|
||||
//if it does not connect it starts an access point with the specified name
|
||||
//here "AutoConnectAP"
|
||||
@@ -249,7 +357,7 @@ void setup() {
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_MQTT
|
||||
#if defined(ENABLE_MQTT) or defined(ENABLE_AMQTT)
|
||||
//read updated parameters
|
||||
strcpy(mqtt_host, custom_mqtt_host.getValue());
|
||||
strcpy(mqtt_port, custom_mqtt_port.getValue());
|
||||
@@ -257,6 +365,9 @@ void setup() {
|
||||
strcpy(mqtt_pass, custom_mqtt_pass.getValue());
|
||||
|
||||
//save the custom parameters to FS
|
||||
#if defined(ENABLE_STATE_SAVE_SPIFFS) and (defined(ENABLE_MQTT) or defined(ENABLE_AMQTT))
|
||||
(writeConfigFS(shouldSaveConfig)) ? DBG_OUTPUT_PORT.println("WiFiManager config FS Save success!"): DBG_OUTPUT_PORT.println("WiFiManager config FS Save failure!");
|
||||
#else if defined(ENABLE_STATE_SAVE_EEPROM)
|
||||
if (shouldSaveConfig) {
|
||||
DBG_OUTPUT_PORT.println("Saving WiFiManager config");
|
||||
|
||||
@@ -268,6 +379,12 @@ void setup() {
|
||||
EEPROM.commit();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_AMQTT
|
||||
wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
|
||||
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
|
||||
#endif
|
||||
|
||||
//if you get here you have connected to the WiFi
|
||||
DBG_OUTPUT_PORT.println("connected...yeey :)");
|
||||
@@ -333,6 +450,22 @@ void setup() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_AMQTT
|
||||
if (mqtt_host != "" && String(mqtt_port).toInt() > 0) {
|
||||
amqttClient.onConnect(onMqttConnect);
|
||||
amqttClient.onDisconnect(onMqttDisconnect);
|
||||
amqttClient.onMessage(onMqttMessage);
|
||||
amqttClient.setServer(mqtt_host, String(mqtt_port).toInt());
|
||||
amqttClient.setCredentials(mqtt_user, mqtt_pass);
|
||||
amqttClient.setClientId(mqtt_clientid);
|
||||
|
||||
connectToMqtt();
|
||||
}
|
||||
#endif
|
||||
|
||||
// #ifdef ENABLE_HOMEASSISTANT
|
||||
// ha_send_data.attach(5, tickerSendState); // Send HA data back only every 5 sec
|
||||
// #endif
|
||||
|
||||
// ***************************************************************************
|
||||
// Setup: MDNS responder
|
||||
@@ -360,24 +493,6 @@ void setup() {
|
||||
webSocket.begin();
|
||||
webSocket.onEvent(webSocketEvent);
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
// Setup: SPIFFS
|
||||
// ***************************************************************************
|
||||
SPIFFS.begin();
|
||||
{
|
||||
Dir dir = SPIFFS.openDir("/");
|
||||
while (dir.next()) {
|
||||
String fileName = dir.fileName();
|
||||
size_t fileSize = dir.fileSize();
|
||||
DBG_OUTPUT_PORT.printf("FS File: %s, size: %s\n", fileName.c_str(), formatBytes(fileSize).c_str());
|
||||
}
|
||||
|
||||
FSInfo fs_info;
|
||||
SPIFFS.info(fs_info);
|
||||
DBG_OUTPUT_PORT.printf("FS Usage: %d/%d bytes\n\n", fs_info.usedBytes, fs_info.totalBytes);
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
// Setup: SPIFFS Webserver handler
|
||||
// ***************************************************************************
|
||||
@@ -455,11 +570,19 @@ void setup() {
|
||||
brightness = 0;
|
||||
}
|
||||
strip.setBrightness(brightness);
|
||||
|
||||
if (mode == HOLD) {
|
||||
mode = ALL;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String(String("OK %") + String(brightness)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK %") + String(brightness)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
getStatusJSON();
|
||||
});
|
||||
|
||||
@@ -475,6 +598,15 @@ void setup() {
|
||||
ws2812fx_speed = server.arg("d").toInt();
|
||||
ws2812fx_speed = constrain(ws2812fx_speed, 0, 255);
|
||||
strip.setSpeed(convertSpeed(ws2812fx_speed));
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String(String("OK ?") + String(ws2812fx_speed)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK ?") + String(ws2812fx_speed)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||
#endif
|
||||
}
|
||||
|
||||
getStatusJSON();
|
||||
@@ -508,6 +640,18 @@ void setup() {
|
||||
mode = OFF;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =off").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =off").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = false;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/all", []() {
|
||||
@@ -515,6 +659,18 @@ void setup() {
|
||||
mode = ALL;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =all").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =all").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/wipe", []() {
|
||||
@@ -522,6 +678,18 @@ void setup() {
|
||||
mode = WIPE;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =wipe").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =wipe").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/rainbow", []() {
|
||||
@@ -529,6 +697,18 @@ void setup() {
|
||||
mode = RAINBOW;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =rainbow").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =rainbow").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/rainbowCycle", []() {
|
||||
@@ -536,6 +716,18 @@ void setup() {
|
||||
mode = RAINBOWCYCLE;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =rainbowCycle").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =rainbowCycle").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/theaterchase", []() {
|
||||
@@ -543,6 +735,37 @@ void setup() {
|
||||
mode = THEATERCHASE;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =theaterchase").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =theaterchase").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/twinkleRandom", []() {
|
||||
exit_func = true;
|
||||
mode = TWINKLERANDOM;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =twinkleRandom").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =twinkleRandom").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/theaterchaseRainbow", []() {
|
||||
@@ -550,6 +773,18 @@ void setup() {
|
||||
mode = THEATERCHASERAINBOW;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =theaterchaseRainbow").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =theaterchaseRainbow").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/tv", []() {
|
||||
@@ -557,6 +792,18 @@ void setup() {
|
||||
mode = TV;
|
||||
getArgs();
|
||||
getStatusJSON();
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String("OK =tv").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK =tv").c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
server.on("/get_modes", []() {
|
||||
@@ -567,16 +814,36 @@ void setup() {
|
||||
getArgs();
|
||||
mode = SET_MODE;
|
||||
getStatusJSON();
|
||||
|
||||
#ifdef ENABLE_MQTT
|
||||
mqtt_client.publish(mqtt_outtopic, String(String("OK /") + String(ws2812fx_mode)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_AMQTT
|
||||
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String(String("OK /") + String(ws2812fx_mode)).c_str());
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
stateOn = true;
|
||||
if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
});
|
||||
|
||||
#ifdef HTTP_OTA
|
||||
httpUpdater.setup(&server, "/update");
|
||||
#endif
|
||||
|
||||
server.begin();
|
||||
|
||||
// Start MDNS service
|
||||
if (mdns_result) {
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_STATE_SAVE
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
(readStateFS()) ? DBG_OUTPUT_PORT.println(" Success!") : DBG_OUTPUT_PORT.println(" Failure!");
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_EEPROM
|
||||
// Load state string from EEPROM
|
||||
String saved_state_string = readEEPROM(256, 36);
|
||||
String chk = getValue(saved_state_string, '|', 0);
|
||||
@@ -588,11 +855,13 @@ void setup() {
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
#ifdef ENABLE_BUTTON
|
||||
button();
|
||||
#endif
|
||||
#ifdef ENABLE_BUTTON2
|
||||
button2();
|
||||
#endif
|
||||
server.handleClient();
|
||||
webSocket.loop();
|
||||
|
||||
@@ -601,24 +870,44 @@ void loop() {
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_MQTT
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
ha_send_data.detach();
|
||||
#endif
|
||||
DBG_OUTPUT_PORT.println("WiFi disconnected, reconnecting!");
|
||||
WiFi.disconnect();
|
||||
WiFi.setSleepMode(WIFI_NONE_SLEEP);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin();
|
||||
} else {
|
||||
if (mqtt_host != "" && String(mqtt_port).toInt() > 0 && mqtt_reconnect_retries < MQTT_MAX_RECONNECT_TRIES) {
|
||||
if (!mqtt_client.connected()) {
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
ha_send_data.detach();
|
||||
#endif
|
||||
DBG_OUTPUT_PORT.println("MQTT disconnected, reconnecting!");
|
||||
mqtt_reconnect();
|
||||
} else {
|
||||
mqtt_client.loop();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
// if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||
if (new_ha_mqtt_msg) sendState();
|
||||
#endif
|
||||
|
||||
// Simple statemachine that handles the different modes
|
||||
if (mode == SET_MODE) {
|
||||
DBG_OUTPUT_PORT.printf("SET_MODE: %d %d\n", ws2812fx_mode, mode);
|
||||
strip.setMode(ws2812fx_mode);
|
||||
mode = HOLD;
|
||||
mode = SETSPEED;
|
||||
}
|
||||
if (mode == OFF) {
|
||||
strip.setColor(0,0,0,0);
|
||||
strip.setMode(FX_MODE_STATIC);
|
||||
// strip.setColor(0,0,0,0);
|
||||
// strip.setMode(FX_MODE_STATIC);
|
||||
if(strip.isRunning()) strip.stop(); //should clear memory
|
||||
// mode = HOLD;
|
||||
}
|
||||
if (mode == ALL) {
|
||||
@@ -626,6 +915,18 @@ void loop() {
|
||||
strip.setMode(FX_MODE_STATIC);
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == SETCOLOR) {
|
||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == SETSPEED) {
|
||||
strip.setSpeed(convertSpeed(ws2812fx_speed));
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == BRIGHTNESS) {
|
||||
strip.setBrightness(brightness);
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == WIPE) {
|
||||
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
strip.setMode(FX_MODE_COLOR_WIPE);
|
||||
@@ -654,11 +955,13 @@ void loop() {
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == HOLD || mode == CUSTOM) {
|
||||
if(!strip.isRunning()) strip.start();
|
||||
if (exit_func) {
|
||||
exit_func = false;
|
||||
}
|
||||
}
|
||||
if (mode == TV) {
|
||||
if(!strip.isRunning()) strip.start();
|
||||
tv();
|
||||
}
|
||||
|
||||
@@ -667,8 +970,13 @@ void loop() {
|
||||
strip.service();
|
||||
}
|
||||
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if (updateStateFS) {
|
||||
(writeStateFS()) ? DBG_OUTPUT_PORT.println(" Success!") : DBG_OUTPUT_PORT.println(" Failure!");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_STATE_SAVE
|
||||
#ifdef ENABLE_STATE_SAVE_EEPROM
|
||||
// Check for state changes
|
||||
sprintf(current_state, "STA|%2d|%3d|%3d|%3d|%3d|%3d|%3d|%3d", mode, strip.getMode(), ws2812fx_speed, brightness, main_color.white, main_color.red, main_color.green, main_color.blue);
|
||||
|
||||
@@ -686,3 +994,4 @@ void loop() {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
+106
-100
@@ -7,10 +7,10 @@
|
||||
|
||||
FEATURES
|
||||
* A lot of blinken modes and counting
|
||||
* WS2812FX can be used as drop-in replacement for Adafruit Neopixel Library
|
||||
* WS2812FX can be used as drop-in replacement for Adafruit NeoPixel Library
|
||||
|
||||
NOTES
|
||||
* Uses the Adafruit Neopixel library. Get it here:
|
||||
* Uses the Adafruit NeoPixel library. Get it here:
|
||||
https://github.com/adafruit/Adafruit_NeoPixel
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ void WS2812FX::decreaseLength(uint16_t s) {
|
||||
s = _segments[0].stop - _segments[0].start + 1 - s;
|
||||
|
||||
for(uint16_t i=_segments[0].start + s; i <= (_segments[0].stop - _segments[0].start + 1); i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(i, 0);
|
||||
this->setPixelColor(i, 0);
|
||||
}
|
||||
Adafruit_NeoPixel::show();
|
||||
|
||||
@@ -211,7 +211,15 @@ uint32_t WS2812FX::getColor(void) {
|
||||
return _segments[0].colors[0];
|
||||
}
|
||||
|
||||
WS2812FX::segment* WS2812FX::getSegments(void) {
|
||||
WS2812FX::Segment WS2812FX::getSegment(void) {
|
||||
return SEGMENT;
|
||||
}
|
||||
|
||||
WS2812FX::Segment_runtime WS2812FX::getSegmentRuntime(void) {
|
||||
return SEGMENT_RUNTIME;
|
||||
}
|
||||
|
||||
WS2812FX::Segment* WS2812FX::getSegments(void) {
|
||||
return _segments;
|
||||
}
|
||||
|
||||
@@ -253,7 +261,6 @@ void WS2812FX::setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t mode
|
||||
void WS2812FX::resetSegments() {
|
||||
memset(_segments, 0, sizeof(_segments));
|
||||
memset(_segment_runtimes, 0, sizeof(_segment_runtimes));
|
||||
|
||||
_segment_index = 0;
|
||||
_num_segments = 1;
|
||||
setSegment(0, 0, 7, FX_MODE_STATIC, DEFAULT_COLOR, DEFAULT_SPEED, false);
|
||||
@@ -318,7 +325,7 @@ uint8_t WS2812FX::get_random_wheel_index(uint8_t pos) {
|
||||
*/
|
||||
uint16_t WS2812FX::mode_static(void) {
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(i, SEGMENT.colors[0]);
|
||||
this->setPixelColor(i, SEGMENT.colors[0]);
|
||||
}
|
||||
return 500;
|
||||
}
|
||||
@@ -334,7 +341,7 @@ uint16_t WS2812FX::blink(uint32_t color1, uint32_t color2, bool strobe) {
|
||||
if(SEGMENT.reverse) color = (color == color1) ? color2 : color1;
|
||||
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(i, color);
|
||||
this->setPixelColor(i, color);
|
||||
}
|
||||
|
||||
if((SEGMENT_RUNTIME.counter_mode_call & 1) == 0) {
|
||||
@@ -386,16 +393,16 @@ uint16_t WS2812FX::color_wipe(uint32_t color1, uint32_t color2, bool rev) {
|
||||
if(SEGMENT_RUNTIME.counter_mode_step < SEGMENT_LENGTH) {
|
||||
uint32_t led_offset = SEGMENT_RUNTIME.counter_mode_step;
|
||||
if(SEGMENT.reverse) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - led_offset, color1);
|
||||
this->setPixelColor(SEGMENT.stop - led_offset, color1);
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + led_offset, color1);
|
||||
this->setPixelColor(SEGMENT.start + led_offset, color1);
|
||||
}
|
||||
} else {
|
||||
uint32_t led_offset = SEGMENT_RUNTIME.counter_mode_step - SEGMENT_LENGTH;
|
||||
if((SEGMENT.reverse && !rev) || (!SEGMENT.reverse && rev)) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - led_offset, color2);
|
||||
this->setPixelColor(SEGMENT.stop - led_offset, color2);
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + led_offset, color2);
|
||||
this->setPixelColor(SEGMENT.start + led_offset, color2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -437,7 +444,7 @@ uint16_t WS2812FX::mode_color_wipe_random(void) {
|
||||
|
||||
|
||||
/*
|
||||
* Random color intruduced alternating from start and end of strip.
|
||||
* Random color introduced alternating from start and end of strip.
|
||||
*/
|
||||
uint16_t WS2812FX::mode_color_sweep_random(void) {
|
||||
if(SEGMENT_RUNTIME.counter_mode_step % SEGMENT_LENGTH == 0) { // aux_param will store our random color wheel index
|
||||
@@ -457,7 +464,7 @@ uint16_t WS2812FX::mode_random_color(void) {
|
||||
uint32_t color = color_wheel(SEGMENT_RUNTIME.aux_param);
|
||||
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(i, color);
|
||||
this->setPixelColor(i, color);
|
||||
}
|
||||
return (SEGMENT.speed);
|
||||
}
|
||||
@@ -470,11 +477,11 @@ uint16_t WS2812FX::mode_random_color(void) {
|
||||
uint16_t WS2812FX::mode_single_dynamic(void) {
|
||||
if(SEGMENT_RUNTIME.counter_mode_call == 0) {
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(i, color_wheel(random(256)));
|
||||
this->setPixelColor(i, color_wheel(random(256)));
|
||||
}
|
||||
}
|
||||
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), color_wheel(random(256)));
|
||||
this->setPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), color_wheel(random(256)));
|
||||
return (SEGMENT.speed);
|
||||
}
|
||||
|
||||
@@ -485,7 +492,7 @@ uint16_t WS2812FX::mode_single_dynamic(void) {
|
||||
*/
|
||||
uint16_t WS2812FX::mode_multi_dynamic(void) {
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(i, color_wheel(random(256)));
|
||||
this->setPixelColor(i, color_wheel(random(256)));
|
||||
}
|
||||
return (SEGMENT.speed);
|
||||
}
|
||||
@@ -523,7 +530,7 @@ uint16_t WS2812FX::mode_breath(void) {
|
||||
uint8_t g = (SEGMENT.colors[0] >> 8 & 0xFF) * lum / _brightness;
|
||||
uint8_t b = (SEGMENT.colors[0] & 0xFF) * lum / _brightness;
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(i, r, g, b, w);
|
||||
this->setPixelColor(i, r, g, b, w);
|
||||
}
|
||||
|
||||
SEGMENT_RUNTIME.aux_param = breath_brightness;
|
||||
@@ -544,7 +551,7 @@ uint16_t WS2812FX::mode_fade(void) {
|
||||
uint8_t g = (SEGMENT.colors[0] >> 8 & 0xFF) * lum / _brightness;
|
||||
uint8_t b = (SEGMENT.colors[0] & 0xFF) * lum / _brightness;
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(i, r, g, b, w);
|
||||
this->setPixelColor(i, r, g, b, w);
|
||||
}
|
||||
|
||||
SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % 64;
|
||||
@@ -561,16 +568,16 @@ uint16_t WS2812FX::mode_scan(void) {
|
||||
}
|
||||
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(i, BLACK);
|
||||
this->setPixelColor(i, BLACK);
|
||||
}
|
||||
|
||||
int led_offset = SEGMENT_RUNTIME.counter_mode_step - (SEGMENT_LENGTH - 1);
|
||||
led_offset = abs(led_offset);
|
||||
|
||||
if(SEGMENT.reverse) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - led_offset, SEGMENT.colors[0]);
|
||||
this->setPixelColor(SEGMENT.stop - led_offset, SEGMENT.colors[0]);
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + led_offset, SEGMENT.colors[0]);
|
||||
this->setPixelColor(SEGMENT.start + led_offset, SEGMENT.colors[0]);
|
||||
}
|
||||
|
||||
SEGMENT_RUNTIME.counter_mode_step++;
|
||||
@@ -587,14 +594,14 @@ uint16_t WS2812FX::mode_dual_scan(void) {
|
||||
}
|
||||
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(i, BLACK);
|
||||
this->setPixelColor(i, BLACK);
|
||||
}
|
||||
|
||||
int led_offset = SEGMENT_RUNTIME.counter_mode_step - (SEGMENT_LENGTH - 1);
|
||||
led_offset = abs(led_offset);
|
||||
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + led_offset, SEGMENT.colors[0]);
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + SEGMENT_LENGTH - led_offset - 1, SEGMENT.colors[0]);
|
||||
this->setPixelColor(SEGMENT.start + led_offset, SEGMENT.colors[0]);
|
||||
this->setPixelColor(SEGMENT.start + SEGMENT_LENGTH - led_offset - 1, SEGMENT.colors[0]);
|
||||
|
||||
SEGMENT_RUNTIME.counter_mode_step++;
|
||||
return (SEGMENT.speed / (SEGMENT_LENGTH * 2));
|
||||
@@ -607,7 +614,7 @@ uint16_t WS2812FX::mode_dual_scan(void) {
|
||||
uint16_t WS2812FX::mode_rainbow(void) {
|
||||
uint32_t color = color_wheel(SEGMENT_RUNTIME.counter_mode_step);
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(i, color);
|
||||
this->setPixelColor(i, color);
|
||||
}
|
||||
|
||||
SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) & 0xFF;
|
||||
@@ -621,7 +628,7 @@ uint16_t WS2812FX::mode_rainbow(void) {
|
||||
uint16_t WS2812FX::mode_rainbow_cycle(void) {
|
||||
for(uint16_t i=0; i < SEGMENT_LENGTH; i++) {
|
||||
uint32_t color = color_wheel(((i * 256 / SEGMENT_LENGTH) + SEGMENT_RUNTIME.counter_mode_step) & 0xFF);
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + i, color);
|
||||
this->setPixelColor(SEGMENT.start + i, color);
|
||||
}
|
||||
|
||||
SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) & 0xFF;
|
||||
@@ -637,15 +644,15 @@ uint16_t WS2812FX::theater_chase(uint32_t color1, uint32_t color2) {
|
||||
for(uint16_t i=0; i < SEGMENT_LENGTH; i++) {
|
||||
if((i % 3) == SEGMENT_RUNTIME.counter_mode_call) {
|
||||
if(SEGMENT.reverse) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - i, color1);
|
||||
this->setPixelColor(SEGMENT.stop - i, color1);
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + i, color1);
|
||||
this->setPixelColor(SEGMENT.start + i, color1);
|
||||
}
|
||||
} else {
|
||||
if(SEGMENT.reverse) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - i, color2);
|
||||
this->setPixelColor(SEGMENT.stop - i, color2);
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + i, color2);
|
||||
this->setPixelColor(SEGMENT.start + i, color2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -686,9 +693,9 @@ uint16_t WS2812FX::mode_running_lights(void) {
|
||||
for(uint16_t i=0; i < SEGMENT_LENGTH; i++) {
|
||||
int lum = map((int)(sin((i + SEGMENT_RUNTIME.counter_mode_step) * radPerLed) * 128), -128, 128, 0, 255);
|
||||
if(SEGMENT.reverse) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + i, (r * lum) / 256, (g * lum) / 256, (b * lum) / 256, (w * lum) / 256);
|
||||
this->setPixelColor(SEGMENT.start + i, (r * lum) / 256, (g * lum) / 256, (b * lum) / 256, (w * lum) / 256);
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - i, (r * lum) / 256, (g * lum) / 256, (b * lum) / 256, (w * lum) / 256);
|
||||
this->setPixelColor(SEGMENT.stop - i, (r * lum) / 256, (g * lum) / 256, (b * lum) / 256, (w * lum) / 256);
|
||||
}
|
||||
}
|
||||
SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH;
|
||||
@@ -702,14 +709,14 @@ uint16_t WS2812FX::mode_running_lights(void) {
|
||||
uint16_t WS2812FX::twinkle(uint32_t color) {
|
||||
if(SEGMENT_RUNTIME.counter_mode_step == 0) {
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(i, BLACK);
|
||||
this->setPixelColor(i, BLACK);
|
||||
}
|
||||
uint16_t min_leds = max(1, SEGMENT_LENGTH / 5); // make sure, at least one LED is on
|
||||
uint16_t max_leds = max(1, SEGMENT_LENGTH / 2); // make sure, at least one LED is on
|
||||
SEGMENT_RUNTIME.counter_mode_step = random(min_leds, max_leds);
|
||||
}
|
||||
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), color);
|
||||
this->setPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), color);
|
||||
|
||||
SEGMENT_RUNTIME.counter_mode_step--;
|
||||
return (SEGMENT.speed / SEGMENT_LENGTH);
|
||||
@@ -740,7 +747,7 @@ void WS2812FX::fade_out() {
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
uint32_t color = Adafruit_NeoPixel::getPixelColor(i);
|
||||
color = (color >> 1) & 0x7F7F7F7F;
|
||||
Adafruit_NeoPixel::setPixelColor(i, color);
|
||||
this->setPixelColor(i, color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -751,7 +758,7 @@ uint16_t WS2812FX::twinkle_fade(uint32_t color) {
|
||||
fade_out();
|
||||
|
||||
if(random(3) == 0) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), color);
|
||||
this->setPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), color);
|
||||
}
|
||||
return (SEGMENT.speed / 8);
|
||||
}
|
||||
@@ -778,9 +785,9 @@ uint16_t WS2812FX::mode_twinkle_fade_random(void) {
|
||||
* Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/
|
||||
*/
|
||||
uint16_t WS2812FX::mode_sparkle(void) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.aux_param, BLACK);
|
||||
this->setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.aux_param, BLACK);
|
||||
SEGMENT_RUNTIME.aux_param = random(SEGMENT_LENGTH); // aux_param stores the random led index
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.aux_param, SEGMENT.colors[0]);
|
||||
this->setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.aux_param, SEGMENT.colors[0]);
|
||||
return (SEGMENT.speed / SEGMENT_LENGTH);
|
||||
}
|
||||
|
||||
@@ -792,15 +799,15 @@ uint16_t WS2812FX::mode_sparkle(void) {
|
||||
uint16_t WS2812FX::mode_flash_sparkle(void) {
|
||||
if(SEGMENT_RUNTIME.counter_mode_call == 0) {
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(i, SEGMENT.colors[0]);
|
||||
this->setPixelColor(i, SEGMENT.colors[0]);
|
||||
}
|
||||
}
|
||||
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.aux_param, SEGMENT.colors[0]);
|
||||
this->setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.aux_param, SEGMENT.colors[0]);
|
||||
|
||||
if(random(5) == 0) {
|
||||
SEGMENT_RUNTIME.aux_param = random(SEGMENT_LENGTH); // aux_param stores the random led index
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.aux_param, WHITE);
|
||||
this->setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.aux_param, WHITE);
|
||||
return 20;
|
||||
}
|
||||
return SEGMENT.speed;
|
||||
@@ -813,12 +820,12 @@ uint16_t WS2812FX::mode_flash_sparkle(void) {
|
||||
*/
|
||||
uint16_t WS2812FX::mode_hyper_sparkle(void) {
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(i, SEGMENT.colors[0]);
|
||||
this->setPixelColor(i, SEGMENT.colors[0]);
|
||||
}
|
||||
|
||||
if(random(5) < 2) {
|
||||
for(uint16_t i=0; i < max(1, SEGMENT_LENGTH/3); i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), WHITE);
|
||||
this->setPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), WHITE);
|
||||
}
|
||||
return 20;
|
||||
}
|
||||
@@ -831,14 +838,14 @@ uint16_t WS2812FX::mode_hyper_sparkle(void) {
|
||||
*/
|
||||
uint16_t WS2812FX::mode_multi_strobe(void) {
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(i, BLACK);
|
||||
this->setPixelColor(i, BLACK);
|
||||
}
|
||||
|
||||
uint16_t delay = SEGMENT.speed / (2 * ((SEGMENT.speed / 10) + 1));
|
||||
if(SEGMENT_RUNTIME.counter_mode_step < (2 * ((SEGMENT.speed / 10) + 1))) {
|
||||
if((SEGMENT_RUNTIME.counter_mode_step & 1) == 0) {
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(i, SEGMENT.colors[0]);
|
||||
this->setPixelColor(i, SEGMENT.colors[0]);
|
||||
}
|
||||
delay = 20;
|
||||
} else {
|
||||
@@ -861,13 +868,13 @@ uint16_t WS2812FX::chase(uint32_t color1, uint32_t color2, uint32_t color3) {
|
||||
uint16_t b = (a + 1) % SEGMENT_LENGTH;
|
||||
uint16_t c = (b + 1) % SEGMENT_LENGTH;
|
||||
if(SEGMENT.reverse) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - a, color1);
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - b, color2);
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - c, color3);
|
||||
this->setPixelColor(SEGMENT.stop - a, color1);
|
||||
this->setPixelColor(SEGMENT.stop - b, color2);
|
||||
this->setPixelColor(SEGMENT.stop - c, color3);
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + a, color1);
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + b, color2);
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + c, color3);
|
||||
this->setPixelColor(SEGMENT.start + a, color1);
|
||||
this->setPixelColor(SEGMENT.start + b, color2);
|
||||
this->setPixelColor(SEGMENT.start + c, color3);
|
||||
}
|
||||
|
||||
SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH;
|
||||
@@ -963,7 +970,7 @@ uint16_t WS2812FX::mode_chase_flash(void) {
|
||||
uint8_t flash_step = SEGMENT_RUNTIME.counter_mode_call % ((flash_count * 2) + 1);
|
||||
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(i, SEGMENT.colors[0]);
|
||||
this->setPixelColor(i, SEGMENT.colors[0]);
|
||||
}
|
||||
|
||||
uint16_t delay = (SEGMENT.speed / SEGMENT_LENGTH);
|
||||
@@ -972,11 +979,11 @@ uint16_t WS2812FX::mode_chase_flash(void) {
|
||||
uint16_t n = SEGMENT_RUNTIME.counter_mode_step;
|
||||
uint16_t m = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH;
|
||||
if(SEGMENT.reverse) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - n, WHITE);
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - m, WHITE);
|
||||
this->setPixelColor(SEGMENT.stop - n, WHITE);
|
||||
this->setPixelColor(SEGMENT.stop - m, WHITE);
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + n, WHITE);
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + m, WHITE);
|
||||
this->setPixelColor(SEGMENT.start + n, WHITE);
|
||||
this->setPixelColor(SEGMENT.start + m, WHITE);
|
||||
}
|
||||
delay = 20;
|
||||
} else {
|
||||
@@ -997,7 +1004,7 @@ uint16_t WS2812FX::mode_chase_flash_random(void) {
|
||||
uint8_t flash_step = SEGMENT_RUNTIME.counter_mode_call % ((flash_count * 2) + 1);
|
||||
|
||||
for(uint16_t i=0; i < SEGMENT_RUNTIME.counter_mode_step; i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + i, color_wheel(SEGMENT_RUNTIME.aux_param));
|
||||
this->setPixelColor(SEGMENT.start + i, color_wheel(SEGMENT_RUNTIME.aux_param));
|
||||
}
|
||||
|
||||
uint16_t delay = (SEGMENT.speed / SEGMENT_LENGTH);
|
||||
@@ -1005,12 +1012,12 @@ uint16_t WS2812FX::mode_chase_flash_random(void) {
|
||||
uint16_t n = SEGMENT_RUNTIME.counter_mode_step;
|
||||
uint16_t m = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH;
|
||||
if(flash_step % 2 == 0) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + n, WHITE);
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + m, WHITE);
|
||||
this->setPixelColor(SEGMENT.start + n, WHITE);
|
||||
this->setPixelColor(SEGMENT.start + m, WHITE);
|
||||
delay = 20;
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + n, color_wheel(SEGMENT_RUNTIME.aux_param));
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + m, BLACK);
|
||||
this->setPixelColor(SEGMENT.start + n, color_wheel(SEGMENT_RUNTIME.aux_param));
|
||||
this->setPixelColor(SEGMENT.start + m, BLACK);
|
||||
delay = 30;
|
||||
}
|
||||
} else {
|
||||
@@ -1031,15 +1038,15 @@ uint16_t WS2812FX::running(uint32_t color1, uint32_t color2) {
|
||||
for(uint16_t i=0; i < SEGMENT_LENGTH; i++) {
|
||||
if((i + SEGMENT_RUNTIME.counter_mode_step) % 4 < 2) {
|
||||
if(SEGMENT.reverse) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + i, color1);
|
||||
this->setPixelColor(SEGMENT.start + i, color1);
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - i, color1);
|
||||
this->setPixelColor(SEGMENT.stop - i, color1);
|
||||
}
|
||||
} else {
|
||||
if(SEGMENT.reverse) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + i, color2);
|
||||
this->setPixelColor(SEGMENT.start + i, color2);
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - i, color2);
|
||||
this->setPixelColor(SEGMENT.stop - i, color2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1085,18 +1092,18 @@ uint16_t WS2812FX::mode_halloween(void) {
|
||||
uint16_t WS2812FX::mode_running_random(void) {
|
||||
for(uint16_t i=SEGMENT_LENGTH-1; i > 0; i--) {
|
||||
if(SEGMENT.reverse) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - i, Adafruit_NeoPixel::getPixelColor(SEGMENT.stop - i + 1));
|
||||
this->setPixelColor(SEGMENT.stop - i, Adafruit_NeoPixel::getPixelColor(SEGMENT.stop - i + 1));
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + i, Adafruit_NeoPixel::getPixelColor(SEGMENT.start + i - 1));
|
||||
this->setPixelColor(SEGMENT.start + i, Adafruit_NeoPixel::getPixelColor(SEGMENT.start + i - 1));
|
||||
}
|
||||
}
|
||||
|
||||
if(SEGMENT_RUNTIME.counter_mode_step == 0) {
|
||||
SEGMENT_RUNTIME.aux_param = get_random_wheel_index(SEGMENT_RUNTIME.aux_param);
|
||||
if(SEGMENT.reverse) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop, color_wheel(SEGMENT_RUNTIME.aux_param));
|
||||
this->setPixelColor(SEGMENT.stop, color_wheel(SEGMENT_RUNTIME.aux_param));
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start, color_wheel(SEGMENT_RUNTIME.aux_param));
|
||||
this->setPixelColor(SEGMENT.start, color_wheel(SEGMENT_RUNTIME.aux_param));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1113,15 +1120,15 @@ uint16_t WS2812FX::mode_larson_scanner(void) {
|
||||
|
||||
if(SEGMENT_RUNTIME.counter_mode_step < SEGMENT_LENGTH) {
|
||||
if(SEGMENT.reverse) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - SEGMENT_RUNTIME.counter_mode_step, SEGMENT.colors[0]);
|
||||
this->setPixelColor(SEGMENT.stop - SEGMENT_RUNTIME.counter_mode_step, SEGMENT.colors[0]);
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step, SEGMENT.colors[0]);
|
||||
this->setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step, SEGMENT.colors[0]);
|
||||
}
|
||||
} else {
|
||||
if(SEGMENT.reverse) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - ((SEGMENT_LENGTH * 2) - SEGMENT_RUNTIME.counter_mode_step) + 2, SEGMENT.colors[0]);
|
||||
this->setPixelColor(SEGMENT.stop - ((SEGMENT_LENGTH * 2) - SEGMENT_RUNTIME.counter_mode_step) + 2, SEGMENT.colors[0]);
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + ((SEGMENT_LENGTH * 2) - SEGMENT_RUNTIME.counter_mode_step) - 2, SEGMENT.colors[0]);
|
||||
this->setPixelColor(SEGMENT.start + ((SEGMENT_LENGTH * 2) - SEGMENT_RUNTIME.counter_mode_step) - 2, SEGMENT.colors[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1137,9 +1144,9 @@ uint16_t WS2812FX::mode_comet(void) {
|
||||
fade_out();
|
||||
|
||||
if(SEGMENT.reverse) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - SEGMENT_RUNTIME.counter_mode_step, SEGMENT.colors[0]);
|
||||
this->setPixelColor(SEGMENT.stop - SEGMENT_RUNTIME.counter_mode_step, SEGMENT.colors[0]);
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step, SEGMENT.colors[0]);
|
||||
this->setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step, SEGMENT.colors[0]);
|
||||
}
|
||||
|
||||
SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH;
|
||||
@@ -1166,7 +1173,7 @@ uint32_t prevLed, thisLed, nextLed;
|
||||
px_r = (((Adafruit_NeoPixel::getPixelColor(SEGMENT.start+1) & 0xFF0000) >> 16) >> 1) + ((Adafruit_NeoPixel::getPixelColor(SEGMENT.start) & 0xFF0000) >> 16);
|
||||
px_g = (((Adafruit_NeoPixel::getPixelColor(SEGMENT.start+1) & 0x00FF00) >> 8) >> 1) + ((Adafruit_NeoPixel::getPixelColor(SEGMENT.start) & 0x00FF00) >> 8);
|
||||
px_b = (((Adafruit_NeoPixel::getPixelColor(SEGMENT.start+1) & 0x0000FF) ) >> 1) + ((Adafruit_NeoPixel::getPixelColor(SEGMENT.start) & 0x0000FF));
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start, px_r, px_g, px_b);
|
||||
this->setPixelColor(SEGMENT.start, px_r, px_g, px_b);
|
||||
*/
|
||||
// set brightness(i) = ((brightness(i-1)/2 + brightness(i+1)) / 2) + brightness(i)
|
||||
for(uint16_t i=SEGMENT.start + 1; i <SEGMENT.stop; i++) {
|
||||
@@ -1174,7 +1181,7 @@ uint32_t prevLed, thisLed, nextLed;
|
||||
prevLed = (Adafruit_NeoPixel::getPixelColor(i-1) >> 2) & 0x3F3F3F3F;
|
||||
thisLed = Adafruit_NeoPixel::getPixelColor(i);
|
||||
nextLed = (Adafruit_NeoPixel::getPixelColor(i+1) >> 2) & 0x3F3F3F3F;
|
||||
Adafruit_NeoPixel::setPixelColor(i, prevLed + thisLed + nextLed);
|
||||
this->setPixelColor(i, prevLed + thisLed + nextLed);
|
||||
|
||||
/* the old way
|
||||
px_r = ((
|
||||
@@ -1192,7 +1199,7 @@ uint32_t prevLed, thisLed, nextLed;
|
||||
(((Adafruit_NeoPixel::getPixelColor(i+1) & 0x0000FF) ) ) ) >> 1) +
|
||||
(((Adafruit_NeoPixel::getPixelColor(i ) & 0x0000FF) ) );
|
||||
|
||||
Adafruit_NeoPixel::setPixelColor(i, px_r, px_g, px_b);
|
||||
this->setPixelColor(i, px_r, px_g, px_b);
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -1201,17 +1208,17 @@ uint32_t prevLed, thisLed, nextLed;
|
||||
px_r = (((Adafruit_NeoPixel::getPixelColor(SEGMENT.stop-1) & 0xFF0000) >> 16) >> 2) + ((Adafruit_NeoPixel::getPixelColor(SEGMENT.stop) & 0xFF0000) >> 16);
|
||||
px_g = (((Adafruit_NeoPixel::getPixelColor(SEGMENT.stop-1) & 0x00FF00) >> 8) >> 2) + ((Adafruit_NeoPixel::getPixelColor(SEGMENT.stop) & 0x00FF00) >> 8);
|
||||
px_b = (((Adafruit_NeoPixel::getPixelColor(SEGMENT.stop-1) & 0x0000FF) ) >> 2) + ((Adafruit_NeoPixel::getPixelColor(SEGMENT.stop) & 0x0000FF));
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop, px_r, px_g, px_b);
|
||||
this->setPixelColor(SEGMENT.stop, px_r, px_g, px_b);
|
||||
*/
|
||||
if(!_triggered) {
|
||||
for(uint16_t i=0; i<max(1, SEGMENT_LENGTH/20); i++) {
|
||||
if(random(10) == 0) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), color);
|
||||
this->setPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), color);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(uint16_t i=0; i<max(1, SEGMENT_LENGTH/10); i++) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), color);
|
||||
this->setPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), color);
|
||||
}
|
||||
}
|
||||
return (SEGMENT.speed / SEGMENT_LENGTH);
|
||||
@@ -1247,7 +1254,7 @@ uint16_t WS2812FX::fire_flicker(int rev_intensity) {
|
||||
byte lum = max(w, max(r, max(g, b))) / rev_intensity;
|
||||
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
int flicker = random(0, lum);
|
||||
Adafruit_NeoPixel::setPixelColor(i, max(r - flicker, 0), max(g - flicker, 0), max(b - flicker, 0), max(w - flicker, 0));
|
||||
this->setPixelColor(i, max(r - flicker, 0), max(g - flicker, 0), max(b - flicker, 0), max(w - flicker, 0));
|
||||
}
|
||||
return (SEGMENT.speed / SEGMENT_LENGTH);
|
||||
}
|
||||
@@ -1260,14 +1267,14 @@ uint16_t WS2812FX::mode_fire_flicker(void) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Random flickering, less intesity.
|
||||
* Random flickering, less intensity.
|
||||
*/
|
||||
uint16_t WS2812FX::mode_fire_flicker_soft(void) {
|
||||
return fire_flicker(6);
|
||||
}
|
||||
|
||||
/*
|
||||
* Random flickering, more intesity.
|
||||
* Random flickering, more intensity.
|
||||
*/
|
||||
uint16_t WS2812FX::mode_fire_flicker_intense(void) {
|
||||
return fire_flicker(1.7);
|
||||
@@ -1281,21 +1288,21 @@ uint16_t WS2812FX::tricolor_chase(uint32_t color1, uint32_t color2, uint32_t col
|
||||
for(uint16_t i=0; i < SEGMENT_LENGTH; i++) {
|
||||
if((i + SEGMENT_RUNTIME.counter_mode_step) % 6 < 2) {
|
||||
if(SEGMENT.reverse) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + i, color1);
|
||||
this->setPixelColor(SEGMENT.start + i, color1);
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - i, color1);
|
||||
this->setPixelColor(SEGMENT.stop - i, color1);
|
||||
}
|
||||
} else if((i + SEGMENT_RUNTIME.counter_mode_step) % 6 < 4) {
|
||||
if(SEGMENT.reverse) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + i, color2);
|
||||
this->setPixelColor(SEGMENT.start + i, color2);
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - i, color2);
|
||||
this->setPixelColor(SEGMENT.stop - i, color2);
|
||||
}
|
||||
} else {
|
||||
if(SEGMENT.reverse) {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + i, color3);
|
||||
this->setPixelColor(SEGMENT.start + i, color3);
|
||||
} else {
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.stop - i, color3);
|
||||
this->setPixelColor(SEGMENT.stop - i, color3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1323,24 +1330,24 @@ uint16_t WS2812FX::mode_circus_combustus(void) {
|
||||
/*
|
||||
* ICU mode
|
||||
*/
|
||||
uint16_t WS2812FX::mode_icu() {
|
||||
uint16_t WS2812FX::mode_icu(void) {
|
||||
uint16_t dest = SEGMENT_RUNTIME.counter_mode_step & 0xFFFF;
|
||||
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + dest, SEGMENT.colors[0]);
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + dest + SEGMENT_LENGTH/2, SEGMENT.colors[0]);
|
||||
this->setPixelColor(SEGMENT.start + dest, SEGMENT.colors[0]);
|
||||
this->setPixelColor(SEGMENT.start + dest + SEGMENT_LENGTH/2, SEGMENT.colors[0]);
|
||||
|
||||
if(SEGMENT_RUNTIME.aux_param == dest) { // pause between eye movements
|
||||
if(random(6) == 0) { // blink once in a while
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + dest, 0);
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + dest + SEGMENT_LENGTH/2, 0);
|
||||
this->setPixelColor(SEGMENT.start + dest, 0);
|
||||
this->setPixelColor(SEGMENT.start + dest + SEGMENT_LENGTH/2, 0);
|
||||
return 200;
|
||||
}
|
||||
SEGMENT_RUNTIME.aux_param = random(SEGMENT_LENGTH/2);
|
||||
return 1000 + random(2000);
|
||||
}
|
||||
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + dest, 0);
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + dest + SEGMENT_LENGTH/2, 0);
|
||||
this->setPixelColor(SEGMENT.start + dest, 0);
|
||||
this->setPixelColor(SEGMENT.start + dest + SEGMENT_LENGTH/2, 0);
|
||||
|
||||
if(SEGMENT_RUNTIME.aux_param > SEGMENT_RUNTIME.counter_mode_step) {
|
||||
SEGMENT_RUNTIME.counter_mode_step++;
|
||||
@@ -1350,8 +1357,8 @@ uint16_t WS2812FX::mode_icu() {
|
||||
dest--;
|
||||
}
|
||||
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + dest, SEGMENT.colors[0]);
|
||||
Adafruit_NeoPixel::setPixelColor(SEGMENT.start + dest + SEGMENT_LENGTH/2, SEGMENT.colors[0]);
|
||||
this->setPixelColor(SEGMENT.start + dest, SEGMENT.colors[0]);
|
||||
this->setPixelColor(SEGMENT.start + dest + SEGMENT_LENGTH/2, SEGMENT.colors[0]);
|
||||
|
||||
return (SEGMENT.speed / SEGMENT_LENGTH);
|
||||
}
|
||||
@@ -1372,6 +1379,5 @@ uint16_t WS2812FX::mode_custom() {
|
||||
* Custom mode helper
|
||||
*/
|
||||
void WS2812FX::setCustomMode(uint16_t (*p)()) {
|
||||
setMode(FX_MODE_CUSTOM);
|
||||
customMode = p;
|
||||
}
|
||||
@@ -5,9 +5,9 @@
|
||||
www.aldick.org
|
||||
FEATURES
|
||||
* A lot of blinken modes and counting
|
||||
* WS2812FX can be used as drop-in replacement for Adafruit Neopixel Library
|
||||
* WS2812FX can be used as drop-in replacement for Adafruit NeoPixel Library
|
||||
NOTES
|
||||
* Uses the Adafruit Neopixel library. Get it here:
|
||||
* Uses the Adafruit NeoPixel library. Get it here:
|
||||
https://github.com/adafruit/Adafruit_NeoPixel
|
||||
LICENSE
|
||||
The MIT License (MIT)
|
||||
@@ -50,8 +50,8 @@
|
||||
#define BRIGHTNESS_MIN 0
|
||||
#define BRIGHTNESS_MAX 255
|
||||
|
||||
|
||||
|
||||
/* each segment uses 36 bytes of SRAM memory, so if you're application fails because of
|
||||
insufficient memory, decreasing MAX_NUM_SEGMENTS may help */
|
||||
#define MAX_NUM_SEGMENTS 10
|
||||
#define NUM_COLORS 4 /* number of colors per segment */
|
||||
#define SEGMENT _segments[_segment_index]
|
||||
@@ -138,25 +138,26 @@ class WS2812FX : public Adafruit_NeoPixel {
|
||||
|
||||
// segment parameters
|
||||
public:
|
||||
typedef struct segment {
|
||||
uint8_t mode;
|
||||
uint32_t colors[NUM_COLORS];
|
||||
uint16_t speed;
|
||||
typedef struct Segment { // 20 bytes
|
||||
uint16_t start;
|
||||
uint16_t stop;
|
||||
uint16_t speed;
|
||||
uint8_t mode;
|
||||
bool reverse;
|
||||
uint32_t colors[NUM_COLORS];
|
||||
} segment;
|
||||
|
||||
// segment runtime parameters
|
||||
typedef struct segment_runtime {
|
||||
public:
|
||||
typedef struct Segment_runtime { // 16 bytes
|
||||
unsigned long next_time;
|
||||
uint32_t counter_mode_step;
|
||||
uint32_t counter_mode_call;
|
||||
unsigned long next_time;
|
||||
uint16_t aux_param;
|
||||
uint16_t aux_param2;
|
||||
} segment_runtime;
|
||||
|
||||
public:
|
||||
|
||||
WS2812FX(uint16_t n, uint8_t p, neoPixelType t) : Adafruit_NeoPixel(n, p, t) {
|
||||
_mode[FX_MODE_STATIC] = &WS2812FX::mode_static;
|
||||
_mode[FX_MODE_BLINK] = &WS2812FX::mode_blink;
|
||||
@@ -211,7 +212,7 @@ class WS2812FX : public Adafruit_NeoPixel {
|
||||
_mode[FX_MODE_CIRCUS_COMBUSTUS] = &WS2812FX::mode_circus_combustus;
|
||||
_mode[FX_MODE_BICOLOR_CHASE] = &WS2812FX::mode_bicolor_chase;
|
||||
_mode[FX_MODE_TRICOLOR_CHASE] = &WS2812FX::mode_tricolor_chase;
|
||||
// if flash memory is constrained (i'm looking at you Adruino Nano), replace modes
|
||||
// if flash memory is constrained (I'm looking at you Arduino Nano), replace modes
|
||||
// that use a lot of flash with mode_static (reduces flash footprint by about 3600 bytes)
|
||||
#ifdef REDUCED_MODES
|
||||
_mode[FX_MODE_BREATH] = &WS2812FX::mode_static;
|
||||
@@ -337,7 +338,13 @@ class WS2812FX : public Adafruit_NeoPixel {
|
||||
const __FlashStringHelper*
|
||||
getModeName(uint8_t m);
|
||||
|
||||
WS2812FX::segment*
|
||||
WS2812FX::Segment
|
||||
getSegment(void);
|
||||
|
||||
WS2812FX::Segment_runtime
|
||||
getSegmentRuntime(void);
|
||||
|
||||
WS2812FX::Segment*
|
||||
getSegments(void);
|
||||
|
||||
private:
|
||||
@@ -431,10 +438,10 @@ class WS2812FX : public Adafruit_NeoPixel {
|
||||
uint8_t _segment_index = 0;
|
||||
uint8_t _num_segments = 1;
|
||||
segment _segments[MAX_NUM_SEGMENTS] = { // SRAM footprint: 20 bytes per element
|
||||
// mode, color[], speed, start, stop, reverse
|
||||
{ FX_MODE_STATIC, {DEFAULT_COLOR}, DEFAULT_SPEED, 0, 7, false}
|
||||
// start, stop, speed, mode, reverse, color[]
|
||||
{ 0, 7, DEFAULT_SPEED, FX_MODE_STATIC, false, {DEFAULT_COLOR}}
|
||||
};
|
||||
segment_runtime _segment_runtimes[MAX_NUM_SEGMENTS]; // SRAM footprint: 14 bytes per element
|
||||
segment_runtime _segment_runtimes[MAX_NUM_SEGMENTS]; // SRAM footprint: 16 bytes per element
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
<!--
|
||||
FSWebServer - Example Index Page
|
||||
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
|
||||
This file is part of the ESP8266WebServer library for Arduino environment.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
||||
<title>ESP Monitor</title>
|
||||
<script type="text/javascript" src="graphs.js"></script>
|
||||
<script type="text/javascript">
|
||||
var heap,temp,digi;
|
||||
var reloadPeriod = 1000;
|
||||
var running = false;
|
||||
|
||||
function loadValues(){
|
||||
if(!running) return;
|
||||
var xh = new XMLHttpRequest();
|
||||
xh.onreadystatechange = function(){
|
||||
if (xh.readyState == 4){
|
||||
if(xh.status == 200) {
|
||||
var res = JSON.parse(xh.responseText);
|
||||
heap.add(res.heap);
|
||||
temp.add(res.analog);
|
||||
digi.add(res.gpio);
|
||||
if(running) setTimeout(loadValues, reloadPeriod);
|
||||
} else running = false;
|
||||
}
|
||||
};
|
||||
xh.open("GET", "/status", true);
|
||||
xh.send(null);
|
||||
};
|
||||
|
||||
function run(){
|
||||
if(!running){
|
||||
running = true;
|
||||
loadValues();
|
||||
}
|
||||
}
|
||||
|
||||
function onBodyLoad(){
|
||||
var refreshInput = document.getElementById("refresh-rate");
|
||||
refreshInput.value = reloadPeriod;
|
||||
refreshInput.onchange = function(e){
|
||||
var value = parseInt(e.target.value);
|
||||
reloadPeriod = (value > 0)?value:0;
|
||||
e.target.value = reloadPeriod;
|
||||
}
|
||||
var stopButton = document.getElementById("stop-button");
|
||||
stopButton.onclick = function(e){
|
||||
running = false;
|
||||
}
|
||||
var startButton = document.getElementById("start-button");
|
||||
startButton.onclick = function(e){
|
||||
run();
|
||||
}
|
||||
|
||||
// Example with 10K thermistor
|
||||
//function calcThermistor(v) {
|
||||
// var t = Math.log(((10230000 / v) - 10000));
|
||||
// t = (1/(0.001129148+(0.000234125*t)+(0.0000000876741*t*t*t)))-273.15;
|
||||
// return (t>120)?0:Math.round(t*10)/10;
|
||||
//}
|
||||
//temp = createGraph(document.getElementById("analog"), "Temperature", 100, 128, 10, 40, false, "cyan", calcThermistor);
|
||||
|
||||
temp = createGraph(document.getElementById("analog"), "Analog Input", 100, 128, 0, 1023, false, "cyan");
|
||||
heap = createGraph(document.getElementById("heap"), "Current Heap", 100, 125, 0, 30000, true, "orange");
|
||||
digi = createDigiGraph(document.getElementById("digital"), "GPIO", 100, 146, [0, 4, 5, 16], "gold");
|
||||
run();
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body id="index" style="margin:0; padding:0;" onload="onBodyLoad()">
|
||||
<div id="controls" style="display: block; border: 1px solid rgb(68, 68, 68); padding: 5px; margin: 5px; width: 362px; background-color: rgb(238, 238, 238);">
|
||||
<label>Period (ms):</label>
|
||||
<input type="number" id="refresh-rate"/>
|
||||
<input type="button" id="start-button" value="Start"/>
|
||||
<input type="button" id="stop-button" value="Stop"/>
|
||||
</div>
|
||||
<div id="heap"></div>
|
||||
<div id="analog"></div>
|
||||
<div id="digital"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,14 +1,37 @@
|
||||
//#define USE_NEOANIMATIONFX // Uses NeoAnimationFX, PIN is ignored & set to RX/GPIO3, see: https://github.com/debsahu/NeoAnimationFX
|
||||
#define USE_WS2812FX // Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
|
||||
|
||||
// Neopixel
|
||||
#define PIN 2 // PIN (5 / D1) where neopixel / WS2811 strip is attached
|
||||
#define NUMLEDS 144 // Number of leds in the strip
|
||||
//#define BUILTIN_LED 2 // ESP-12F has the built in LED on GPIO2, see https://github.com/esp8266/Arduino/issues/2192
|
||||
#define BUTTON 0 // Input pin (4 / D2) for switching the LED strip on / off, connect this PIN to ground to trigger button.
|
||||
#define PIN 15 // PIN (15 / D8) where neopixel / WS2811 strip is attached
|
||||
#define NUMLEDS 194 // Number of leds in the strip
|
||||
#define BUILTIN_LED 2 // ESP-12F has the built in LED on GPIO2, see https://github.com/esp8266/Arduino/issues/2192
|
||||
#define BUTTON 14 // Input pin (14 / D5) for switching the LED strip on / off, connect this PIN to ground to trigger button.
|
||||
#define BUTTON2 12 // Input pin (12 / D6) for read color data with RGB sensor, connect this PIN to ground to trigger button.
|
||||
|
||||
const char HOSTNAME[] = "ESPLightRGBW01"; // Friedly hostname
|
||||
const char HOSTNAME[] = "ESPLightRGBW02"; // Friedly hostname
|
||||
|
||||
#define ENABLE_OTA // If defined, enable Arduino OTA code.
|
||||
#define ENABLE_MQTT // If defined, enable MQTT client code, see: https://github.com/toblum/McLighting/wiki/MQTT-API
|
||||
#define HTTP_OTA // If defined, enable Added ESP8266HTTPUpdateServer
|
||||
//#define ENABLE_OTA // If defined, enable Arduino OTA code.
|
||||
#define ENABLE_AMQTT // If defined, enable Async MQTT code, see: https://github.com/marvinroger/async-mqtt-client
|
||||
//#define ENABLE_MQTT // If defined, enable MQTT client code, see: https://github.com/toblum/McLighting/wiki/MQTT-API
|
||||
#define ENABLE_HOMEASSISTANT // If defined, enable Homeassistant integration, ENABLE_MQTT must be active
|
||||
#define ENABLE_BUTTON // If defined, enable button handling code, see: https://github.com/toblum/McLighting/wiki/Button-control
|
||||
#define ENABLE_BUTTON2 //
|
||||
//#define MQTT_HOME_ASSISTANT_SUPPORT // If defined, use AMQTT and select Tools -> IwIP Variant -> Higher Bandwidth
|
||||
|
||||
|
||||
#if defined(USE_NEOANIMATIONFX) and defined(USE_WS2812FX)
|
||||
#error "Cant have both NeoAnimationFX and WS2812FX enabled. Choose either one."
|
||||
#endif
|
||||
#if !defined(USE_NEOANIMATIONFX) and !defined(USE_WS2812FX)
|
||||
#error "Need to either use NeoAnimationFX and WS2812FX mode."
|
||||
#endif
|
||||
#if defined(ENABLE_MQTT) and defined(ENABLE_AMQTT)
|
||||
#error "Cant have both PubSubClient and AsyncMQTT enabled. Choose either one."
|
||||
#endif
|
||||
#if ( (defined(ENABLE_HOMEASSISTANT) and !defined(ENABLE_MQTT)) and (defined(ENABLE_HOMEASSISTANT) and !defined(ENABLE_AMQTT)) )
|
||||
#error "To use HA, you have to either enable PubCubClient or AsyncMQTT"
|
||||
#endif
|
||||
|
||||
// parameters for automatically cycling favorite patterns
|
||||
uint32_t autoParams[][4] = { // color, speed, mode, duration (seconds)
|
||||
@@ -18,15 +41,38 @@ uint32_t autoParams[][4] = { // color, speed, mode, duration (seconds)
|
||||
{0x000000ff, 200, 46, 15.0} // fireworks for 15 seconds
|
||||
};
|
||||
|
||||
#if defined(ENABLE_MQTT) or defined(ENABLE_AMQTT)
|
||||
#ifdef ENABLE_MQTT
|
||||
#define MQTT_MAX_PACKET_SIZE 256
|
||||
#define MQTT_MAX_PACKET_SIZE 512
|
||||
#define MQTT_MAX_RECONNECT_TRIES 4
|
||||
|
||||
int mqtt_reconnect_retries = 0;
|
||||
char mqtt_intopic[strlen(HOSTNAME) + 4]; // Topic in will be: <HOSTNAME>/in
|
||||
char mqtt_outtopic[strlen(HOSTNAME) + 5]; // Topic out will be: <HOSTNAME>/out
|
||||
char mqtt_intopic[strlen(HOSTNAME) + 4 + 5]; // Topic in will be: <HOSTNAME>/in
|
||||
char mqtt_outtopic[strlen(HOSTNAME) + 5 + 5]; // Topic out will be: <HOSTNAME>/out
|
||||
uint8_t qossub = 0; // PubSubClient can sub qos 0 or 1
|
||||
#endif
|
||||
|
||||
const char mqtt_clientid[] = "ESPLightMax"; // MQTT ClientID
|
||||
#ifdef ENABLE_AMQTT
|
||||
String mqtt_intopic = String(HOSTNAME) + "/in";
|
||||
String mqtt_outtopic = String(HOSTNAME) + "/out";
|
||||
uint8_t qossub = 0; // AMQTT can sub qos 0 or 1 or 2
|
||||
uint8_t qospub = 0; // AMQTT can pub qos 0 or 1 or 2
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_HOMEASSISTANT
|
||||
String mqtt_ha = "home/" + String(HOSTNAME) + "_ha/";
|
||||
String mqtt_ha_state_in = mqtt_ha + "state/in";
|
||||
String mqtt_ha_state_out = mqtt_ha + "state/out";
|
||||
|
||||
const char* on_cmd = "ON";
|
||||
const char* off_cmd = "OFF";
|
||||
bool stateOn = false;
|
||||
bool animation_on = false;
|
||||
bool new_ha_mqtt_msg = false;
|
||||
uint16_t color_temp = 327; // min is 154 and max is 500
|
||||
#endif
|
||||
|
||||
const char mqtt_clientid[] = "NeoPixelsStrip"; // MQTT ClientID
|
||||
|
||||
char mqtt_host[64] = "";
|
||||
char mqtt_port[6] = "";
|
||||
@@ -41,7 +87,7 @@ uint32_t autoParams[][4] = { // color, speed, mode, duration (seconds)
|
||||
#define DBG_OUTPUT_PORT Serial // Set debug output port
|
||||
|
||||
// List of all color modes
|
||||
enum MODE { SET_MODE, HOLD, OFF, ALL, WIPE, RAINBOW, RAINBOWCYCLE, THEATERCHASE, TWINKLERANDOM, THEATERCHASERAINBOW, TV, CUSTOM, AUTO };
|
||||
enum MODE { SET_MODE, HOLD, OFF, ALL, SETCOLOR, SETSPEED, BRIGHTNESS, WIPE, RAINBOW, RAINBOWCYCLE, THEATERCHASE, TWINKLERANDOM, THEATERCHASERAINBOW, TV, CUSTOM, AUTO };
|
||||
|
||||
MODE mode = RAINBOW; // Standard mode that is active when software starts
|
||||
|
||||
@@ -66,7 +112,8 @@ typedef struct ledstate LEDState; // Define the datatype LEDState
|
||||
LEDState ledstates[NUMLEDS]; // Get an array of led states to store the state of the whole strip
|
||||
LEDState main_color = { 0, 255, 0, 0}; // Store the "main color" of the strip used in single color modes
|
||||
|
||||
#define ENABLE_STATE_SAVE // If defined, save state on reboot
|
||||
#define ENABLE_STATE_SAVE_SPIFFS // If defined, saves state on SPIFFS
|
||||
//#define ENABLE_STATE_SAVE_EEPROM // If defined, save state on reboot
|
||||
#ifdef ENABLE_STATE_SAVE
|
||||
char current_state[36]; // Keeps the current state representation
|
||||
char last_state[36]; // Save the last state as string representation
|
||||
@@ -74,10 +121,18 @@ LEDState main_color = { 0, 255, 0, 0}; // Store the "main color" of the strip u
|
||||
int timeout_statechange_save = 5000; // Timeout in ms to wait before state is saved
|
||||
bool state_save_requested = false; // State has to be saved after timeout
|
||||
#endif
|
||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
bool updateStateFS = false;
|
||||
#endif
|
||||
|
||||
// Button handling
|
||||
|
||||
#ifdef ENABLE_BUTTON || ENABLE_BUTTON2
|
||||
boolean buttonState = false;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_BUTTON
|
||||
#define BTN_MODE_SHORT "STA| 1| 0|245|196| 0|255|255|255" // Static white
|
||||
#define BTN_MODE_SHORT "STA| 1| 0|245|196|255| 0| 0| 0" // Static white
|
||||
#define BTN_MODE_MEDIUM "STA| 1| 48|245|196| 0|255|102| 0" // Fire flicker
|
||||
#define BTN_MODE_LONG "STA| 1| 46|253|196| 0|255|102| 0" // Fireworks random
|
||||
|
||||
@@ -87,5 +142,18 @@ LEDState main_color = { 0, 255, 0, 0}; // Store the "main color" of the strip u
|
||||
byte mediumKeyPressCountMin = 20; // 20 * 25 = 500 ms
|
||||
byte KeyPressCount = 0;
|
||||
byte prevKeyState = HIGH; // button is active low
|
||||
boolean buttonState = false;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_BUTTON2
|
||||
#define BTN_MODE_SHORT "STA| 1| 0|245|196|255| 0| 0| 0" // Static white
|
||||
#define BTN_MODE_MEDIUM "STA| 1| 48|245|196| 0|255|102| 0" // Fire flicker
|
||||
#define BTN_MODE_LONG "STA| 1| 46|253|196| 0|255|102| 0" // Fireworks random
|
||||
|
||||
unsigned long keyPrevMillis2 = 0;
|
||||
const unsigned long keySampleIntervalMs2 = 25;
|
||||
byte longKeyPressCountMax2 = 80; // 80 * 25 = 2000 ms
|
||||
byte mediumKeyPressCountMin2 = 20; // 20 * 25 = 500 ms
|
||||
byte KeyPressCount2 = 0;
|
||||
byte prevKeyState2 = HIGH; // button is active low
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,12 +6,36 @@
|
||||
|
||||
> Because of it's open architecture and APIs it's easy to build new clients for different platforms (iOS, Android, Windows Universal Apps, Siri/Cortana integration, ...).
|
||||
|
||||
[](https://youtu.be/rc6QVHKAXBs)
|
||||
|
||||
[](https://youtu.be/4JnGXZaPnrw)
|
||||
|
||||
___
|
||||
Update 07.04.2018:
|
||||
And even more changes to McLighting! Most of them were contributed by user @debsahu. Thank you!
|
||||
- Update arduino-esp8266 to latest, at least version 2.4.1
|
||||
- AMQTT is now the default MQTT library, it's a bit more lightweight and stable. You can still use PubSubClient if you want to.
|
||||
- You can use @debsahu great NeoAnimationFX library as a alternative to WS2812FX. It's based on the NeoPixelBus instead of Adafruits NeoPixel library. It can handle longer strips more efficient. If you want, give it a try. WS2812FX is still the default.
|
||||
- Some more changes regarding Homeassistant integration.
|
||||
Please see the [Wiki](https://github.com/toblum/McLighting/wiki/Software-installation) for details on the required libraries.
|
||||
If you have problems with the new version, let us know. You can get the last version [here](https://github.com/toblum/McLighting/tree/Before_AMQTT_NeoAnimationFX).
|
||||
|
||||
I'm also working on a alternative web interface for McLighting in the meanwhile, but it may take some more time.
|
||||
For the german users: McLighting was used in [Kliemannsland](https://youtu.be/3TUjszkS3bY?t=1211) (a funny web show) when they built a really big Neopixel installation.
|
||||
|
||||
Update 18.03.2018:
|
||||
The code for integration with homeassistant was merged into master. It's currently active by default. You can safely disable it in definitions.h when use do not want to use it, or want to use McLighting on a small ESP_01.
|
||||
There are some informations in the [Wiki](https://github.com/toblum/McLighting/wiki/Homeassistant-integration).
|
||||
|
||||
Update 17.02.2018:
|
||||
User @debsahu contributed code for integration with homeassistant. It's currently in a separate branch (https://github.com/toblum/McLighting/tree/feature/ha_integration). If you're using Homeassistant, please try it out and give feedback.
|
||||
User @FabLab-Luenen created a version of McLighting (https://github.com/FabLab-Luenen/McLighting) for 6812 and other RGBW strips. Give it a try, if you own such strips.
|
||||
A thank you goes to all contributors.
|
||||
|
||||
Update 12. / 15.02.2018:
|
||||
Added Home Assistant Support using MQTT Light. A better implementation would be using MQTT Light JSON.
|
||||
Replaced Home Assistant Support using MQTT Light to MQTT JSON Light.
|
||||
|
||||
Update 31.01.2018:
|
||||
User @codmpm did a very professional McLighting installation and even designed his own PCBs. He has a great writeup for his project at: https://allgeek.de/2018/01/29/esp8266-neopixel-controller/ (in german).
|
||||
|
||||
@@ -60,11 +84,6 @@ Today I presented the project at [Pi and More 9](https://piandmore.de/) and got
|
||||
___
|
||||
|
||||
|
||||
[](https://youtu.be/rc6QVHKAXBs)
|
||||
|
||||
[](https://youtu.be/4JnGXZaPnrw)
|
||||
|
||||
|
||||
## The Hardware
|
||||
|
||||
The project ist based on the famous ESP8266 microcontroller and WD2811/WS2812 LED strips. There are many variations of the ESP chip out there, but I chose the NodeMCU dev board, because it's powered by micro USB and has a voltage converter included to power the ESP which uses 3.3V.
|
||||
@@ -110,15 +129,14 @@ I hope I didn't miss any sources and mentioned every author. In case I forgot so
|
||||
|
||||
## Todos
|
||||
- [x] MQTT support
|
||||
- [ ] Support multiple strips and control them separately or together
|
||||
- [ ] Support multiple strips and control them separately or together [Issue](https://github.com/toblum/McLighting/issues/118)
|
||||
- [ ] Save favourite effects? [Issue](https://github.com/toblum/McLighting/issues/35)
|
||||
- [ ] Make number of pixels, MQTT and PIN configurable via front end [Issue](https://github.com/toblum/McLighting/issues/93)
|
||||
- [ ] OTA update [Issue](https://github.com/toblum/McLighting/issues/93)
|
||||
- [ ] Make number of pixels, MQTT and PIN configurable via front end [Issue](https://github.com/toblum/McLighting/issues/93) and [Issue](https://github.com/toblum/McLighting/issues/101)
|
||||
- [x] OTA update [Issue](https://github.com/toblum/McLighting/issues/93)
|
||||
- [ ] Bundle webpages instead of SPIFFS [Issue](https://github.com/toblum/McLighting/issues/93)
|
||||
- [ ] Remove old / wrong EEPROM settings completely (https://github.com/toblum/McLighting/issues/92)
|
||||
- [x] Fix issue with websockets connection problems
|
||||
- [ ] Add support for 433MHz wireless socket using the [RC switch](https://github.com/sui77/rc-switch) library.
|
||||
- [ ] Switch to the [NeoPixelBus library](https://github.com/Makuna/NeoPixelBus/wiki)
|
||||
- [x] Switch to the [NeoPixelBus library](https://github.com/Makuna/NeoPixelBus/wiki)
|
||||
- [x] Use the led strip for status information in connection phase
|
||||
- [x] Enhance the documentation
|
||||
- [x] Stability improvements
|
||||
@@ -128,9 +146,11 @@ I hope I didn't miss any sources and mentioned every author. In case I forgot so
|
||||
- [x] Button control [Issue](https://github.com/toblum/McLighting/issues/36)
|
||||
- [x] Retain last state [Issue](https://github.com/toblum/McLighting/issues/47)
|
||||
- [ ] Additional clients
|
||||
- [ ] If no wifi, at least enable button mode. [Issue](https://github.com/toblum/McLighting/issues/88)
|
||||
- [ ] If no wifi, at least enable button mode.
|
||||
- [ ] Also enable McLighting in Wifi AP mode.
|
||||
- [ ] Make a set of NodeRed nodes.
|
||||
- [x] Make a set of NodeRed nodes.
|
||||
- [ ] Multiple buttons/GPIO Inputs. [Issue](https://github.com/toblum/McLighting/issues/119)
|
||||
- [ ] Music visualizer / Bring back ArtNet [Issue](https://github.com/toblum/McLighting/issues/111)
|
||||
|
||||
|
||||
## Licence
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
light:
|
||||
- platform: mqtt_json
|
||||
name: "NeoPixel LEDs"
|
||||
state_topic: "home/McLighting01_ha/state/out"
|
||||
command_topic: "home/McLighting01_ha/state/in"
|
||||
on_command_type: 'first'
|
||||
effect: true
|
||||
effect_list:
|
||||
######
|
||||
- "Blink"
|
||||
- "Breath"
|
||||
- "Color Wipe"
|
||||
- "Color Wipe Inverse"
|
||||
- "Color Wipe Reverse"
|
||||
- "Color Wipe Reverse Inverse"
|
||||
- "Color Wipe Random"
|
||||
- "Random Color"
|
||||
- "Single Dynamic"
|
||||
- "Multi Dynamic"
|
||||
- "Rainbow"
|
||||
- "Rainbow Cycle"
|
||||
- "Scan"
|
||||
- "Dual Scan"
|
||||
- "Fade"
|
||||
- "Theater Chase"
|
||||
- "Theater Chase Rainbow"
|
||||
- "Running Lights"
|
||||
- "Twinkle"
|
||||
- "Twinkle Random"
|
||||
- "Twinkle Fade"
|
||||
- "Twinkle Fade Random"
|
||||
- "Sparkle"
|
||||
- "Flash Sparkle"
|
||||
- "Hyper Sparkle"
|
||||
- "Strobe"
|
||||
- "Strobe Rainbow"
|
||||
- "Multi Strobe"
|
||||
- "Blink Rainbow"
|
||||
- "Chase White"
|
||||
- "Chase Color"
|
||||
- "Chase Random"
|
||||
- "Chase Rainbow"
|
||||
- "Chase Flash"
|
||||
- "Chase Flash Random"
|
||||
- "Chase Rainbow White"
|
||||
- "Chase Blackout"
|
||||
- "Chase Blackout Rainbow"
|
||||
- "Color Sweep Random"
|
||||
- "Running Color"
|
||||
- "Running Red Blue"
|
||||
- "Running Random"
|
||||
- "Larson Scanner"
|
||||
- "Comet"
|
||||
- "Fireworks"
|
||||
- "Fireworks Random"
|
||||
- "Merry Christmas"
|
||||
- "Fire Flicker"
|
||||
- "Fire Flicker (soft)"
|
||||
- "Fire Flicker (intense)"
|
||||
- "Circus Combustus"
|
||||
- "Halloween"
|
||||
- "Bicolor Chase"
|
||||
- "Tricolor Chase"
|
||||
- "ICU"
|
||||
brightness: true
|
||||
color_temp: true
|
||||
rgb: true
|
||||
optimistic: false
|
||||
qos: 0
|
||||
retain: true
|
||||
|
||||
input_number:
|
||||
neopixel_animation_speed:
|
||||
name: NeoPixel Animation Speed
|
||||
initial: 200
|
||||
min: 0
|
||||
max: 255
|
||||
step: 5
|
||||
|
||||
automation:
|
||||
- id: 71938579813759813757
|
||||
alias: NeoPixel Animation Speed Send
|
||||
initial_state: true
|
||||
hide_entity: false
|
||||
trigger:
|
||||
- entity_id: input_number.neopixel_animation_speed
|
||||
platform: state
|
||||
action:
|
||||
- data_template:
|
||||
payload_template: '{"speed": {{ trigger.to_state.state | int }}}'
|
||||
retain: true
|
||||
topic: home/McLighting01_ha/state/in
|
||||
service: mqtt.publish
|
||||
|
||||
- id: 93786598732698756967
|
||||
alias: NeoPixel Animation Speed Receive
|
||||
trigger:
|
||||
- platform: mqtt
|
||||
topic: home/McLighting01_ha/state/out
|
||||
action:
|
||||
- data_template:
|
||||
entity_id: input_number.neopixel_animation_speed
|
||||
value: '{{ trigger.payload_json.speed | int }}'
|
||||
service: input_number.set_value
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 22 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
Reference in New Issue
Block a user