We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Processing to Arduino (Read 1068 times)
Processing to Arduino
Jan 23rd, 2009, 2:59pm
 
Hi there

So im trying to trigger a LED plugged into the arduino through processing to fade in. I am planning to use Max to trgger processing and inturn want processing to send the arduino a fade in so bytes from 0 - 255? I am really not sure whether im doing the right thing at all. I have max to processing to arduino to trigger but i cant seem to get it to fade in and then stop? Here is my code so far:

PROCESSING SKETCH

import oscP5.*;
import netP5.*;
import processing.serial.*;

Serial port;
OscP5 oscP5;
NetAddress myBroadcastLocation;

float tempValue = 0;
void setup()
{
 size(256, 150);
 frameRate(30);

 println("Available serial ports:");
 println(Serial.list());
   oscP5 = new OscP5(this,12000);

 // Uses the first port in this list (number 0).  Change this to
 // select the port corresponding to your Arduino board.  The last
 // parameter (e.g. 9600) is the speed of the communication.  It
 // has to correspond to the value passed to Serial.begin() in your
 // Arduino sketch.
 port = new Serial(this, Serial.list()[0], 9600);  
 
myBroadcastLocation = new NetAddress("127.0.0.1",12000);


}

void draw()
{
 byte val;

    if(tempValue > 40.0 && tempValue < 41.2) // trigger from MAX/MSP
 {
   for(val = 0 ; val <= 255; val+=1) // fade in???
 
  port.write(val);  

delay(30);

     
}
}

/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
 /* get and print the address pattern and the typetag of the received OscMessage */
 println("### received an osc message with addrpattern "+theOscMessage.addrPattern()+" and typetag "+theOscMessage.typetag());
 theOscMessage.print();

 /*****************/
//create temp value by extracting the float value from the oscMessage//
 tempValue =  theOscMessage.get(0).floatValue();
 println(tempValue);

 /*****************/


ARDUINO SKETCH

int ledPin = 9;

void setup()
{
 // begin the serial communication
 Serial.begin(9600);
 pinMode(ledPin, OUTPUT);
}

void loop()
{
 byte val;

 // check if data has been sent from the computer
 if (Serial.available()) {
   // read the most recent byte (which will be from 0 to 255)
   val = Serial.read();
   // set the brightness of the LED
   analogWrite(ledPin, val);
 }
}

Sorry if this has been posted before couldn't find anything about it:

Thanks

Page Index Toggle Pages: 1