Back to Parent

// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

// Include Particle Device OS APIs
#include "Particle.h"
#include <neopixel.h>

#define PIXEL_PIN SPI // plug into pin MO
#define PIXEL_COUNT 12 // 0 addressed
//#define PIXEL_TYPE SK6812RGBW
#define PIXEL_TYPE WS2812

// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);

// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
SerialLogHandler logHandler(LOG_LEVEL_INFO);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

static int photoPin = A0;
static int tempPin = A1;


uint32_t w = strip.Color(0, 0, 0, 255); // Pure white
uint32_t blue = strip.Color(0, 0, 255); // Blue
uint32_t green = strip.Color(0, 255, 0); // Green
uint32_t purple = strip.Color(100, 0, 100); // Purple
uint32_t red = strip.Color(255, 0, 0); // Red

uint32_t c1 = green; 
uint32_t c2 = purple; 

int photoReading = 0;
int tempReading = 0;
int tempOut =0;
int photoOut = 0;
// setup() runs once, when the device is first turned on
void setup() {
    Particle.function("kiss", kiss);
    Particle.function("ambient", ambient);
    
    Particle.variable("Brightness", photoReading);
    Particle.variable("Temperature", tempReading);
    strip.begin();
    ambient("");
   
   //Particle.subscribe("diot/love-cup-kiss/cup1/", handleKiss); //cup1 for other cup
   Particle.subscribe("diot/love-cup-kiss/", handleKiss);

}

// loop() runs over and over again, as quickly as it can execute.
void loop() {
    photoReading = analogRead(photoPin);
    tempReading = analogRead(tempPin);
    
  
    
    
    delay(100);
    
    if (photoReading < 2500){
       // Particle.publish();
        publishKiss();
    }
    else{
        ambient("");
    }
    if(tempReading > 509){
        c1 = red;
    }
    else{
        c1 = blue;
    }
    delay (1000);
}

int ambient(String Command){
    for( int i = 0; i < strip.numPixels(); i++ ){
        strip.setPixelColor(i, c1); // set a color 
        strip.show();
        delay( 100 );
    }
    return 1;
}

int kiss(String Command){
     
    for( int i = 0; i < strip.numPixels(); i++ ){
        strip.setPixelColor(i, c1); // set a color 
        strip.show();
        delay( 100 );
    }
    for( int i = 0; i < strip.numPixels(); i++ ){
        strip.setPixelColor(i, c2); // set a color 
        strip.show();
        delay( 100 );
    }
    return 1;
}

void publishKiss(){
    String eventName = "diot/love-cup-kiss/" + System.deviceID();
    Particle.publish(eventName, NULL, 30, PUBLIC);//cup2 for other cup
    //String eventName = "love-cup/kiss/0a10aced202194944a05990c";
    //Particle.publish(eventName, NULL, 30, PUBLIC);
}

void handleKiss(const char *event, const char *data){
    kiss("");
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0