Interface and Application Programming

This week's assignment was to write an application that interfaces with one of the devices designed during this semester. Evidently, I have chosen my device from the input week and written an application to visualize the measured values. Since my programming skills are quite poor I have relied on Anna's working example and have modified the code to leave my personalized fingerprint. My programming software of choice was Processing and since I was using Arduino for every code till now I was able to understand the written example.

First of all, I have changed the random colors of the lines to simple black and wanned to visualize the values all the way around: close detection to long line and far detection to short line. Because of this change I have in the code "200-height", 200 being the maximum considerable receivable value. Since, my window is 1024x1024 I simply have multiplied everything by two to fill up the whole window. Another tweak is the personalized background which a simple image and is loaded into the application with the loadImage command. None the less, when the received values are more than 1024 black lines, the background image re-loads (for a new "page") and the reading keeps on going.

It was really fun to program the application and learned even more about how programming code works.


import processing.serial.*;

Serial serialPort;
int col = 0;
PImage img;

void setup() {
size(1024, 1024); //set window size

img = loadImage("bg.jpg"); //load background image
image(img, 0, 0); //place background image

// open serial port: COM4
println(Serial.list());
serialPort = new Serial(this, Serial.list()[1], 9600);
}

void draw() {

while (serialPort.available () > 0) {
int height = serialPort.read();
col = col+1;
if (col > 1024) {
col = 0;
image(img, 0, 0);
}
println(height); //print the values from the serial port
line(col, 512-(200-height)*2, col, (200-height)*2+512);

stroke((int)(0));
}
}