Back to Parent

int redPin= D0;
int greenPin = D2;
int bluePin = D1;
int c1 = 0;
int c2 = 0;
int c3 = 0;
String whatSong = "";
// int triggered = 0;
void setup(){
  // Subscribe to the integration response event
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  Particle.subscribe("Spotify", myHandler, MY_DEVICES);
}
void loop(){
  // Get some data
  String data = String(10);
  // Trigger the integration
  Particle.publish("Spotify", data, PRIVATE);
  Serial.println("**************");
  Serial.println("What I'm playing right now?");
  for (int i = 0; i < 10; i ++){
    changeColor (c1, c2, c3);
    if (whatSong == "Jazz"){
      jazzSong(c1, c2, c3);
    } else if (whatSong == "Musical"){
      musicalNumber(c1, c2, c3);
    } else if (whatSong == "Pop"){
      popSong(c1, c2, c3);
    } else if (whatSong == "Rock") {
      rockSong(c1, c2, c3);
    } else {
      Serial.println("nothing is playing");
      setColor(255, 255, 255);
    }
  }
  // int c1 = rand()  % 255 ;
  // int c2 = rand()  % 255 ;
  // int c3 = rand()  % 255 ;
  // setColor(c1, c2, c3); // Random Color
  // delay(1000);
  // c1 = rand()  % 255 ;
  // c2 = rand()  % 255 ;
  // c3 = rand()  % 255 ;
  // setColor(c1, c2, c3); // Random Color
  // if(triggered == 1){
  //   Serial.println("TRIGGER");
  //   triggered = 0;
  // }
  // Wait 60 seconds
  delay(10000);
}
void changeColor(int c1, int c2, int c3){
  c1 = rand() %255;
  c2 = rand() %255;
  c3 = rand() % 255;
  setColor(c1, c2, c3);
  delay(2000);
}
void jazzSong(int c1, int c2, int c3){
  c1 = rand() % 90;
  c2 = rand() % 200 + 65;
  c3 = rand() % 255 + 200;
  setColor(c1, c2, c3);
  delay(2000);
}
void musicalNumber(int c1, int c2, int c3){
  c1 = rand() % 100;
  c2 = rand() % 250+230;
  c3 = rand() % 100;
  setColor(c1, c2, c3);
  delay(2000);
}
void popSong(int c1, int c2, int c3){
  c1 = rand() % 255;
  c2 = rand() % 255;
  c3 = rand() % 255;
  setColor(c1, c2, c3);
  delay(2000);
}
void rockSong(int c1, int c2, int c3){
  c1 = rand() % 255 + 230;
  c2 = rand() % 70;
  c3 = rand() % 70;
  setColor(c1, c2, c3);
  delay(2000);
}
void setColor(int redValue, int greenValue, int blueValue) {
  analogWrite(redPin, redValue);
  analogWrite(greenPin, greenValue);
  analogWrite(bluePin, blueValue);
}
void myHandler(const char *event, const char *data) {
  // Handle the integration response
  Serial.println("**************");
  Serial.println(data);
  if (strcmp(data,"L-O-V-E")==0){
    Serial.println("Yeah! L-O-V-E");
    whatSong = "Jazz";
  } else if (strcmp(data, "You&#39;re Welcome")==0){
    Serial.println("Yeah! You're welcome.");
    whatSong = "Musical";
  } else if (strcmp(data, "Love Never Felt so Good")==0){
    Serial.println("Yeah! Love never felt so good.");
    whatSong = "Pop";
  } else if (strcmp(data, "Another One Bites The Dust - Remastered 2011")==0) {
    Serial.println("Yeah! Another One.");
    whatSong = "Rock";
  } else {
    Serial.println("false");
    // whatSong = "";
  }
  // triggered = 1;
  Serial.println("**************");
}
Click to Expand

Content Rating

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

0