serial code
October 17th, 2007 admin
the following processing code parses an xml file (which is being dynamically changed via php). depending on the value of the given fields from the xml feed, processing will send a byte to arduino via serial which will then trigger an RGB LED to emit a specific colour.
import processing.xml.*;
import processing.serial.*;
XMLElement xml;
int temperature;
String state;
String temp;
String timer;
int time;
Serial myPort;
void setup() {
size(200, 200);
myPort = new Serial(this, Serial.list()[0],9600);
}
void draw() {
xml = new XMLElement(this, “http://itp.nyu.edu/~ss4259/xmlfeed.php”);
int children = xml.getChildCount();
println(”elements “+children);
for (int i = 0; i < children; i++) {
XMLElement kid = xml.getChild(i);
int grand_kids = kid.getChildCount();
String names = kid.getStringAttribute(”values”);
println(”grand kidz:” + names);
for(int j = 0; j < grand_kids; j++){
XMLElement grand_kid = kid.getChild(j);
String stuff = grand_kid.getContent();
if(names.equals(”temp”) == true){
temp = grand_kid.getContent();
}
else if(names.equals(”state”) == true){
state = grand_kid.getContent();
}
else if(names.equals(”timer”) == true){
timer = grand_kid.getContent();
}
println(”Variables : ” + stuff);
}
//myPort.write(’A');
if (temp.equals(”33″)) {
myPort.write(’A');
}
else if(temp.equals(”250″)){
myPort.write(’B');
}
else if(temp.equals(”400″)){
myPort.write(’C');
}
else if (state.equals(”inactive”)) {
myPort.write(’D');
}
delay(150);
}
}
Posted in icm | No Comments »