Interfacing with Processing

hi

I am looking to wiring for reference, and I’d like to ask about some language comparisons. As I am new to this as we all are, please understand.

Here is what I’ve altered in the serial:light serial example.

// light serial

int ledpin=13;
int val=0;
int analPin = 0;

void setup() {
beginSerial(19200);
pinMode(ledpin, OUTPUT);
}

void loop() {
val = analogRead(analPin);
printInteger(val);
printByte(1);
digitalWrite(ledpin, HIGH);
printByte(0);
delay(100);
digitalWrite(ledpin, HIGH);
}

//original code from wiring
// light serial
// by BARRAGAN http://people.interaction-ivrea.it/h.barragan

char val; // variable to receive data from the serial port
int ledpin = 48; // LED connected to pin 48 (on-board LED)
void setup()
{
pinMode(ledpin, OUTPUT); // pin 48 (on-board LED) as OUTPUT
Serial.begin(9600); // start serial communication at 9600bps
}

void loop() {
if( Serial.available() ) // if data is available to read
{
val = Serial.read(); // read it and store it in ‘val’
}
if( val == ‘H’ ) // if ‘H’ was received
{
digitalWrite(ledpin, HIGH); // turn ON the LED
} else {
digitalWrite(ledpin, LOW); // otherwise turn it OFF
}
delay(100); // wait 100ms for next reading
}


Is this correct? I haven’t got any result from the led light…

Please let me know what I should change.

thanks

Try this Arduino code with the Processing sketch from the Wiring example:

char val;    // variable to receive data from the serial port  
int ledpin = 13;  // LED connected to pin 13

void setup()  
{  
  pinMode(ledpin, OUTPUT);  // pin 13 as OUTPUT  
  beginSerial(9600);  // start serial communication at 9600bps  
}  
  
void loop() {  
  if( serialAvailable() )  // if data is available to read  
  {  
    val = serialRead();    // read it and store it in 'val'  
  }  
  if( val == 'H' )     // if 'H' was received  
  {  
    digitalWrite(ledpin, HIGH);  // turn ON the LED  
  } else {  
    digitalWrite(ledpin, LOW);   // otherwise turn it OFF  
  }  
  delay(100);     // wait 100ms for next reading  
}

Also make sure that the serial port to which Arduino is connected is the third one in the list printed by the Processing sketch (the array returned by Serial.list() is zero-based, so Serial.list()[2] is the third element).

thanks for the quick response. ::)