init swyx led status anzeige
This commit is contained in:
commit
1aa00977d7
122
sketch_swyx_anzeige.ino
Normal file
122
sketch_swyx_anzeige.ino
Normal file
@ -0,0 +1,122 @@
|
||||
#include <FastLED.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
/* FastLED_RGBW
|
||||
*
|
||||
* Hack to enable SK6812 RGBW strips to work with FastLED.
|
||||
*
|
||||
* Original code by Jim Bumgardner (http://krazydad.com).
|
||||
* Modified by David Madison (http://partsnotincluded.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FastLED_RGBW_h
|
||||
#define FastLED_RGBW_h
|
||||
|
||||
struct CRGBW {
|
||||
union {
|
||||
struct {
|
||||
union {
|
||||
uint8_t g;
|
||||
uint8_t green;
|
||||
};
|
||||
union {
|
||||
uint8_t r;
|
||||
uint8_t red;
|
||||
};
|
||||
union {
|
||||
uint8_t b;
|
||||
uint8_t blue;
|
||||
};
|
||||
union {
|
||||
uint8_t w;
|
||||
uint8_t white;
|
||||
};
|
||||
};
|
||||
uint8_t raw[4];
|
||||
};
|
||||
|
||||
CRGBW(){}
|
||||
|
||||
CRGBW(uint8_t rd, uint8_t grn, uint8_t blu, uint8_t wht){
|
||||
r = rd;
|
||||
g = grn;
|
||||
b = blu;
|
||||
w = wht;
|
||||
}
|
||||
|
||||
inline void operator = (const CRGB c) __attribute__((always_inline)){
|
||||
this->r = c.r;
|
||||
this->g = c.g;
|
||||
this->b = c.b;
|
||||
this->white = 0;
|
||||
}
|
||||
};
|
||||
|
||||
inline uint16_t getRGBWsize(uint16_t nleds){
|
||||
uint16_t nbytes = nleds * 4;
|
||||
if(nbytes % 3 > 0) return nbytes / 3 + 1;
|
||||
else return nbytes / 3;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// How many leds in your strip?
|
||||
#define NUM_LEDS 9
|
||||
|
||||
// For led chips like WS2812, which have a data line, ground, and power, you just
|
||||
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
|
||||
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
|
||||
// Clock pin only needed for SPI based chipsets when not using hardware SPI
|
||||
#define DATA_PIN D4
|
||||
#define CLOCK_PIN 13
|
||||
|
||||
// Define the array of leds
|
||||
// FastLED with RGBW
|
||||
CRGBW leds[NUM_LEDS];
|
||||
CRGB *ledsRGB = (CRGB *) &leds[0];
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.setTimeout(100);
|
||||
WiFi.mode(WIFI_STA);
|
||||
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(ledsRGB, getRGBWsize(NUM_LEDS));
|
||||
colorFill(CRGB::Black);
|
||||
}
|
||||
|
||||
|
||||
void colorFill(CRGB c){
|
||||
for(int i = 0; i < NUM_LEDS; i++){
|
||||
leds[i] = c;
|
||||
FastLED.show();
|
||||
//delay(50);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (Serial.available())
|
||||
{
|
||||
String rs = Serial.readString();
|
||||
Serial.println(rs.substring(0,3));
|
||||
if(rs.substring(0,3) == "dta"){
|
||||
leds[rs.substring(4,6).toInt()] = CRGB(
|
||||
rs.substring(7,9).toInt(),
|
||||
rs.substring(10,12).toInt(),
|
||||
rs.substring(13,15).toInt()
|
||||
);
|
||||
}
|
||||
if(rs.substring(0,3) == "shw"){
|
||||
FastLED.show();
|
||||
}
|
||||
if(rs.substring(0,3) == "shc"){
|
||||
Serial.println(rs.substring(4,6).toInt());
|
||||
Serial.println(rs.substring(7,9).toInt());
|
||||
Serial.println(rs.substring(10,12).toInt());
|
||||
colorFill(CRGB(
|
||||
rs.substring(4,6).toInt(),
|
||||
rs.substring(7,9).toInt(),
|
||||
rs.substring(10,12).toInt()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user