// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
#define PIXEL_PIN1 D4
#define PIXEL_PIN2 D5
#define PIXEL_PIN3 D6
#define PIXEL_PIN4 D2
#define PIXEL_PIN5 D8
#define PIXEL_PIN6 D9
#define PIXEL_PIN7 D3
#define PIXEL_COUNT 15
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN1, PIXEL_TYPE);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN2, PIXEL_TYPE);
Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN3, PIXEL_TYPE);
Adafruit_NeoPixel strip4 = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN4, PIXEL_TYPE);
Adafruit_NeoPixel strip5 = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN5, PIXEL_TYPE);
Adafruit_NeoPixel strip6 = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN6, PIXEL_TYPE);
Adafruit_NeoPixel strip7 = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN7, PIXEL_TYPE);
long lastPublishedAt = 0;
int publishAfter = 10000;
int threshold=4;
int updelay=700;
int downdelay=1000;
int alloff=0;
const int dirPin=D10;
const int stepPin=D9;
int cup=0;
int cupused=0;
void setup() {
strip1.begin();
strip1.show();
strip2.begin();
strip2.show();
strip3.begin();
strip3.show();
strip4.begin();
strip4.show();
strip5.begin();
strip5.show();
strip6.begin();
strip6.show();
strip7.begin();
strip7.show();
pinMode(dirPin,OUTPUT);
pinMode(stepPin,OUTPUT);
Particle.function("Paper_cup",papercup);
Particle.function("Reset",resetcup);
Particle.function("Threshold",getthresh);
Particle.function("Updelay",getup);
Particle.function("Downdelay",getdown);
Particle.variable("Cup_count",cup);
Particle.variable("Threshold",threshold);
alloff=1;
}
int papercup(String command)
{
alloff=0;
if(cup<10)
{
cupused=1;
cup++;
}
else
{
cupused=0;
return-1;
}
return 1;
}
int getthresh(String command)
{
if(command.toInt()<10)
threshold=command.toInt();
else
return-1;
return 1;
}
int getup(String command)
{
updelay=command.toInt();
return 1;
}
int getdown(String command)
{
downdelay=command.toInt();
return 1;
}
int resetcup(String command)
{
digitalWrite(dirPin,LOW);//CW-bar goes down
for(int j=0;j<16*cup;j++)
{
for(int i=0;i<200;i++)
{
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
}
}
alloff=1;
if(cup<=threshold)
publishevent();
cup=0;
}
void loop()
{
barlights();
uint32_t tocolor = strip7.Color(0,0,0);
if(cup==0)
tocolor = strip7.Color(0, 0, 0);
else if(cup>0 && cup<=threshold)
tocolor = strip7.Color(0, 255-(cup*20), 0);
else
tocolor = strip7.Color(225+(cup*5),0,0);
for(int i=0;i<PIXEL_COUNT;i++)
{
strip7.setPixelColor(i, tocolor );
strip7.show();
}
if(cupused==1)
{
digitalWrite(dirPin,HIGH);//CCW-bar goes up
for(int j=0;j<16;j++)
{
for(int i=0;i<200;i++)
{
digitalWrite(stepPin,HIGH);
delayMicroseconds(700);
digitalWrite(stepPin,LOW);
delayMicroseconds(700);
}
}
cupused=0;
}
}
void barlights()
{
uint32_t coloroff = strip1.Color(0, 0, 0);
uint32_t color1 = strip1.Color(255, 0, 0);
uint32_t color2 = strip2.Color(255, 0, 0);
uint32_t color3 = strip3.Color(255, 0, 0);
uint32_t color4 = strip4.Color(255, 0, 0);
uint32_t color5 = strip5.Color(255, 0, 0);
uint32_t color6 = strip6.Color(255, 0, 0);
if(alloff==1)
{
for(int i=0;i<PIXEL_COUNT;i++)
{
strip1.setPixelColor(i, coloroff);
strip1.show();
strip2.setPixelColor(i, coloroff );
strip2.show();
strip3.setPixelColor(i, coloroff );
strip3.show();
strip4.setPixelColor(i, coloroff );
strip4.show();
strip5.setPixelColor(i, coloroff );
strip5.show();
strip6.setPixelColor(i, coloroff );
strip6.show();
}
}
else
{
for(int i=0;i<PIXEL_COUNT;i++)
{
strip1.setPixelColor(i, color1 );
strip1.show();
strip2.setPixelColor(i, color2 );
strip2.show();
strip3.setPixelColor(i, color3 );
strip3.show();
strip4.setPixelColor(i, color4 );
strip4.show();
strip5.setPixelColor(i, color5 );
strip5.show();
strip6.setPixelColor(i, color6 );
strip6.show();
}
}
}
void publishevent()
{
if( lastPublishedAt + publishAfter < millis() )
{
String eventName = "jiangtaoyan/2019/enchantedBar/" + System.deviceID();
Particle.publish( "jiangtaoyan/2019/enchantedBar/", "discount" );
lastPublishedAt = millis();
}
}
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. .