Drawing Waveform ?

84 views
Skip to first unread message

Danesvar Neelamagam

unread,
Apr 15, 2015, 11:45:27 PM4/15/15
to mitappinv...@googlegroups.com
Hello everyone. For the app i'm developing i need to draw the waveform. I have done a project that needed to draw a wave form using arduino processing. heres the code:

// DRAW THE PULSE WAVEFORM
  // prepare pulse data points    
  RawY[RawY.length-1] = (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[i] = RawY[i+1];                         // shifting all raw datapoints one pixel left
    float dummy = RawY[i] * zoom + offset;       // adjust the raw data to the selected scale
    ScaledY[i] = constrain(int(dummy),44,556);   // transfer the raw data array to the scaled array
  }
  stroke(250,0,0);                               // red
  noFill();
  beginShape();                                  // using beginShape() renders fast
  for (int x = 1; x < ScaledY.length-1; x++) {    
    vertex(x+10, ScaledY[x]);                    //draw a line connecting the data points
  }
  endShape();


How do i do this with app inventor?

SteveJG

unread,
Apr 16, 2015, 7:57:41 AM4/16/15
to mitappinv...@googlegroups.com
This will will get you a graph on the AI2 Canvas.

You save the curve information  (data points x,y) in a csv file  and plot as shown in one of the examples

or

use the Acellerometer real time example to plot the data in real time.

The code you provided draws a graph using a different language ... there is a scaling routine shown showing how to move from World coordinates (your data set) to Screen coordinates (the x,y coordinates of the Canvas).

Regards,
Steve




Reply all
Reply to author
Forward
0 new messages