Neopixel using a button error


#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#include <ESP8266WiFi.h>
#include <SPI.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "";
char ssid[] = "";
char pass[] = "";

int r;
int g;
int b;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, D6, NEO_GRB + NEO_KHZ800);

//zeRGBa
BLYNK_WRITE(V2) {
  r = param.asInt();
}
BLYNK_WRITE(V3) {
  g = param.asInt();
}
BLYNK_WRITE(V4) {
  b = param.asInt();
}

void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  strip.begin();
  strip.show(); 
}

void loop() {
  Blynk.run();

  if (digitalRead(D1) == HIGH) { //on pin D1 is a Button!
    strip.setPixelColor(1, 255, 0, 0);
    strip.show(); 
  } else {
    strip.setPixelColor(1, 0, 0, 0);
    strip.show(); 
  }
}

Hello,
I would like to control my LEDs via smartphone. As a test I wrote this code. This should turn on a specific LED as soon as you press a button in the Blynk app. But every time I press the button, the ESP will simply disconect.

So can you guys find a mistake or helping me otherwise?

Lg

Wel, we are not a code mechanic shop here :wink:

But as I see, your Blynk related code is doing nothing but assigning a value to a variable (r, g & b) it then does nothing with those variables…

PS you might be better using MERGE mode like this…

BLYNK_WRITE(V1) // zeRGBa assigned to V1 
{
  r = param[0].asInt();
  g = param[1].asInt();
  b = param[2].asInt();
}

And this shouldn’t be in the void loop() since as soon as you press the physical button, that code tries to run thousands of times a second and can disconnect the device from the server…

Try running in a timed loop instead.

1 Like

I think the D6 here may be a problem. The Neopixel library may be treating this as GPIO6, which isn’t an available pin on the ESP8266.

Try changing this to 12 and keeping the Neopixel strip connected to D6 (Which is GPIO12) and see what happens.

If it’s not that, then it may be your cluttered void loop.

Pete.

1 Like

ok guys it works now! just had to make a timed loop with a small delay. the connection is now fine!
Thank you!
<33

1 Like