We feel fine

 

 

 

 

 

 

 

 

Idea: Use data gathered from the we feel fine project and display it using the arduino. A query is launched from processing asking for some feelings of persons in pittsburgh and then tranformed into a percentage of bad/good feelings which are assigned to an amount of a certain colour (blue for bad, red for good).

When there is a change in the world, the LED blinks and updates its status.

 

Processing Code:

 

import processing.xml.*;

import processing.serial.*;

 

Serial myPort;  // Create object from Serial class

int val;        // Data received from the serial port

XMLElement xml;

int lastPerGood=0;

int lastPerBad=0;

String buff = “”;

int NEWLINE = 10;

 

void setup() {

  size(200, 200);

  println(Serial.list());

  String portName = Serial.list()[0];

  myPort = new Serial(this, portName, 9600);

}

 

void draw() {

  background(255);

  int good=0;

  int bad=0;

  int total=0;

  int perGood=0;

  int perBad=0;

  

  xml = new XMLElement(this, “http://api.wefeelfine.org:8080/ShowFeelings?display=xml&returnfields=sentence,%20feeling&limit=500&city=Pittsburgh”);

  

  int numSentences = xml.getChildCount();

  

  for (int i = 0; i < numSentences; i++) {

    XMLElement kid = xml.getChild(i);

    String id = kid.getStringAttribute(“feeling”); 

    if(id!=null){

      if(id.equals(“good”)||id.equals(“happy”)||id.equals(“better”)){

        good=good+1;

        total=total+1;

      }

      if(id.equals(“bad”)||id.equals(“sad”)||id.equals(“worse”)){

        bad=bad+1;

        total=total+1;

      }

    }

  }

  

  println(“feeeling…”);

  perGood=(good*100/total);

  perBad=(bad*100/total);

  if(perGood!=lastPerGood || perBad!=lastPerBad){

    lastPerGood=perGood;

    lastPerBad=perBad;

    println(“\nTotal:”+total+”  Good:”+good+”  Bad:”+bad);

    println(“Good(%):”+perGood+”  Bad(%):”+perBad);

    myPort.write(255);

  }

 myPort.write(perBad);

  println(perBad);

  delay(3000);

   

}

 

 

Arduino Code:

 

 

int ledBluePin = 9;

int ledRedPin=10;

void setup()

{

  // begin the serial communication

  Serial.begin(9600);

  pinMode(ledBluePin, OUTPUT);

  pinMode(ledRedPin, OUTPUT);

}

 

void loop()

{

  byte val;

  

  analogWrite(ledRedPin,200);

  // check if data has been sent from the computer

  if (Serial.available()) {

    // read the most recent byte (which will be from 0 to 255)

    val = Serial.read();

    if(val==255) blink() else analogWrite(ledBluePin, val*3);

    // set the brightness of the LED

  }

}

 

 

void blink(){

  int i=0;

  while(i<=10){

  analogWrite(ledRedPin, 0);

  delay(100);

  analogWrite(ledRedPin, 255);

  delay(100);

  i=i+1;

  }

}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s