// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
#define PIXEL_PIN A5 //define the pin number
#define PIXEL_COUNT 50 //define pixels
#define PIXEL_TYPE WS2811 //defne type
int i;
int j;
long startedAt=0;
int duration= 3*1000;
int festival_starts=0;
uint32_t orange; //create colour integers
uint32_t green;
uint32_t white;
uint32_t blue;
uint32_t red;
uint32_t festive_indian;
uint32_t festive_turkish;
uint32_t darkred;
uint32_t yellow;
uint32_t alert;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE); //define object
String sharedEventName="diot/2019/smartstudio/";
void setup()
{
Serial.begin(9600);
strip.begin();//prepares datapin for output
strip.show();//initializes all neopixel to 'OFF'
festive_indian=strip.Color(255,153,10); //define values for the colour
green=strip.Color(0,100,0);
blue=strip.Color(0,0,128);
white=strip.Color(255,255,255);
red=strip.Color(255,0,0);
orange=strip.Color(255,100,0);
festive_turkish=strip.Color(234,70,48);
darkred=strip.Color(120,0,0);
yellow=strip.Color(255,222,0);
alert=strip.Color(160,32,240);
Particle.subscribe("IndianFestival",handleSharedEvent1); //create an event for each festival
Particle.subscribe("TurkishFestival",handleSharedEvent2);
Particle.subscribe("ChineseFestival",handleSharedEvent3);
Particle.subscribe(sharedEventName, handleSharedEvent);
startedAt=millis();
}
void loop()
{
}
void handleSharedEvent1(const char *event, const char *data) //executes this function when indian festival starts
{
festival_starts=1;
while(startedAt+duration<millis())
{
Indian();
}
}
void handleSharedEvent2(const char *event, const char *data) //executes this fucntion when turkish festival starts
{
festival_starts=1;
while(startedAt+duration<millis())
{
Turkish();
}
}
void handleSharedEvent3(const char *event, const char *data) //executes this function when chinese festival starts
{
festival_starts=1;
while(startedAt+duration<millis())
{
Chinese();
}
}
void IndianFlag() //
{
strip.setBrightness(100);
for(i=0;i<19;i++) //sets first 19 pins to green colour
{
strip.setPixelColor(i,green);
strip.show();
}
for(i=19;i<36;i++)
{
strip.setPixelColor(i,white);
strip.show();
}
for(i=36;i<50;i++)
{
strip.setPixelColor(i,orange);
strip.show();
}
delay(3000);
}
void BreatheIndian() //creates breathing pattern
{
for(i=0;i<50;i++)
{
strip.setPixelColor(i,festive_indian);
}
strip.show();
for(i=10;i<100;i=i+10) //increase the brightness
{
strip.setBrightness(i);
strip.show();
delay(100);
}
for(i=0;i<50;i++)
{
strip.setPixelColor(i,festive_indian);
}
strip.show();
for(i=100;i>10;i=i-10)
{
strip.setBrightness(i);
strip.show();
delay(100);
}
}
void Indian()
{
IndianFlag();
delay(100);
BreatheIndian();
delay(100);
BreatheIndian();
delay(100);
}
void TurkishFlag() //create turkish flag
{
strip.setBrightness(100);
for(i=0;i<24;i++)
{
strip.setPixelColor(i,red);
strip.show();
}
for(i=24;i<26;i++)
{
strip.setPixelColor(i,white);
strip.show();
}
for(i=26;i<28;i++)
{
strip.setPixelColor(i,red);
strip.show();
}
for(i=28;i<32;i++)
{
strip.setPixelColor(i,white);
strip.show();
}
for(i=32;i<50;i++)
{
strip.setPixelColor(i,red);
strip.show();
}
delay(3000);
}
void BreatheTurkish()
{
for(i=0;i<50;i=i+2)
{
strip.setPixelColor(i,festive_turkish);
}
strip.show();
for(i=1;i<49;i=i+2)
{
strip.setPixelColor(i,white);
}
strip.show();
for(i=10;i<100;i=i+10)
{
strip.setBrightness(i);
strip.show();
delay(100);
}
for(i=0;i<50;i=i+2)
{
strip.setPixelColor(i,festive_turkish);
}
strip.show();
for(i=1;i<49;i=i+2)
{
strip.setPixelColor(i,white);
}
strip.show();
for(i=100;i>10;i=i-10)
{
strip.setBrightness(i);
strip.show();
delay(100);
}
}
void Turkish()
{
TurkishFlag();
delay(100);
BreatheTurkish();
delay(100);
BreatheTurkish();
delay(100);
}
void ChineseFlag() //create chinese flag
{
strip.setBrightness(100);
for(i=43;i<50;i++) //set certain pixels to darkred
{
strip.setPixelColor(i,darkred);
strip.show();
}
for(i=41;i<43;i++)
{
strip.setPixelColor(i,yellow);
strip.show();
}
strip.setPixelColor(40,darkred);
strip.show();
for(i=30;i<40;i++)
{
strip.setPixelColor(i,yellow);
strip.show();
}
strip.setPixelColor(29,darkred);
strip.show();
for(i=27;i<29;i++)
{
strip.setPixelColor(i,yellow);
strip.show();
}
for(i=0;i<27;i++)
{
strip.setPixelColor(i,darkred);
strip.show();
}
delay(3000);
}
void BreatheChinese()
{
for(i=0;i<50;i++)
{
strip.setPixelColor(i,darkred);
}
strip.show();
for(i=10;i<100;i=i+10)
{
strip.setBrightness(i);
strip.show();
delay(100);
}
for(i=0;i<50;i++)
{
strip.setPixelColor(i,darkred);
}
strip.show();
for(i=100;i>10;i=i-10)
{
strip.setBrightness(i);
strip.show();
delay(100);
}
}
void Chinese()
{
ChineseFlag();
delay(100);
BreatheChinese();
delay(100);
BreatheChinese();
delay(100);
}
void handleSharedEvent(const char *event, const char *data) //call this function when a networked function is recieved
{
String eventName=String(event);
if(eventName.indexOf("ImGone")>-1)
{
if(festival_starts==0)
{
for(i=0;i<50;i++)
{
strip.setPixelColor(i,alert);
strip.show();
}
}
}
else if(eventName.indexOf("ImHere")>-1)
{
for(i=0;i<50;i++)
{
strip.setPixelColor(i,0,0,0);
strip.show();
}
}
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .