Homework 05 – Arduino and Processing – Casey Henrichs

14 Nov

Here I changed the background color as well as changed the “stroke” values to include the “xPos” input which gave a colored gradient in the processing window.

This is the processing code run with a potentiometer.

import processing.serial.*;

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

void setup () {
// set the window size:
size(1000, 300);

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:

background(50); // set inital background:
void draw () {


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

String inString = myPort.readStringUntil(‘\n’);

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 is storing all inpute data
inByte = map(inByte, 0, 1023, 0, height);//map incomming value to height of screen, fourth value here is 0-300

//can add ellipse command determined by the potentiometer, to get it to move all the way across the screen find the “size” (1000) above and [multiply by three due to the “inbyte scale” already intact]
stroke(150, xPos, xPos);// draw the line: changing the value here can change color
line(xPos, height, xPos, height – inByte);

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


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s