13/5/2015 // Interface & Application Programming //

Processing

Since this is my first go with Processing I wanted to learn some basic functions first. I found some cool tutorials and made a ball move in a box and change color randomly. [How exciting!!!]


The code I used for my first experiment is very simple and pretty much the same that was shown in basic tutorials for beginners like myself.
From what I was able to find Processing seems like a great program for designers and artists that want to experiment with digital media and I intend to keep exploring it's roams.

// Random Color Ball // Fab academy 2015 // By Katie Levine // Public Domain int x=30; int y=30; int speedx=12; int speedy=8; void setup() { size(1000, 700); smooth(); } void draw() { x=x+speedx; if (x>970 || x<30) { speedx=speedx*-1; fill( random(255), random(255), random(255)); } y=y+speedy; if (y>670 || y<30) { speedy=speedy*-1; fill( random(255), random(255), random(255)); } background(0); ellipse(x, y, 60, 60); }

Arduino

After gaining some basic tools for Processing I wanted to implement my new skill with an input. I tried to use the sound sensor that I made in week 10 but I didn't manage to program it. I tryied uploading Arduino code but couldn't get a read on serial monitor so I couldn't proceed with processing. I began looking for a way to connect Python serial monitor to Processing and I'm still looking for that.
For now I decided to use an actual Arduino board with an ultrasonic sensor.



In order for this process to work I made a simple Arduino code, it reads data from the sensor and writes them in serial monitor.

// Ultra Sonic Sensor with Serial // Fab academy 2015 // By Katie Levine // Public Domain //#include <Serial.h> #define trigPin 7 #define echoPin 8 int duration = 0; int cm = 0; void setup() { Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); } void loop() { digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(5); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); cm = duration / 29 /2; Serial.write (cm); delay(1); }

Processing + Arduino

After making the code for Arduino I had a working input device that could read distance from the sensor.I used a Sparkfun tutorial to learn how to combine the two programs and made a code for Processing. I made a simple ellipse that changes its' size according to the distance from the sensor.

// Ultra Sonic Sensor with Serial // Fab academy 2015 // By Katie Levine // Public Domain import processing.serial.*; int val = 0; Serial port; void setup() { size(600, 600); smooth(); frameRate(24); port = new Serial(this, Serial.list()[2], 9600); } void draw() { background(255); fill(255, 0, 0, 120); stroke (255, 0, 0, 120); ellipse (300, 300, val*5, val*5); } void serialEvent(Serial port) { val = port.read(); }

Previous Week Next Week