Kate Mytty

How to Make (Almost) Anything

Project 13: Computer Interface

The goal of this week’s project was to design a computer interface for an input device. As I had a phototransistor board from awhile back, I wanted to make a computer interface that would respond to that board. I spent awhile learning basic processing at http://hello.processing.org/guide/ - which is an incredible resource! The videos are really helpful.

I tried it in two ways: First, I used the phototransistor board that I had made during input week and tested that. I got a little response in the window.

The timer seemed to be off so I then tried again on an arduino board to see if I could make a larger response on the computer interface.

This was the result.

Project 13a

Code used


To read the light level int photoRPin = 0;
int minLight; //Used to calibrate the readings
int maxLight; //Used to calibrate the readings
int lightLevel;
int adjustedLightLevel;
void setup() {
Serial.begin(9600);
//Setup the starting light level limits
lightLevel=analogRead(photoRPin);
minLight=lightLevel-20;
maxLight=lightLevel;
}
void loop(){
//auto-adjust the minimum and maximum limits in real time
lightLevel=analogRead(photoRPin);
if(minLight>lightLevel){
minLight=lightLevel;
}
if(maxLight maxLight=lightLevel;
}
//Adjust the light level to produce a result between 0 and 100.
adjustedLightLevel = map(lightLevel, minLight, maxLight, 0, 100);
//Send the adjusted Light level result to Serial port (processing)
Serial.println(adjustedLightLevel);
//slow down the transmission for effective Serial communication.
delay(50);
}

To program the computer interface in python
import processing.serial.*;
Serial port;
float brightness = 0;
void setup()
{
size(500,500);
port = new Serial(this, "COM8", 9600);
port.bufferUntil('\n');
}
void draw()
{
background(0,255,brightness);
}
void serialEvent (Serial port)
{
brightness = float(port.readStringUntil('\n'));
}


Check out the video outcome here.

2014 Kate Mytty. This is under Creative Commons. Please do let me know if you use something.

Powered by Type & Grids