Skills Dev 5 - WeiNi, Shariq, Yashasvi
Made by shariqs, Wei-Ni Ting and ytulchiy
Made by shariqs, Wei-Ni Ting and ytulchiy
Created: December 16th, 2020
In this exercise, we will develop paired devices and networked interactions with Particle.publish and Particle.subscribe. Our team builds on the idea of our final project, which is to create an ambient mosaic that lights up in different colors based on users' inputs for their emotions. Once a user inputs his or her emotional status, a second user's device should be able to receive that status and triggers the component.
void setup() {
Particle.function("happy",setHappy);
Particle.function("sad",setSad);
Particle.function("fear",setFear);
Particle.function("disgust",setDisgust);
Particle.function("anger",setAnger);
Particle.function("surprise",setSurprise);
Particle.function("off",setOff);
Particle.publish("emotion", "off", PRIVATE);
}
int setHappy(String command){
if(command.equals("happy")){
Particle.publish("emotion", "happy", PRIVATE);
return 1;
}
}
int setSad(String command){
if(command.equals("sad")){
Particle.publish("emotion", "sad", PRIVATE);
return 2;
}
}
int setFear(String command){
if(command.equals("fear")){
Particle.publish("emotion", "fear", PRIVATE);
return 3;
}
}
int setDisgust(String command){
if(command.equals("disgust")){
Particle.publish("emotion", "disgust", PRIVATE);
return 4;
}
}
int setAnger(String command){
if(command.equals("anger")){
Particle.publish("emotion", "anger", PRIVATE);
return 5;
}
}
int setSurprise(String command){
if(command.equals("surprise")){
Particle.publish("emotion", "surprise", PRIVATE);
return 6;
}
}
int setOff(String command){
if(command.equals("off")){
Particle.publish("emotion", "off", PRIVATE);
return 0;
}
}
void loop(){
}
Click to Expand
// 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