求!processing如何画出两路波形
我有程序可以画一路波形:
import processing.serial.*;
PFont font;
Scrollbar scaleBar;
Serial port;
int Sensor; // HOLDS PULSE SENSOR DATA FROM ARDUINO
int IBI; // HOLDS TIME BETWEN HEARTBEATS FROM ARDUINO
int BPM; // HOLDS HEART RATE VALUE FROM ARDUINO
int[] RawY; // HOLDS HEARTBEAT WAVEFORM DATA BEFORE SCALING
int[] ScaledY; // USED TO POSITION SCALED HEARTBEAT WAVEFORM
int[] rate; // USED TO POSITION BPM DATA WAVEFORM
float zoom; // USED WHEN SCALING PULSE WAVEFORM TO PULSE WINDOW
float offset; // USED WHEN SCALING PULSE WAVEFORM TO PULSE WINDOW
color eggshell = color(255, 253, 248);
int heart = 0; // This variable times the heart image 'pulse' on screen
//THESE VARIABLES DETERMINE THE SIZE OF THE DATA WINDOWS
int PulseWindowWidth = 490;
int PulseWindowHeight = 512;
int BPMWindowWidth = 180;
int BPMWindowHeight = 340;
boolean beat = false; // set when a heart beat is detected, then cleared when the BPM graph is advanced
void setup() {
size(700, 600);// Stage size 屏大小
frameRate(100);
font = loadFont("Arial-BoldMT-24.vlw");
textFont(font);
textAlign(CENTER);
rectMode(CENTER);
ellipseMode(CENTER);
// Scrollbar constructor inputs: x,y,width,height,minVal,maxVal
scaleBar = new Scrollbar (400, 575, 180, 12, 0.5, 1.0);// set parameters for the scale bar
RawY = new int; // initialize raw pulse waveform array
ScaledY = new int; // initialize scaled pulse waveform array
rate = new int ; // initialize BPM waveform array
zoom = 0.75; // initialize scale of heartbeat window
// set the visualizer lines to 0
for (int i=0; i<rate.length; i++){
rate = 555; // Place BPM graph line at bottom of BPM Window
}
for (int i=0; i<RawY.length; i++){
RawY = height/2; // initialize the pulse window data line to V/2
}
// GO FIND THE ARDUINO
println(Serial.list()); // print a list of available serial ports
// choose the number between the [] that is connected to the Arduino
port = new Serial(this, Serial.list(), 115200);// make sure Arduino is talking serial at this baud rate
port.clear(); // flush buffer
port.bufferUntil('\n');// set buffer full flag on receipt of carriage return
}
void draw() {
background(0);
noStroke();
// DRAW OUT THE PULSE WINDOW AND BPM WINDOW RECTANGLES
fill(eggshell);// color for the window background
rect(255,height/2,PulseWindowWidth,PulseWindowHeight);
rect(600,385,BPMWindowWidth,BPMWindowHeight);
// DRAW THE PULSE WAVEFORM
// prepare pulse data points
RawY = (1023 - Sensor) - 212; // place the new raw datapoint at the end of the array
zoom = scaleBar.getPos(); // get current waveform scale value
offset = map(zoom,0.5,1,150,0); // calculate the offset needed at this scale
for (int i = 0; i < RawY.length-1; i++) { // move the pulse waveform by
RawY = RawY; // shifting all raw datapoints one pixel left
float dummy = RawY * zoom + offset; // adjust the raw data to the selected scale
ScaledY = constrain(int(dummy),44,556); // transfer the raw data array to the scaled array
}
stroke(250,0,0); // red is a good color for the pulse waveform
noFill();
beginShape(); // using beginShape() renders fast
for (int x = 1; x < ScaledY.length-1; x++) {
vertex(x+10, ScaledY); //draw a line connecting the data points
}
endShape();
//DO THE SCROLLBAR THINGS
scaleBar.update (mouseX, mouseY);
scaleBar.display();
//
}//end of draw loop
这个程序是从串口0接受一个传感器的数据,然后画出波形,我现在想不断在两个传感器进行跳转采集出数据传1和传2(数据结果为121212121212121212交替从串口0上传),然后同时画出这两个波形。上面这个程序是单一路的,怎样才能传1一路,传2 一路,两路都显示呢?求大神指点。
将两个数据放入两个数组,再一起画。 林定祥 发表于 2016-5-5 17:47 static/image/common/back.gif
将两个数据放入两个数组,再一起画。
嗯嗯,谢谢!我觉得也是,关键我不知道怎么改,你能指出在哪块怎样改一改吗?谢谢。
页:
[1]