Published © CC BY

OnLight - Blynk Controlled Photon with LED NeoPixel Ring

This NeoPixel LED light has six different light settings, is connected to the Wi-Fi and controlled via Particle Photon and Blynk app.

IntermediateFull instructions provided2,076
OnLight - Blynk Controlled Photon with LED NeoPixel Ring

Things used in this project

Hardware components

Photon
Particle Photon
×1
Adafruit Particle/Spark NeoPixel Ring Kit - 24 NeoPixels
×1
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×1

Software apps and online services

Blynk
Blynk

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Case with screw clap

Stand

Code

OnLight

Arduino
Version 1.0
/*************************************************************
* Project OnLight V1.0
* Description: OnLight is a smart light connected to the Wi-Fi. 
It can be controlled via the Blynk app. Various functions are 
already preprogrammed, e.g. four light settings, color picker 
and strobe light. The OnLight-Case is 3D printed and can be screwed into 
E-27 sockets or on self-developed mounts.
* Author: Andre Nakonz
* Date: 2018/01/18
*
*
* CREDITS
* 
* For this example you need the Blynk library.
* Blynk library is licensed under MIT license.
*
* Code snippets are from Adafruit. 
*
* Code snippets are from PerfectPixel 
*
**************************************************************/


// If you work with the Particle Web IDE, use the libraries on the left to include.
#include <neopixel.h>
#include <blynk.h>
SYSTEM_MODE(AUTOMATIC);
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define BLYNK_PRINT Serial
#define PIXEL_COUNT 24 // Neopixel Ring for Photon has 24 LEDs
#define PIXEL_PIN D6 // Neopixel Ring uses D6
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
char auth[] = YOUR TOKEN; // example: char auth[] = „abcdef123456“;
int speed = 10; //
int colorPicker = 0;
int mode = 0;
// Here is where you can put in your favorite colors for the flashlights!
// just add new {rrr, ggg, bbb}, lines. They will be picked out randomly
uint8_t myColors[][3] = {
{232, 100, 255}, // purple
{200, 200, 20}, // yellow
{ 30, 200, 200}, // blue
};
// For the flashlights
#define FAVCOLORS sizeof(myColors) / 3
void setup(){
Blynk.begin(auth);
strip.begin();
strip.show();
strip.setBrightness(40); // 40/255 brightness (about 15%)
}
BLYNK_WRITE(V0)
{
mode = 0; //OFF
}
BLYNK_WRITE(V1)
{
mode = 1; // TROPICAL
}
BLYNK_WRITE(V2)
{
mode = 2; // NORDIC
}
BLYNK_WRITE(V3)
{
mode = 3; //SOLID
}
BLYNK_WRITE(V4)
{
mode = 4; //RAINBOW SOLID
}
BLYNK_WRITE(V5)
{
mode = 5; //RAINBOW CIRCLE – all Colors in one circle
}
BLYNK_WRITE(V6)
{
mode = 6; //FLASH
}
BLYNK_WRITE(V10)
{
speed = param.asInt(); //Get the speed from the slider
}
BLYNK_WRITE(V11)
{
colorPicker = param.asInt(); //Get the color from the slider
}
void loop()
{
Blynk.run();
if(mode == 0){ //activitating the off button will ovveride all other colors
colorWipe(strip.Color(0, 0, 0), 1);
}
else if(mode == 1){ // Tropical
for(int j=0; j<256; j++) {
for(int i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel2((i+j) & 255));
}
strip.show();
delay(speed);
}
}
else if(mode == 2){ // Nordic
for(int j=0; j<256; j++) {
for(int i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel3((i+j) & 255));
}
strip.show();
delay(speed);
}
}
else if(mode == 3){ // Solid Color
for (int i = 0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, Wheel(colorPicker & 255));
}
strip.show();
}
else if(mode == 4){ // Rainbow Solid
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(speed);
}
}
else if (mode == 5){ // Raibow Circle
for(int j=0; j<256; j++) {
for(int i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(speed);
}
}
else if (mode == 6){ // Flash
// pick a random favorite color!
int c = random (FAVCOLORS);
int red = myColors[c][0];
int green = myColors[c][1];
int blue = myColors[c][2];
// get a random pixel from the list
int j = random(strip.numPixels());
// now we will fade in over 5 steps
for (int x=1; x <= 5; x++) {
int r = red * x / 5;
int g = green * x / 5;
int b = blue * x / 5;
strip.setPixelColor(j, strip.Color(r, g, b));
strip.show();
delay(speed);
}
// & fade out in 5 steps
for (int x=5; x >= 0; x) {
int r = red * x / 5;
int g = green * x / 5;
int b = blue * x / 5;
strip.setPixelColor(j, strip.Color(r, g, b));
strip.show();
delay(speed);
}
// LED will be off when done (they are faded to 0)
}
}
// 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);
}
}
// Tropical Wheel
// strip.Color (r,g,b) – red is always on 255
uint32_t Wheel2(byte WheelPos2) {
if (WheelPos2 < 85) {
return strip.Color(255, 170  WheelPos2 * 2, 0);
//Or:
//return strip.Color(255, 255 – WheelPos2 * 3, 0);
//if red = 255 and green <= 255 the yellow seems greenish
} else if (WheelPos2 < 170) {
WheelPos2 -= 85;
return strip.Color(255, 0, WheelPos2 * 3);
} else {
WheelPos2 -= 170;
return strip.Color(255, WheelPos2 * 2, 255  WheelPos2 * 3);
//Or:
//return strip.Color(255, 255 – WheelPos2 * 3, 0);
//if red = 255 and green <= 255 the yellow seems greenish
}
}
// Nordic Wheel
// strip.Color (r,g,b) – blue is always on 255
uint32_t Wheel3(byte WheelPos3) {
if (WheelPos3 < 85) {
return strip.Color(0, 255  WheelPos3 * 3, 255);
} else if (WheelPos3 < 170) {
WheelPos3 -= 85;
return strip.Color(WheelPos3 * 3, 0, 255 );
} else {
WheelPos3 -= 170;
return strip.Color(255  WheelPos3 * 3, WheelPos3 * 3, 255);
}
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(3);
}
}

Credits

Comments