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.
ledpin
should be0
instead ofD0
.