coding problems not sure about whats wrong

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());
}
}

Please make sure you post any code within the code tags, so it's easier to read. just put [code][/code] around it (without the * though)

Also, it looks like you're looking to run this code with Processing. I would suggest first looking at the Arduino with Processing tutorial.

thanks :slight_smile:

captianillogical:
thanks :slight_smile:

Also, just a quick note, it looks like you have a typo:

String feed = "hppt://blog.makezine.com/index.xml";

Shouldn't that be 'http'? :stuck_out_tongue:

Shouldn't that be 'http'?

There are two typos. char * is seriously misspelled, too.

There's also a 'ckunk' where I think he means 'chunk'.

i am having a problem with the command void fetchData(){ in processing i am in java mode of processing what is the problem also this is the same code from earlier

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()[0];
  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();
      }
    }
  }
   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 (chunk.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());
    }
  }

im doing this sketch from my book and i am having a lot of problems.I understand that it is Processing code and every time i try to run processing with the arduino plugin it just crashes! Also can i run this program without the plugin. in conclusion i am unsure about pretty much everything. plaese help

hppt://blog.makezine.com/index.xml should use http instead of hppt... try that?

this is a processing problem, not an arduino problem.

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

If Serial.list() returns NULL, because there are no com ports that the Arduino could be listening to, referencing the first item in the non-existent list WILL cause a crash.

i am having a problem with the command

Bummer, dude!

Now, if you defined what the problem was, maybe we could offer some suggestions.

i am in java mode of processing

What the heck does this mean?

what is the problem also this is the same code from earlier

Complete lack of punctuation.

unexpected token void was command my problem
ignore my punctuation and and at the top right it says mode manager and i cant get rid of java mode without another mode such as python

michinyon:
this is a processing problem, not an arduino problem.-michinyon

everyone on processing says this is an arduino problem

was command my problem

Could be that because of your piss-poor indenting, you are trying to define the fetchData() function inside the draw() function.

at the top right it says mode manager

At the top, right of what?

Idontunderstandwhyyouthinkpunctuationandpropercapitalizationdoesn'tmatter.

everyone on processing says this is an arduino problem

and every time i try to run processing with the arduino plugin it just crashes!

Unplug the Arduino. Run Processing. Does it crash? If so, it can't possibly be an Arduino problem.

You should print the list returned by Serial.list(), with delimiters before and after the list, so the list is quite clear. If the list is empty, you have one problem. If it's not, you have another problem. Which one are we trying to help you solve?

I wouldn't go any further if the OP can't be bothered to write something readable. How he thinks making things hard to read is going to help I don't know.

I'm not your girlfriend you're texting to. I'm a programmer you're asking for help. If you don't want that help then don't bother.

Someone who can't be bothered to put a period at the end of a sentence probably also couldn't be bothered to format his code which would immediately reveal the problem.

I can see it from here sticking out like a sore thumb.

Isn't there a Processing forum?

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

  • Moderator