Pages: 1 [2]   Go Down
Author Topic: From processing to arduino  (Read 1156 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And how do I do that??
sorry for being very annoying.
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3379
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And how do I do that??

How do you decide which encoding scheme to use? Coin flip?

I personally prefer ASCII over binary because it is easier to keep in sync.
« Last Edit: March 15, 2013, 02:59:19 pm by Arrch » Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 98
Posts: 3576
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How you want to send the data, is your choice.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am sending int like arduinoPort.write(pos); which is an int, how do I combine that with the strtok() command?
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3379
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am sending int like arduinoPort.write(pos); which is an int, how do I combine that with the strtok() command?

You don't. You read in the two bytes individually, and pack them into an int. strok() only works if you decide to use an ASCII encoding scheme.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And what is that like?
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3379
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And what is that like?

Like this

and

This
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, rely enjoyed the second link but when I put in processing "z = (int)(word(pos, posc));" it says the function does not exists  
« Last Edit: March 15, 2013, 03:34:24 pm by pedroply » Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3379
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, rely enjoyed the second link but when I put in "z = (int)(word(pos, posc));" it says the function does not exists 

What function doesn't exist? If you're trying to compile some code, and you get an error, not posting the entire code and the entire error is less than unhelpful.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the code:
Code:
import processing.serial.*;
import oscP5.*;
import netP5.*;


Serial arduinoPort;
OscP5 oscP5;

float redAmount = 0.0f;
float greenAmount = 0.0f;
float blueAmount = 0.0f;
byte pos = 0;
byte posc = 0;
int z;


void setup(){
  size(320, 480);
  background(0);
  oscP5 = new OscP5(this, 8000);
  arduinoPort = new Serial(this, "COM3", 9600);
 
 
}


void draw(){
  background(redAmount, greenAmount, blueAmount);
 
  fill(0);
  //red rect
  stroke(255,0,0);
  rect(34,39,67,255);
  fill(50,40,40);
  rect(34,39+255,67,-redAmount);
 
  //green rect
  fill(0);
  stroke(0,255,0);
  rect(124,39,67,255);
  fill(40,50,40);
  rect(124,39+255,67,-greenAmount);
 
  //blue rect
  fill(0);
  stroke(0,0,255);
  rect(216,39,67,255);
  fill(40,40,50);
  rect(216,39+255,67,-blueAmount);
 
 
 
 
}

void oscEvent(OscMessage theOscMessage){
  String addr = theOscMessage.addrPattern();
  float val = theOscMessage.get(0).floatValue();
 
  if(addr.equals("/1/red")){ redAmount = val;}
  if(addr.equals("/1/green")){ greenAmount = val;}
  if(addr.equals("/1/blue")){ blueAmount = val;}
  pos = byte(blueAmount);
  posc = byte(redAmount);
  z = (int)(word(pos, posc));
  arduinoPort.write(z);
 
 
 
}


and here is the error:
the fuction word(byte, byte) does not exist.
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3379
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's Processing. The example in the linked thread was a general idea about how to work with bytes and ints with the Arduino. You'll notice a couple posts down, there is a better, more portable way to do it.
« Last Edit: March 15, 2013, 03:54:58 pm by Arrch » Logged

Pages: 1 [2]   Go Up
Jump to: