Making Things Interactive

March 8, 2008

Midterm: Single Pixel of a 3-D Mirror

Filed under: 7: Mid-Term Project,Paul Castellana — paulcastellana @ 4:21 pm

I was trying to insert some images I posted to Flickr, but it’s not working. Here’s the link to flickr though.

I found the formula for linearizing the voltage output from the IR Range sensor here.

Video:

int servoPin = 2;     // Control pin for servo motor
int minPulse = 500;   // Minimum servo position
int maxPulse = 2500;  // Maximum servo position
int pulse = 0;        // Amount to pulse the servo

long lastPulse = 0;    // the time in milliseconds of the last pulse
int refreshTime = 20; // the time needed in between pulses

int val;             // outgoing ADC value
int distance = 0;    // linearized distance value

void setup()
{
pinMode(servoPin, OUTPUT);  // Set servo pin as an output pin
pulse = minPulse;           // Set the motor position value to the minimum
beginSerial(9600);
}

void loop()
{
val = analogRead(0); // read analog input:
distance = (2914 / (val + 5)) - 1;   // linearize sensor readings
printString("distance = "); // print out distance readings for reference
printInteger(distance);
printString("  ");

delay(10);

pulse = distance*125;    // convert distance to a value between minPulse
// and maxPulse

if (minPulse < pulse = refreshTime) {  // pulse the servo again if rhe refresh time (20 ms) have passed:
digitalWrite(servoPin, HIGH);   // Turn the motor on
delayMicroseconds(pulse);       // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW);    // Turn the motor off
lastPulse = millis();           // save the time of the last pulse
} else {
pulse = minPulse;
}
}
}
Advertisements

1 Comment »

  1. Your first tag should use the word “sourcecode” instead of just “source”

    Comment by jssmith44 — March 10, 2008 @ 2:03 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: