Alle Pixel koennen ueber einen Befehl mit einer Farbe gezielt versehen

This commit is contained in:
starcalc 2017-07-05 01:01:41 +02:00
parent 135486035f
commit 79e6189857
3 changed files with 40 additions and 6 deletions

View File

@ -104,6 +104,11 @@ void NeoPatterns::Reverse() {
}
}
void NeoPatterns::Stop(uint8_t interval) {
Interval = interval;
ActivePattern = NONE;
}
void NeoPatterns::None(uint8_t interval) {
Interval = interval;
if (ActivePattern != NONE) {
@ -183,7 +188,6 @@ void NeoPatterns::Scanner(uint32_t color1, uint8_t interval, bool colorful, bool
Interval = interval;
TotalSteps = (numPixels() - 1) * 2;
Color1 = color1;
Color2 = color1;
Index = 0;
wPos = 0;
this->colorful = colorful;

View File

@ -12,9 +12,9 @@ class NeoPatterns : public Adafruit_NeoPixel
NeoPatterns(uint16_t pixels, uint8_t pin, uint8_t type, void (*callback)());
void Update();
void Reverse();
void None(uint8_t interval = 40);
void Stop(uint8_t interval = 40);
void RainbowCycle(uint8_t interval, direction dir = FORWARD);
void RainbowCycleUpdate();
void TheaterChase(uint32_t color1, uint32_t color2, uint8_t interval, direction dir = FORWARD);

View File

@ -6,7 +6,7 @@
#include <avr/power.h>
#endif
#define PIN 2 //data pin for ws2812 (pixelprojektor @ ctdo: PIN 2)
#define PIN D2 //data pin for ws2812 (pixelprojektor @ ctdo: PIN 2) // Für pixelpad: Pin2
#define NUMPIXELS 64
NeoPatterns strip = NeoPatterns(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800, &StripComplete);
@ -65,6 +65,34 @@ bool onSetBrightness(const HomieRange& range, const String& value) {
homieNode.setProperty("brightness").send(value);
}
bool onSetPixels(const HomieRange& range, const String& value) {
String remaining = value;
int i = 0;
// Kein Effekt
strip.Stop();
do {
String current = remaining.substring(0, 7);
Homie.getLogger() << i << ":" << current << endl;
uint32_t currentcolor = strip.parseColor(current);
strip.setPixelColor(strip.numToPos(i), currentcolor);
i++;
remaining = remaining.substring(7);
} while (remaining.length() > 2 && (i < strip.numPixels()));
Homie.getLogger() << " filling rest with black" << endl;
while (i < strip.numPixels()) {
strip.setPixelColor(strip.numToPos(i), strip.Color(0, 0, 0));
i++;
}
strip.show();
return true;
}
bool onSetEffect(const HomieRange& range, const String& value) {
stopAfterCompletion = false;
String effect = value;
@ -116,11 +144,10 @@ bool onSetEffect(const HomieRange& range, const String& value) {
strip.RandomFadeSingle(p1);
}
else {
effect = "none";
strip.None();
}
}
homieNode.setProperty("effect").send(effect);
homieNode.setProperty("effect").send(value);
}
bool onSetIcon(const HomieRange& range, const String& value) {
@ -170,15 +197,18 @@ void setup() {
homieNode.advertise("clear").settable(onSetClear);
homieNode.advertise("length").settable(onSetLength);
homieNode.advertise("icon").settable(onSetIcon);
homieNode.advertiseRange("pixels", 0, (NUMPIXELS - 1)*7).settable(onSetPixels);
Homie.setup();
strip.begin();
strip.clear();
// strip.setBrightness(64);
strip.setBrightness(255); // HEEELLLLLLL :)
// strip.setBrightness(255); // HEEELLLLLLL :)
strip.setBrightness(10); // DEBUG!
strip.show();
stopAfterCompletion = false; // Default
// strip.Plasma(); // Default effect
ArduinoOTA.setHostname("pixelprojektor");
ArduinoOTA.onStart([]() {