diff --git a/src/examples/button/Button.h b/src/examples/button/Button.h index 45a0daa..7fbe93f 100644 --- a/src/examples/button/Button.h +++ b/src/examples/button/Button.h @@ -14,6 +14,7 @@ class Button : public Sprocket { MeshNet* net; int pin; int warnlevel = 0; + int cycleEnd = 4; Button(SprocketConfig cfg) : Sprocket(cfg) {} Sprocket* activate(Scheduler* scheduler, Network* network) { pin = D2; @@ -30,6 +31,7 @@ class Button : public Sprocket { if(digitalRead(pin)){ Serial.println("warnlevel: " + String(warnlevel)); warnlevel++; + if(warnlevel == cycleEnd) warnlevel = 0; network->broadcast(String(warnlevel)); } } diff --git a/src/examples/illucat/Illucat.h b/src/examples/illucat/Illucat.h index 08a89b9..83d86f7 100644 --- a/src/examples/illucat/Illucat.h +++ b/src/examples/illucat/Illucat.h @@ -9,7 +9,10 @@ using namespace std; using namespace std::placeholders; +#define ARRAY_LENGTH(array) sizeof(array)/sizeof(array[0]) + enum PIXEL_MODES {RED = 0xFF0000, GREEN = 0x00FF00, YELLOW = 0xffff00, BLUE = 0x0000FF, ORANGE = 0xffa500}; +int CAT_MODES[] = {RED, GREEN, YELLOW, BLUE, ORANGE}; struct NeoPixelConfig { int pin; @@ -21,6 +24,7 @@ class Illucat : public Sprocket { public: MeshNet* net; NeoPattern* pixels; + int currentMode; Illucat(SprocketConfig cfg, NeoPixelConfig pixelCfg) : Sprocket(cfg) { pixels = new NeoPattern(pixelCfg.length, pixelCfg.pin, NEO_GRB + NEO_KHZ800, [](int pixels){}); pixels->begin(); @@ -34,11 +38,15 @@ class Illucat : public Sprocket { void messageReceived( uint32_t from, String &msg ) { Serial.printf("illucat: received from %u msg=%s\n", from, msg.c_str()); - setColor(msg.c_str()); + changeMode(msg.c_str()); } - void setColor(const char *color){ - pixels->ColorSet(BLUE); - pixels->show(); + void changeMode(const char *mode){ + currentMode = atoi(mode); + Serial.println(currentMode); + //if(ARRAY_LENGTH(CAT_MODES) >= (int) mode){ + pixels->ColorSet(CAT_MODES[currentMode]); + pixels->show(); + //} } void setHexColor(const char *hex){ int r, g, b;