kitesurfer1404 / WS2812FX

WS2812 FX Library for Arduino and ESP8266
MIT License
1.6k stars 347 forks source link

LEDs not rendering animation? #24

Closed ntalekt closed 7 years ago

ntalekt commented 7 years ago

First, thank you for putting this library together. I'm trying to use it with an Adafruit tutorial for an Alexa controlled WS2812 device.

I'm going to create FauxWemo devices using the fauxmoESP library and assigning them to specific effects in your library. That way I can just have Alexa turn on/off the different effects easily.

The FauxWemo + Alexa stuff is working fine however when I try and ws2812fx.setMode(40); or any other animated effect it doesn't animate, it just sits there static. Any help would be appreciated.

Here is the code:

#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#include <ESP8266WiFi.h>
#include "fauxmoESP.h"
#include <WS2812FX.h>

#define WIFI_SSID ""
#define WIFI_PASS ""
#define SERIAL_BAUDRATE                 115200

fauxmoESP fauxmo;
#define LED_COUNT 12
#define LED_PIN 2

WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
volatile boolean neopixel_state = false; // off by default!

// -----------------------------------------------------------------------------
// Wifi
// -----------------------------------------------------------------------------
void wifiSetup() {
  // Set WIFI module to STA mode
  WiFi.mode(WIFI_STA);

  // Connect
  Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
  WiFi.begin(WIFI_SSID, WIFI_PASS);

  // Wait
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(100);
  }
  Serial.println();

  // Connected!
  Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
}

void callback(uint8_t device_id, const char * device_name, bool state) {
  Serial.printf("[MAIN] %s state: %s\n", device_name, state ? "ON" : "OFF");

  if ( (strcmp(device_name, "rainbow") == 0) ) {
    // this just sets a variable that the main loop() does something about
    if (state) {
      neopixel_state = true;
    } else {
      neopixel_state = false;
    }
  }
}

void setup() {
  // Init WS2812FX
  ws2812fx.init();

  // Init serial port and clean garbage
  Serial.begin(SERIAL_BAUDRATE);
  Serial.println();
  Serial.println();
  Serial.println("FauxMo demo sketch");
  Serial.println("After connection, ask Alexa/Echo to 'turn pixels on' or 'off' or 'turn relay on' or 'off'");

  // Wifi
  wifiSetup();

  // Fauxmo
  fauxmo.addDevice("rainbow");
  fauxmo.onMessage(callback);
}

void loop() {
  fauxmo.handle();
  ws2812fx.service();

  if (neopixel_state == true) {
    ws2812fx.setBrightness(100);
    ws2812fx.setSpeed(200);
    ws2812fx.setMode(40);
    ws2812fx.start();

  } else {
    ws2812fx.stop();
  }
}
ntalekt commented 7 years ago

I just ended up calling ws2812fx.service(); in the loop and calling the modes in the callback. Seems to be working fine. Now to deal with the white in RGBWs.

Thanks again.