i have a question on example 08a arduino networked lamp

the beginning of the sketch ( import processing.Serial.*; ) i tryed to verify
the sketch to see were i was and this came up and has stumped me to know end. im' does not name a type.

let me know what u think.

thank u

// arduino networked lamp
// parts of the code are inspired
// by a blog post by tod e. kurt (todbot.com)

import processing.Serial.*;

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

int interval = 10; // retrieve feed every 60 seconds;
int lastTime; // the last time we fetched the content

int love = 0;
int peace =0;
int arduino = 0;

int light = 0; // light level mesured by the lamp

serial port;
color c;
string cs;

string buffer = ""; // accumulates characters coming from arduino

PFont font;

void setup() {
size(640,480);
frameRate(10); // we dont need fast updates

font = loadFont("HelveticaNeue-bold-32.vlw");
fill(255);
textFont(font, 32);

// IMPORTANT NOTE:
// the first serial port retrieved by serial.list()
//should be your arduino. if not, uncomment the next
//line by deleting the // befor it and re-run the
//sketch to see a list of serial ports. then, change
//the 0 in between [ and ] to the number of the port
//that your arduino is connected to.
//println(serial.list());
String arduinoPort = Serial.list()[0];
port = new Serial(this,arduinoPort, 9600); // connect arduino

lastTime = 0;
fetchData();
}

void draw() {
background( c );
int n = (interval - ((millis()-lastTime/1000));
// build a colour based on 3 values
c = color(peace, love, arduino);
cs = "#" + hex(c,6) // prepare a string to be sent to arduino

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,240);
text(" " + love, 130, 240);
rect(200,212, love, 28);

text("arduino ",10,280);
text(" " + arduino, 130, 200);
rect(200,252, arduino, 28);

// write the colour string to the screen
text("sending", 10, 340);
text(cs, 200,340);
text("light level", 10, 380);
rect(200, 352,light/10.23,28); // this turns 1023 into 100

if (n <= 0){
fetchData();
lastTime = millis();
}

port.write(cs); // send data to Arduino

if (port.available() > 0) { // check if there is data waiting
int inByte = port.read(); // read one byte
if (inByte != 10) { // if byte is not newline
buffer = buffer + char(inByte); // just add it to the buffer
}
else {

// newline reached, let's process the data
if (buffer.length() > 1) { // make sure there is enough data

// chop off the last character, it's a carriage return
// (a carriage return is the character at the end of a
// line of text)
buffer = buffer.substring(0,buffer.length() -1);

//turn the buffer from string into an integer number
light = int(beffer);

// clean the buffer for the next read cycle
buffer = "";

// We're likely falling behind in taking readings
// from Arduino. So let's clear the backlog of
// incoming sensor readings so the next reading is
// up-to-date.
port.clear)();
}
}
}
void fetchData() {
// we use these strings to parse the feed
String data;
String chunk;

// zero the counters
love = 0;
peace = 0;
arduino =0;
try {
URL url = new URL(feed); // An object to represent the URL
// prepare a connection
URLConnection conn = url.openConnection();
conn.connect(); // now connect to the Website

// this is a bit of virtual plumbing as we connect
// the data coming from the connection to be buffered
// reader that reads the data one line at a time.
BufferedReader in = new
BufferedReader(new InputStreamReader(conn.getInputStream()));
// read each line from the feed
while ((data = in.readLine()) != null) {

StringTokenizer st =
new StringTokenizer(data,""<>,.()[] ");// break it down
while (st.hasMoreTokens()) {
// each chunk of data is made lowercase
chunk= st.nextTocken().toLowerCase() ;

if (chunk.indexOf("love") >= 0 ) // found "love"?
love++; // increment love by 1
if (chunk.indexOf("peace") >=0) // found "peace"?
peace++; // increment peace by 1
if (chunk.indexOf("arduino") >= 0) // found "arduino"?
arduino++; // increment arduino by 1
}
}

// Set 64 to be the maximum number of references we care about.
if (peace > 64) peace = 64;
if (love > 64) love = 64;
if (arduino > 64) arduino = 64;

peace = peace * 4; // multiply by 4 so that the max is 255
love = love * 4; // which comes in handy when building a
arduino = arduino * 4;// colour that is made of 4 bytes (argb)
}
catch (exception ex){ // if there was an error, stop the sketch
ex.printStackTrace();
system.out.println("ERROR: "+ex.getMessage());
}

}

That is Processing code, not Arduino.

thanks.

how do i fix this problem?

That sketch runs in Processing. If you don't have Processing installed, download it from Download Processing / Processing.org.

The associated Arduino sketch is http://cdn.makezine.com/make/books/getstartedarduino/eg/Example_08B.txt.

You will need both, I presume.

It would have helped if you had explained that it was an example from 'Getting Started with Arduino', so I didn't have to go searching for it.

thank u for the help. next time i will give more information about what i am doing.

how do i get the processing program to work with arduino i up loaded
the java program that it needed. but it still dose not see Android SDK Tools.
i am working on network lamp project from getting started with arduino.

I don't have the book, so I'm not sure. What do you need the Android SDK for? There is nothing in either sketch that suggests any Android connection.

this is were i got the program for the processing part of this project. http://processing.org/download/. and this program keeps asking
if this Android SDK is installed. witch it is now. hear is what the processing program is asking. is the android sdk installed ?
the android sdk dose not appear to be installed,
because the ANDROID_SDK variable is not set.
if it is installed, click yes to slect the location of the sdk or no to visit the sdk
download site at http://devloper.android.com/sdk.
let me know what u think. thank you.

Are you trying to click the Standard/Android button in the top right of the Processing IDE? That seems to be what triggers the Android SDK requirement. You don't need to change that from Standard, unless you want to target Android devices.

i see i did not know this. thanks for the help.

i got most of the lamp to work but i am having problems with the button to turn the lamp on and off.
the leds switch and the sensor is working.
this project is from getting started with arduino
hears the arduino code
// Example 08B: Arduino Networked Lamp
//
// Copy and paste this example into an empty Arduino sketch

#define SENSOR 0
#define R_LED 9
#define G_LED 10
#define B_LED 11
#define BUTTON 12

int val = 0; // variable to store the value coming from the sensor

int btn = LOW;
int old_btn = LOW;
int state = 0;
char buffer[7] ;
int pointer = 0;
byte inByte = 0;

byte r = 0;
byte g = 0;
byte b = 0;

void setup() {
Serial.begin(9600); // open the serial port
pinMode(BUTTON, INPUT);
}

void loop() {
val = analogRead(SENSOR); // read the value from the sensor
Serial.println(val); // print the value to
// the serial port

if (Serial.available() >0) {

// read the incoming byte:
inByte = Serial.read();

// If the marker's found, next 6 characters are the colour
if (inByte == '#') {

while (pointer < 6) { // accumulate 6 chars
buffer[pointer] = Serial.read(); // store in the buffer
pointer++; // move the pointer forward by 1
}

// now we have the 3 numbers stored as hex numbers
// we need to decode them into 3 bytes r, g and b
r = hex2dec(buffer[1]) + hex2dec(buffer[0]) * 16;
g = hex2dec(buffer[3]) + hex2dec(buffer[2]) * 16;
b = hex2dec(buffer[5]) + hex2dec(buffer[4]) * 16;

pointer = 0; // reset the pointer so we can reuse the buffer

}
}

btn = digitalRead(BUTTON); // read input value and store it

// Check if there was a transition
if ((btn == HIGH) && (old_btn == LOW)){
state = 1 - state;
}

old_btn = btn; // val is now old, let's store it

if (state == 1) { // if the lamp is on

analogWrite(R_LED, r); // turn the leds on
analogWrite(G_LED, g); // at the colour
analogWrite(B_LED, b); // sent by the computer
} else {

analogWrite(R_LED, 0); // otherwise turn off
analogWrite(G_LED, 0);
analogWrite(B_LED, 0);
}

delay(100); // wait 100ms between each send
}

int hex2dec(byte c) { // converts one HEX character into a number
if (c >= '0' && c <= '9') {
return c - '0';
} else if (c >= 'A' && c <= 'F') {
return c - 'A' + 10;
}
}
hears the process code
// Example 08A: Arduino networked lamp
// parts of the code are inspired
// by a blog post by Tod E. Kurt (todbot.com)
//
// Copy and paste this example into an empty Processing sketch

import processing.serial.*;

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

int interval = 10; // retrieve feed every 60 seconds;
int lastTime; // the last time we fetched the content

int love = 0;
int peace = 0;
int arduino = 0;

int light = 0; // light level measured by the lamp

Serial port;
color c;
String cs;

String buffer = ""; // Accumulates characters coming from Arduino

PFont font;

void setup() {
size(640,480);
frameRate(10); // we don't need fast updates

font = loadFont("HelveticaNeue-Bold-32.vlw");
fill(255);
textFont(font, 32);
// IMPORTANT NOTE:
// The first serial port retrieved by Serial.list()
// should be your Arduino. If not, uncomment the next
// line by deleting the // before it, and re-run the
// sketch to see a list of serial ports. Then, change
// the 0 in between [ and ] to the number of the port
// that your Arduino is connected to.
println(Serial.list());
String arduinoPort = Serial.list()[1];
port = new Serial(this, arduinoPort, 9600); // connect to Arduino

lastTime = 0;
fetchData();
}

void draw() {
background( c );
int n = (interval - ((millis()-lastTime)/1000));

// Build a colour based on the 3 values
c = color(peace, love, arduino);
cs = "#" + hex(c,6); // Prepare a string to be sent to Arduino

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,240);
text(" " + love, 130, 240);
rect(200,212, love, 28);

text("arduino ",10,280);
text(" " + arduino, 130, 280);
rect(200,252, arduino, 28);

// write the colour string to the screen
text("sending", 10, 340);
text(cs, 200,340);

text("light level", 10, 380);
rect(200, 352,light/10.23,28); // this turns 1023 into 100

if (n <= 0) {
fetchData();
lastTime = millis();
}

port.write(cs); // send data to Arduino

if (port.available() > 0) { // check if there is data waiting
int inByte = port.read(); // read one byte
if (inByte != 10) { // if byte is not newline
buffer = buffer + char(inByte); // just add it to the buffer
}
else {

// newline reached, let's process the data
if (buffer.length() > 1) { // make sure there is enough data

// chop off the last character, it's a carriage return
// (a carriage return is the character at the end of a
// line of text)
buffer = buffer.substring(0,buffer.length() -1);

// turn the buffer from string into an integer number
light = int(buffer);

// clean the buffer for the next read cycle
buffer = "";

// We're likely falling behind in taking readings
// from Arduino. So let's clear the backlog of
// incoming sensor readings so the next reading is
// up-to-date.
port.clear();
}
}
}

}

void fetchData() {
// we use these strings to parse the feed
String data;
String chunk;

// zero the counters
love = 0;
peace = 0;
arduino = 0;
try {
URL url = new URL(feed); // An object to represent the URL
// prepare a connection
URLConnection conn = url.openConnection();
conn.connect(); // now connect to the Website

// this is a bit of virtual plumbing as we connect
// the data coming from the connection to a buffered
// reader that reads the data one line at a time.
BufferedReader in = new
BufferedReader(new InputStreamReader(conn.getInputStream()));

// read each line from the feed
while ((data = in.readLine()) != null) {

StringTokenizer st =
new StringTokenizer(data,""<>,.()[] ");// break it down
while (st.hasMoreTokens()) {
// each chunk of data is made lowercase
chunk= st.nextToken().toLowerCase() ;

if (chunk.indexOf("love") >= 0 ) // found "love"?
love++; // increment love by 1
if (chunk.indexOf("peace") >= 0) // found "peace"?
peace++; // increment peace by 1
if (chunk.indexOf("arduino") >= 0) // found "arduino"?
arduino++; // increment arduino by 1
}
}

// Set 64 to be the maximum number of references we care about.
if (peace > 64) peace = 64;
if (love > 64) love = 64;
if (arduino > 64) arduino = 64;

peace = peace * 4; // multiply by 4 so that the max is 255,
love = love * 4; // which comes in handy when building a
arduino = arduino * 4; // colour that is made of 4 bytes (ARGB)
}
catch (Exception ex) { // If there was an error, stop the sketch
ex.printStackTrace();
System.out.println("ERROR: "+ex.getMessage());
}

}

15 posts, and you still can't post code correctly? Modify your post. Select all the code. Select the icon with the # sign. Save your post.

When you do your part, we'll look at the code.

like this?

// Example 08A: Arduino networked lamp
// parts of the code are inspired
// by a blog post by Tod E. Kurt (todbot.com)
//
// Copy and paste this example into an empty Processing sketch

import processing.serial.*;

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

int interval = 10;  // retrieve feed every 60 seconds;
int lastTime;       // the last time we fetched the content

int love    = 0;
int peace   = 0;
int arduino = 0;

int light = 0;  // light level measured by the lamp

Serial port;
color c;
String cs;

String buffer = ""; // Accumulates characters coming from Arduino

PFont font;

void setup() {
  size(640,480);
  frameRate(10);    // we don't need fast updates

  font = loadFont("HelveticaNeue-Bold-32.vlw");  
  fill(255);  
  textFont(font, 32);
  // IMPORTANT NOTE:
  // The first serial port retrieved by Serial.list()
  // should be your Arduino. If not, uncomment the next
  // line by deleting the // before it, and re-run the
  // sketch to see a list of serial ports. Then, change
  // the 0 in between [ and ] to the number of the port
  // that your Arduino is connected to.
   println(Serial.list());
  String arduinoPort = Serial.list()[1];
  port = new Serial(this, arduinoPort, 9600); // connect to Arduino

  lastTime = 0;
  fetchData();
}

void draw() {
  background( c );
  int n = (interval - ((millis()-lastTime)/1000));

  // Build a colour based on the 3 values
  c = color(peace, love, arduino);
  cs = "#" + hex(c,6); // Prepare a string to be sent to Arduino

  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,240);
  text(" " + love, 130, 240);
  rect(200,212, love, 28);

  text("arduino ",10,280);
  text(" " + arduino, 130, 280);
  rect(200,252, arduino, 28);

  // write the colour string to the screen
  text("sending", 10, 340);
  text(cs, 200,340);

  text("light level", 10, 380);
  rect(200, 352,light/10.23,28); // this turns 1023 into 100

  if (n <= 0) {
    fetchData();
    lastTime = millis();
  }

  port.write(cs); // send data to Arduino

  if (port.available() > 0) { // check if there is data waiting
    int inByte = port.read(); // read one byte
    if (inByte != 10) { // if byte is not newline
      buffer = buffer + char(inByte); // just add it to the buffer
    }
    else {

      // newline reached, let's process the data
      if (buffer.length() > 1) { // make sure there is enough data

        // chop off the last character, it's a carriage return
        // (a carriage return is the character at the end of a
        // line of text)
        buffer = buffer.substring(0,buffer.length() -1);
 
        // turn the buffer from string into an integer number
        light = int(buffer);

        // clean the buffer for the next read cycle
        buffer = "";

        // We're likely falling behind in taking readings
        // from Arduino. So let's clear the backlog of
        // incoming sensor readings so the next reading is
        // up-to-date.
        port.clear(); 
      }
    } 
  }

}

void fetchData() {
  // we use these strings to parse the feed
  String data; 
  String chunk;

  // zero the counters
  love    = 0;
  peace   = 0;
  arduino = 0;
  try {
    URL url = new URL(feed);  // An object to represent the URL
    // prepare a connection   
    URLConnection conn = url.openConnection(); 
    conn.connect(); // now connect to the Website

    // this is a bit of virtual plumbing as we connect
    // the data coming from the connection to a buffered
    // reader that reads the data one line at a time.
    BufferedReader in = new
      BufferedReader(new InputStreamReader(conn.getInputStream()));

    // read each line from the feed
    while ((data = in.readLine()) != null) {

      StringTokenizer st =
        new StringTokenizer(data,"\"<>,.()[] ");// break it down
      while (st.hasMoreTokens()) {
        // each chunk of data is made lowercase
        chunk= st.nextToken().toLowerCase() ;

        if (chunk.indexOf("love") >= 0 ) // found "love"?
          love++;    // increment love by 1
        if (chunk.indexOf("peace") >= 0)   // found "peace"?
          peace++;   // increment peace by 1
        if (chunk.indexOf("arduino") >= 0) // found "arduino"?
          arduino++; // increment arduino by 1
      }
    }

    // Set 64 to be the maximum number of references we care about.
    if (peace > 64)   peace = 64;
    if (love > 64)    love = 64;
    if (arduino > 64) arduino = 64;

    peace = peace * 4;     // multiply by 4 so that the max is 255,
    love = love * 4;       // which comes in handy when building a
    arduino = arduino * 4; // colour that is made of 4 bytes (ARGB)
  } 
  catch (Exception ex) { // If there was an error, stop the sketch
    ex.printStackTrace();
    System.out.println("ERROR: "+ex.getMessage());
  }

}[/code
[code]// Example 08B: Arduino Networked Lamp
//
// Copy and paste this example into an empty Arduino sketch

#define SENSOR 0   
#define R_LED 9
#define G_LED 10
#define B_LED 11
#define BUTTON 12

int val = 0; // variable to store the value coming from the sensor

int btn = LOW;
int old_btn = LOW;
int state = 0;
char buffer[7] ;
int pointer = 0;
byte inByte = 0;

byte r = 0;
byte g = 0;
byte b = 0;

void setup() {
  Serial.begin(9600);  // open the serial port
  pinMode(BUTTON, INPUT);
}

void loop() {
  val = analogRead(SENSOR); // read the value from the sensor
  Serial.println(val);      // print the value to
                            // the serial port

  if (Serial.available() >0) {

    // read the incoming byte:
    inByte = Serial.read();

    // If the marker's found, next 6 characters are the colour
    if (inByte == '#') {

      while (pointer < 6) { // accumulate 6 chars
        buffer[pointer] = Serial.read(); // store in the buffer
        pointer++; // move the pointer forward by 1
      }

      // now we have the 3 numbers stored as hex numbers
      // we need to decode them into 3 bytes r, g and b
      r = hex2dec(buffer[1]) + hex2dec(buffer[0]) * 16;
      g = hex2dec(buffer[3]) + hex2dec(buffer[2]) * 16;
      b = hex2dec(buffer[5]) + hex2dec(buffer[4]) * 16;
      
      pointer = 0; // reset the pointer so we can reuse the buffer
     
    }
  }   

  btn = digitalRead(BUTTON); // read input value and store it

  // Check if there was a transition
  if ((btn == HIGH) && (old_btn == LOW)){
    state = 1 - state;
  }

  old_btn = btn; // val is now old, let's store it

  if (state == 1) { // if the lamp is on
 
    analogWrite(R_LED, r);  // turn the leds on
    analogWrite(G_LED, g);  // at the colour
    analogWrite(B_LED, b);  // sent by the computer
  } else {

    analogWrite(R_LED, 0);  // otherwise turn off
    analogWrite(G_LED, 0); 
    analogWrite(B_LED, 0);
   }
 
  delay(100);                // wait 100ms between each send
}

int hex2dec(byte c) { // converts one HEX character into a number
    if (c >= '0' && c <= '9') {
      return c - '0';
    } else if (c >= 'A' && c <= 'F') {
      return c - 'A' + 10;
    }
}

[/code]

like this?

Was there some part of "Modify your original post" that you failed to comprehend?

  if (Serial.available() >0) {

    // read the incoming byte:
    inByte = Serial.read();

    // If the marker's found, next 6 characters are the colour
    if (inByte == '#') {

      while (pointer < 6) { // accumulate 6 chars
        buffer[pointer] = Serial.read(); // store in the buffer

So, if there is one byte available to read, read all 7 of them. Yeah? How's that working for you?

but i am having problems with the button to turn the lamp on and off.

You need to elaborate on this statement. What problem(s) are you having? Is it with Processing or Arduino?

i found the problem with this project it was my own fault on this. i used to many resistors on the led plus i had one that was too big
for the button. thanks for your help.