Back to Parent

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



// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812

Adafruit_NeoPixel light_ring = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

bool happyStatus = false;
bool sadStatus = false;
bool fearStatus = false;
bool disgustStatus = false;
bool angerStatus = false;
bool surpriseStatus = false;
bool offStatus = false;

// happiness - red - 255,0,0
// sadness - blue - 0,0,128
// fear - orange - 255,140,0
// disgust - green - 0,128,0
// anger - yellow - 255,255,0
// surprise - pink - 255,105,180
// off - white - 255,255,255

int state = 0;

void setup() {

  light_ring.begin();
  light_ring.show(); 
  
  getHappy();
	delay( 500 );
  getSad();
	delay( 500 );
  getFear();
	delay( 500 );
  getDisgust();
	delay( 500 );
  getAnger();
	delay( 500 );
  getSurprise();
	delay( 500 );
  turnOff();
  
  Particle.subscribe("emotion", myColor );

}

void myColor( const char *event, const char*data){
    
    String dataStr = String( data );
    
    if(dataStr.equals( "happy")){
        //getHappy();
				state = 1;
    } else if (dataStr.equals( "sad" ) ){
        //getSad();
				state = 2;
    } else if (dataStr.equals( "fear" )  ){
        //getFear();
				state = 3;
    } else if ( dataStr.equals( "disgust" ) ){
        //getDisgust();
				state = 4;
    } else if (dataStr.equals( "anger" )  ){
        //getAnger();
				state = 5;
    } else if (dataStr.equals( "surprise" )  ){
        //getSurprise();
				state = 6;
    } else if (dataStr.equals( "off" ) ){
        //turnOff();
				state = 0;
    }
    
}

void loop(){
    
    
    if (state == 1){
    	getHappy();
		}else if (state == 2){
		 	getSad();
		}else if (state == 3){
    	getFear();
		}else if (state == 4){
    	 getDisgust();
		}else if (state == 5){
			getAnger();
		}else if (state == 6){
			getSurprise();
		}else{
			turnOff();
		}
		
		delay( 100 );
    
}

void getHappy(){
    
    
    for(int i=0; i<light_ring.numPixels(); i++){
    light_ring.setPixelColor(i,255,0,0); //red
    }
    light_ring.show();
    
}

void getSad(){
    
    
    for(int i=0; i<light_ring.numPixels(); i++){
    light_ring.setPixelColor(i,0,0,128); //blue
    }
    light_ring.show();
    
}

void getFear(){
    
    
    for(int i=0; i<light_ring.numPixels(); i++){
    light_ring.setPixelColor(i,255,140,0); //orange
    }
    light_ring.show();
    
}

void getDisgust(){
    
    
    for(int i=0; i<light_ring.numPixels(); i++){
    light_ring.setPixelColor(i,0,128,0); //green
    }
    light_ring.show();
    
}

void getAnger(){
    
    
    for(int i=0; i<light_ring.numPixels(); i++){
    light_ring.setPixelColor(i,255,255,0); //yellow
    }
    light_ring.show();
    
}

void getSurprise(){
    
    
    for(int i=0; i<light_ring.numPixels(); i++){
    light_ring.setPixelColor(i,255,105,180); //pink
    }
    light_ring.show();
    
}
  
    
void turnOff(){
    
    
    for(int i=0; i<light_ring.numPixels(); i++){
    light_ring.setPixelColor(i,255,255,255); //white
    }
    light_ring.show();
    
}
Click to Expand

Content Rating

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

0