I don't understand why split() is always setting the last data value read in to be zero. Can anyone advise?
EDIT: I do see the last value if I split to strings, instead of converting with int(). So the last string in the line contains a newline, and int() sees a non-numeric value and sets it to zero?
Here is the relevant section of my code:
import processing.serial.*; // serial library
Serial myPort; // The serial port String inBuffer = null; // one line of data from serial port
void draw() { int[] dat; // array of numbers read in on one line from serial port
if (inBuffer != null) { // wait for new data on the serial port
print("SERIAL:" + inBuffer); // show the line of serial input dat = int(split(inBuffer, ',')); // parse comma-separated number string into numbers println("DAT_IN:" + dat[0] + "," + dat[1] + "," + dat[2] + "," + dat[3] + "," + dat[4]); println(); // [... plus other stuff ...] } }
void serialEvent(Serial p) { inBuffer = p.readString(); // store serial port buffer in global var inBuffer }
and here is a sample of the output I get. Note how the last number in the line, 125 or 123, always becomes 0.
I am using a processing sketch to do a data acquisition task (data forwarded to pachube.com). This computer sometimes reboots for windows updates, etc. (I am running Windows XP SP3). How do I get my PachubeData.pde sketch to auto-run after the computer reboots?
If I simply double-click on the .pde filename, it launches the Processing edit window, but does not actually start the sketch. To have it run I have to separately click the "Run" button. So I presume dragging the link to the "Startup" folder will have the same effect (launch the Processing editor, but not the sketch itself). Any suggestions?
EDIT: OOops! Nevermind, I just discovered "File/Export Application" to create the standalone .exe file.
I want to add very simple, real time audio output to my Processing program. Can someone suggest the easiest way? I checked the external sound libraries, there are nine different ones listed at
http://processing.org/reference/libraries/#sound but they all appear to be focused on music composition, rather than simple low-level raw sound.
What I want is something like: beep(pitch, volume, duration) and I get a simple beep tone of that pitch, that many milliseconds long. No wavetable synthesis, scoring system etc.
The "SoundCipher" appears to be simple, because I can get one note played like this:
import arb.soundcipher.*; // simple audio library "SoundCipher" (tempo=120 bpm)
SoundCipher sc = new SoundCipher(this); // sound object for audio feedback
sc.playNote(60, 100, 1); // pitch number, volume, duration in beats
However this is a shaped note with an attack-decay-sustain-release volume envelope, which limits how fast I can make separate notes. I want a raw beep with no volume envelope. Is there a simple way to do this?
I'm doing data acquisition with an Arduino and collecting the data (serial over USB) on the PC with a Processing 1.2.1 program. I am using a separate serialEvent() function to grab data into a buffer, which I guess is interrupt-driven(?).
Printing out the delta between millis() on each pass through draw(), it is usually 15 msec or 30 msec. Can I change that? Setting frameRate() doesn't seem to change anything.
UPDATE: I see that I can make it slower, by setting a lower number, for example with frameRate(5) I get about 200 msec per cycle as expected. So I guess this is a limitation of my computer speed (old Inspiron 9300 laptop).