light into frequency

I finally had some time to hook up the TSL230 to an Arduino Mini.

here is the code i used for the arduino board and some code to print out a graph with processing.

the graph is still a bit jumpy. i hope to make this a bit more stable.

-- here is the code for the arduino --
int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;
int inPin = 2;

unsigned long duration;

void setup(){
Serial.begin(9600);
Serial.println("TSL230");

pinMode(inPin, INPUT);

pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);

digitalWrite(s1,LOW);
digitalWrite(s0,HIGH);

digitalWrite(s3,HIGH);
digitalWrite(s2,HIGH);

}

void loop(){
duration = pulseIn(inPin, HIGH);
Serial.println(duration);
}


-- code for processing

// i have the TSL2300 on a solderess board and am holding a IR led to the side of my finger
// you might have to adjust the distance between IR led and TSL230 to get the graph in the right range

// Graph
// by David A. Mellis
//
// Demonstrates reading data from the Arduino board by graphing the
// values received.
//
// based on Analog In
// by Josh Nimoy.

import processing.serial.*;

Serial port;
String buff = "";
int NEWLINE = 10;

// Store the last 64 values received so we can graph them.
int[] values = new int[64];

int min_value = 0;
int max_value = 0;
int min_pos = 0;
int max_pos = 0;

void setup()
{
size(600, 600);
frameRate(30);
// println("Available serial ports:");
// println(Serial.list());

port = new Serial(this, Serial.list()[0], 9600);

}

void draw()
{
background(53);
stroke(255);

// Graph the stored values by drawing a lines between them.
max_value = -1000;
min_value = 1000;

for (int i = 0; i < 63; i++) {
stroke(255);
line(i * 8, 255 - values_, (i + 1) * 8, 255 - values[i + 1]);_
if(values < min_value){
min_value = values*;
min_pos = i;
_ }_
if(values > max_value){
max_value = values;
max_pos = i;
_ }
}
stroke(200,200,0);
line(min_pos * 8, 0 , min_pos * 8, 255 - min_value);
line(max_pos * 8, 255 - max_value, max_pos * 8, height);
while (port.available() > 0)
serialEvent(port.read());
}
void serialEvent(int serial)
{
if (serial != NEWLINE) {
// Store all the characters on the line.
buff += char(serial);
}
else {
if(buff.length() > 0){
// The end of each line is marked by two characters, a carriage*

* // return and a newline. We're here because we've gotten a newline,
// but we still need to strip off the carriage return.
buff = buff.substring(0, buff.length()-1);
// Parse the String into an integer.
int val = Integer.parseInt(buff);
// Clear the value of "buff"
buff = "";
// Shift over the existing values to make room for the new one.
for (int i = 0; i < 63; i++)
values = values[i + 1];_

int temp_val = val - 10000;
_ // Add the received value to the array._
values[63] = temp_val;
print(" " + temp_val);
_ }
}
}
---*_