Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
ppppaul
ppppaul's Profile
1
Posts
1
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
Problem with serial event and declaring a variable
[2 Replies]
11-May-2013 11:41 AM
Forum:
Programming Questions
Hello,
i recently try to write a sketch for processing which uses the Arduino-Brain-Library as input source.
My Problem is that i cannot get any values from the serialEvent to use in the void draw loop.
If i let them println in the serialEvent they are correct. If i let them println in the void draw loop they turn zero.
Sorry for the clumsy english. Here is my code in the most simplest version i could think off:
import processing.serial.*;
Serial myPort; // The serial port
int packetCount = 0;
float what;
void setup () {
// set the window size:
size(400, 300, P3D);
// List all the available serial ports
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil(10);
background(0);
frameRate (25);
}
void draw () {
println (what); //this gives me zero
}
void serialEvent (Serial myPort) {
// get the ASCII string:
String[] Values = split(myPort.readString(), ',');
// Verify that the packet looks legit
if (Values.length > 1) {
packetCount++;
// Wait till the third packet or so to start recording to avoid initialization garbage.
if (packetCount > 3) {
for (int i = 0; i < Values.length; i++) {
int newValue = Integer.parseInt(Values[i].trim());
//println (Values[4]); //this works
float what = float (Values[4]);
}
}
}
}
«Prev
Next »
Moderate user : ppppaul
Forum