Skip to content

Instantly share code, notes, and snippets.

@cbmainz
Created December 28, 2017 10:57
Show Gist options
  • Save cbmainz/1fa78d3657febdd9883be81de60ad945 to your computer and use it in GitHub Desktop.
Save cbmainz/1fa78d3657febdd9883be81de60ad945 to your computer and use it in GitHub Desktop.
Neopixel ring with Particle Photon via Blynk
#include <blynk.h>
#include <neopixel.h>
#define PIXEL_COUNT 24
#define PIXEL_PIN D6
#define PIXEL_TYPE WS2812B
#define BRIGHTNESS 60 // 50
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxx";
void setup()
{
Blynk.begin(auth);
RGB.brightness(1);
strip.setBrightness(BRIGHTNESS);
strip.begin();
strip.show();
}
BLYNK_WRITE(V1) //Helligkeit
{
int h = param.asInt();
strip.setBrightness(h);
strip.show();
}
BLYNK_WRITE(V2) // Alle LEDs aus
{
int button = param.asInt();
for (int i=0; i<strip.numPixels(); i++) {
strip.clear();
}
strip.show();
}
BLYNK_WRITE(V3) // Rainbow
{
int button = param.asInt();
for(int j=0; j<256; j++) {
for(int i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
//delay(600);
Blynk_Delay(300);
}
}
BLYNK_WRITE(V4) //Farbauswahl für alle LEDs
{
int r = param[0].asInt(); // get a RED channel value
int g = param[1].asInt(); // get a GREEN channel value
int b = param[2].asInt(); // get a BLUE channel value
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, r, g, b);
}
strip.show();
}
void Blynk_Delay(int milli){
int end = millis() + milli;
while(millis() < end){
Blynk.run();
}
}
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);
}
}
@cbmainz
Copy link
Author

cbmainz commented Dec 28, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment