Video

Homework 05 – Arduino and Processing – Daniel Scott

14 Nov

I was attempting to create a solid line in the middle that as i turned the potentiometer and it cycled to below and above the solid line, the color would change depending upon whether it was above that line or below.. Didn’t get quite that far but its getting there. Code as follows:

import processing.serial.*;

Serial myPort;
int xPos = 1; //horizontal position of graph
//

void setup () {
size(1000, 600);//sets window size

println(Serial.list()); //list available serial ports
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil(‘\n’);//continously read the values

background(60, 110, 40);//color of background
}
void draw () {//initiates draw loop

}

void serialEvent (Serial myPort) {//
String inString = myPort.readString();
if (inString != null) {
inString = trim(inString);
float inByte = float(inString);
inByte = map(inByte, 100, 1025, 0, height);

stroke(255, 175, 40);//color of stroke
line(xPos, 250, xPos, height – inByte);//height of stroke
stroke(255, 175, 40);//sets color
line(xPos, 350, xPos, height – inByte);
stroke(255, xPos, 0);//sets color
line(xPos, 350, xPos, height – inByte);

if (xPos >= width) {//ends the window
xPos = 0;//loops back to begining
background(60, 110, 40);//redefines background color
}
else {
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