{\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf470 {\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} \paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0 \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0 \f0\fs24 \cf0 import processing.serial.*;\ \ Serial myPort;\ int val;\ int [] x = new int[500]; //Graph data x:Time\ int [] y = new int[500]; //Graph data y:Voltage\ \ void setup() \ \{\ frameRate(50); //Update every 20msec\ size(600, 350);\ myPort = new Serial(this, "/dev/tty.usbserial-FT98HM6Z", 9600);\ textSize(20);\ \ //To initialize the graph data\ for (int i = 0; i < x.length; i++)\{\ x[i] = i;\ y[i] = 128;\ \} \ \}\ \ void draw()\ \{\ background(0);\ \ //To update the graph data\ for (int i = 0; i < y.length - 1; i++)\{\ y[i] = y[i+1];\ \}\ y[y.length - 1] = val;\ \ \ //To draw the graph area\ fill(255);\ text("0V",10,310);\ text("5V",10,54);\ text("0sec",530,340);\ text("-10sec",30,340);\ fill(0,255,0);\ text(val/255.0*5,560,100);\ \ \ //To plot the data\ pushMatrix();\ translate(50,300);\ scale(1,-1);\ fill(0);\ stroke(255);\ rect(0,0,500,256);\ stroke(0,255,0);\ for (int i = 0; i < x.length - 1; i++)\{\ line(x[i],y[i],x[i+1],y[i+1]);\ \}\ popMatrix();\ \}\ \ void serialEvent(Serial myPort)\{\ delay(10);\ val = myPort.read();\ \}}