Neopixel with Particle Photon

Hi,

I try to control a Neopixel-Ring (24 LEDs) with blynk app. I managed to control the Neopixel-Ring via php but I have now idea how to do this via blynk. Any suggestions?

Cheers
cbmainz

what’s the problem?

This is my code I tried to port from my php control, but I have no clue on how to do this with blynk:

// This #include statement was automatically added by the Particle IDE.
#include "application.h"
#include "neopixel/neopixel.h"
#include "blynk/blynk.h"

SYSTEM_MODE(AUTOMATIC);

/* ======================= extra-examples.cpp ======================== */

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define BLYNK_PRINT Serial
#define PIXEL_COUNT 24
#define PIXEL_PIN D6
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

char auth[] = "xxx";

void setup()
{
  Blynk.begin(auth);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

Blynk.virtualWrite(21)
{
  int color = param[0].asInt();
  for(int i=0; i< strip.numPixels(); i++)
  {
    strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + color) & 255));
  }
  strip.show();
}

void loop()
{
  Blynk.run();
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

Did you try http://docs.blynk.cc ?

Please check how to use Virtual Pins: http://docs.blynk.cc/#blynk-main-operations-send-data-from-app-to-hardware

you need to rewrite your code

Burt how to tell blynk wich hardware pin to use?

you can put any (your own) code inside BLYNK_WRITE, including cotrolling NeoPixel

ha, now it works.

BLYNK_WRITE(V1)
{
  int shift = param.asInt();
  for (int i = 0; i < strip.numPixels(); i++)
  {
    strip.setPixelColor(i, Wheel(shift & 255));
    // OR: strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + shift) & 255));
  }
  strip.show();
}

void loop()
{
  Blynk.run();
}
2 Likes

Easy, right? :wink: