Homework 05 – Arduino and Processing – Kevin Desautels

14 Nov

I hooked up a potentiometer to control the graph in processing. There is a dot in the upper left corner that is supposed to also be controlled by the potentiometer, but isn’t quite working yet.

CODE:

float radius = 400.0;
import processing.serial.*;

Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph

void setup () {

size(1000, 500); // set the window size:
strokeWeight(5);
frameRate(15);
smooth();

println(Serial.list()); // List all the available serial ports
myPort = new Serial(this, Serial.list()[0], 9600); // don’t generate a serialEvent() unless you get a newline character:
myPort.bufferUntil(‘\n’);

background(209); // set inital background:
}

void draw () {
radius = radius + sin( frameCount / 4 );
fill(255, 0, 0);
stroke(255,255,255);
ellipse(X, Y, radius, radius);
}

void serialEvent (Serial myPort) {// get the ASCII string:

String inString = myPort.readString();

if (inString != null) { // trim off any whitespace:

inString = trim(inString);// convert to an int and map to the screen height:

float inByte = float(inString);
inByte = map(inByte, 0, 1023, 0, height);//map incomming value to height of screen

stroke(0, 0, 0 );// draw the line:
fill(0,121,184);
line(xPos, height, xPos, height – inByte);

// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
background(209);
}
else {
// increment the horizontal position:
xPos++;
}
}
}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s