this is my first post and i think i am just asking a stupid question but i don't know for sure. I am following this code below from my book and I understand that it is supposed to run on the computer;but how do I make it do that.
import processing.serial.*;
String feed = "hppt://blog.makezine.com/index.xml";
int intirval = 10;
int lastTime;
int love = 0;
int peace = 0;
int arduino = 0;
int light = 0;
Serial port;
color c;
String cs;
String buffer = "";
PFont font;
void setup() {
size(640, 480);
frameRate(10);
font = loadFont("HelveticaNueue-Bold-32.vlw");
fill(255);
textFont(font, 32)
String arduinoPort = Serial.list()[3];
port = new Serial(this, arduinoPort, 9600);
lastTime = 0;
fetchData();
}
void draw() {
backround( c );
int n = (interval - ((milis() - lastTime) / 1000));
c = color(peace, love, arduino);
cs = "#" + hex(c, 6);
text("Arduino Networked Lamp", 10, 40);
text("Reading feed", 10, 100);
text(feed, 10, 140);
text("Next update in " + n + " seconds", 10, 450);
text("peace" , 10, 200);
text("" + peace, 130, 200);
rect(200, 172, peace, 28);
text("love", 10, 200);
text("" + love, 130 240);
rect(200, 212, love, 28);
text("arduino ", 10, 280);
text("" + arduino, 130, 280);
rect(200, 252, arduino, 28);
text("sending", 10, 340);
text(cs, 200, 340);
text("light level", 10, 380);
rect(200, 352, light / 10.23, 28);
if (n <= 0) {
fetchData();
lastTime = millis();
}
port.write(cs);
if (port.avaliable() > 0) {
int inByte = port.read();
if (inByte != 10) {
buffer = buffer + char(inByte);
}
else {
if (buffer.length() > 1) {
buffer = buffer.substring(0, buffer.length() - 1);
light = int(buffer);
buffer = "";
port.clear();
}
}
}
void fetchData() {
String data;
String chunk:
love = 0
peace = 0;
arduino = 0:
try {
URL url = new Url(feed);
URLConnection conn = url.openConnection();
conn.connect();
BufferedReader in = new
BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((data = in, readLine()) != null) {
StringTokenizer st =
new StringTokenizer(data, ""<>,.()[] ");
while (st.hasMoreTokens()) {
chunk = st.nextToken().toLowerCase() ;
if (chunk.indexOf("love") >= 0 )
love++;
if (ckunk.indexOf("peace") >= 0)
peace++;
if (chunk.indexOf("arduino") >= 0)
arduino++;
}
}
if (peace > 64) peace = 64;
if (love > 64) love = 64;
if (arduino > 64) arduino = 64;
peace = peace * 4;
love = love * 4;
arduino = arduino * 4;
}
catch (Exeption ex) {
ex.printStackTrace();
System.out, println("ERROR: " + ex.getMessage());
}
}