From 1aa00977d7c0b7aff196b6aa6646cca0cfe052dc Mon Sep 17 00:00:00 2001 From: Simon Zeyer Date: Wed, 8 Dec 2021 09:58:03 +0100 Subject: [PATCH] init swyx led status anzeige --- sketch_swyx_anzeige.ino | 122 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 sketch_swyx_anzeige.ino diff --git a/sketch_swyx_anzeige.ino b/sketch_swyx_anzeige.ino new file mode 100644 index 0000000..cbd4b62 --- /dev/null +++ b/sketch_swyx_anzeige.ino @@ -0,0 +1,122 @@ +#include +#include +/* 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(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() + ) + ); + } + } +}