2

I'm trying to make a Google Assistant controlled LED strip, but I'm stuck. I can control the on board LED of the nodemcu with Google Assistant, and I can control a LED strip too, but I can't combine the two. This is my code:

#define WIFI_NAME "****************"
#define WIFI_PASSWORD "********"
#define DEVICE_ID 1
#define DEVICE_NAME "Google_ESP"
#define TOKEN "************"

#define FASTLED_ESP8266_NODEMCU_PIN_ORDER
#include "FastLED.h"

#include <RemoteMe.h>
#include <RemoteMeSocketConnector.h>

#include <ESP8266WiFi.h>

#define ledpin D0

RemoteMe& remoteMe = RemoteMe::getInstance(TOKEN, DEVICE_ID);

//*************** CODE FOR CONFORTABLE VARIABLE SET *********************

inline void setLedstrip(boolean b) {remoteMe.getVariables()->setBoolean("Ledstrip", b); }

//*************** IMPLEMENT FUNCTIONS BELOW *********************


// How many leds in your strip?
#define NUM_LEDS 120

// For led chips like Neopixels, 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
#define DATA_PIN D3

CRGB leds[NUM_LEDS];

boolean ledsOn = 0;

void onLedstripChange(boolean b) {
    Serial.printf("onLedstripChange: b: %d\n",b);

    if(ledsOn != b){
        if(b == 1){
            turnLedsOn();
        }
        else{
            turnLedsOff();
        }

        ledsOn = b;
    }
}


void setup() {
    FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);

    Serial.begin(9600);

    WiFi.begin(WIFI_NAME, WIFI_PASSWORD);

    while (WiFi.status() != WL_CONNECTED) {
        delay(100);
    }

    remoteMe.getVariables()->observeBoolean("Ledstrip" ,onLedstripChange);

    remoteMe.setConnector(new RemoteMeSocketConnector());
    remoteMe.sendRegisterDeviceMessage(DEVICE_NAME);

    pinMode(ledpin, OUTPUT);
    digitalWrite(ledpin, HIGH);
}


void loop() {
  remoteMe.loop();
}


void turnLedsOn(){
  digitalWrite(ledpin, LOW);
  leds[0] = CHSV(0, 100, 100);
  FastLED.show();
}

void turnLedsOff(){
  digitalWrite(ledpin, HIGH);
  leds[0] = CHSV(0, 0, 0);
  FastLED.show();
}

As you can see, it should turn on the on board LED and the first LED of the strip. It only does the on board one.

4
  • Hi @CodeHard, Could you provide links or the actual code to the two programs that work? Handy if you could provide links to the libraries you used. Thanks.
    – sa_leinad
    Jun 20, 2019 at 7:35
  • Wow, okay. Nevermind... I just read my code of the ledstrip only program and the google assistant ledstrip to look for differences, and found out it didn't work because I used pin D3 instead of pin 3...
    – CodeHard
    Jun 20, 2019 at 10:14
  • Also, ledpin should be 0 instead of D0.
    – sa_leinad
    Jun 20, 2019 at 12:15
  • Please add that as an answer down below. You can answer your own question and get some upvotes from solving it (hopefully).
    – sa_leinad
    Jun 20, 2019 at 12:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.