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
|
||||
|
||||
+556
-247
File diff suppressed because it is too large
Load Diff
+107
-101
@@ -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 {
|
||||
uint32_t counter_mode_step;
|
||||
uint32_t counter_mode_call;
|
||||
unsigned long next_time;
|
||||
uint16_t aux_param;
|
||||
} segment_runtime;
|
||||
public:
|
||||
typedef struct Segment_runtime { // 16 bytes
|
||||
unsigned long next_time;
|
||||
uint32_t counter_mode_step;
|
||||
uint32_t counter_mode_call;
|
||||
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 ENABLE_BUTTON // If defined, enable button handling code, see: https://github.com/toblum/McLighting/wiki/Button-control
|
||||
#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,16 +41,39 @@ uint32_t autoParams[][4] = { // color, speed, mode, duration (seconds)
|
||||
{0x000000ff, 200, 46, 15.0} // fireworks for 15 seconds
|
||||
};
|
||||
|
||||
#ifdef ENABLE_MQTT
|
||||
#define MQTT_MAX_PACKET_SIZE 256
|
||||
#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
|
||||
|
||||
const char mqtt_clientid[] = "ESPLightMax"; // MQTT ClientID
|
||||
|
||||
#if defined(ENABLE_MQTT) or defined(ENABLE_AMQTT)
|
||||
#ifdef ENABLE_MQTT
|
||||
#define MQTT_MAX_PACKET_SIZE 512
|
||||
#define MQTT_MAX_RECONNECT_TRIES 4
|
||||
|
||||
int mqtt_reconnect_retries = 0;
|
||||
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
|
||||
|
||||
#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] = "";
|
||||
char mqtt_user[32] = "";
|
||||
@@ -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,12 +121,20 @@ 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_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
|
||||
#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 keyPrevMillis = 0;
|
||||
const unsigned long keySampleIntervalMs = 25;
|
||||
@@ -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
|
||||
#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
|
||||
|
||||
|
||||
+1069
-192
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user