Anders Häggman

MAS.863 Portfolio

WEEK 12 // Interface & Application Programming

As mentioned earlier, prior to this class, I had no experience with programming. After trying a few different environments, I have found that Arduino seems to be straightforward enough for me to understand, which is why I have grown accustomed to using that.

For the programming assignment, I found that using Processing , which is very similar to the Arduino IDE was a good fit for me.

  • Level of previous experience:              
  • Time taken:               
  • Tools used:
    Arduino IDE  //  Processing
  • Got help from:
    Will Langford

To control what happens on the screen, I used and existing board I had made in an earlier week. It is a simple board with a button switch and an LED. I wanted to import the button press information via serial, and then read that information with Processing, and display one of two graphics based on if the button was pressed or not. This is the Arduino code that I used:

#include

SoftwareSerial mySerial(0, 1);

void setup() {

pinMode(7, OUTPUT);
pinMode(1, OUTPUT);

mySerial.begin(9600);
mySerial.println("What is going on?");
}

void loop()
{
int val = digitalRead(8);
if (val) {
mySerial.println(1);
} else {
mySerial.println(0);
}
delay(100);
}

With Processing, I had some issues with incorrectly located commands, so initially the pictures were flashing, or both on at the same time, etc. In the end, this code seemed to work:

import processing.serial.*;

Serial myPort; // The serial port
int lf = 10; // Linefeed in ASCII
String myString = null;

PShape owl;
PShape squirrel;
void setup() {
// List all the available serial ports
println(Serial.list());
// Open the port you are using at the rate you want:
myPort = new Serial(this, Serial.list()[2], 9600);
owl = loadShape("owl.svg");
squirrel = loadShape("squirrel.svg");
size(800, 800);
}

void draw() {

while (myPort.available() > 0) {
myString = myPort.readStringUntil(lf);
if (myString != null) {
myString = trim(myString);
println(myString);
if (myString.equals("1")) {
// println("owl");
background(255);
shape(owl, 300, 300);
} else {
// println(myString);
background(255);
shape(squirrel, 300, 300);}
}
}
}

And here is a short video clip of me pressing the button, and two images on screen changing based on if the button is pressed or not.