Back to Parent

Photon code to light the bracelet depending on Twitter climate
// This code pulls the analysis of Twitter climate and then
// if the climate is mostly positive or neutral, it turns the
// LEDs in the bracelet on. Otherwise, if the climate is mostly
// negative, it turns the LEDs in the bracelet off.

int i = 0;
int ledPin = D4;

void twitterHandler(const char *event, const char *data)
{
  i++;
  Serial.print(i);
  Serial.print(event);
  Serial.print(", data: ");
  if(data) {
    Serial.println(data);
    if(strcmp(data, "pos")==0)
    {
      Serial.println("in Pos");

      digitalWrite(ledPin, HIGH);
    } else if (strcmp(data, "neg") == 0){
      Serial.println("in Neg");

      digitalWrite(ledPin, LOW);
    } else {
      Serial.println("in Neut");

      digitalWrite(ledPin, HIGH);
    }
  } else {
    Serial.println("Null");
  }
}

void setup()
{
  pinMode(ledPin, OUTPUT);

  digitalWrite(ledPin, LOW);

  Particle.subscribe("twitter", twitterHandler);
  Serial.begin(9600);
}
Monisha Gopal (2017) Click to Expand

Content Rating

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

0