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;
}
}
}

1 Comment »

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

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


RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.

Blog at WordPress.com.