Physical Computing, Uncategorized

Electro-Magnate

It’s 8:08 AM… yes people, 808. and i did consume 8+8 caffeinated beverages over the course of the last 22 hours I’ve been P-Comping. I’m not great on documentation after I crash out, but here’s some Arduino code.

int incomingByte = 0;

//servo variables

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

int increment = 50; //there are 40 gear teeth of planar movement

//the servo has 2000 explicit values

//this means 1 tooth is our greatest resolution of movement

//ergo, pulse50 = 1 tooth

//so if we move 5 times/sec, which is 250pulse/sec

//the total render time is 8 seconds

int movePerSec = 5; // how quickly we are rendering the model

int delayTime = 10000 / movePerSec; //determines proper delay

//pixels

int incomingBytes[9]={255,255,255,255,255,255,255,255,255}; //set all pins to white

int currentPinVal[9];

int pixelPin=9; //set pixel  pin

long lastPulse = 0;    // the time in milliseconds of the last pulse

int refreshTime = 20; // the time needed in between pulses

int analogValue = 0;  // the value returned from the analog sensor

int analogPin = 0;    // the analog pin that the sensor’s on

void setup(){

pinMode(servoPin, OUTPUT);  // Set servo pin as an output pin

pinMode(pixelPin, OUTPUT);

pulse = minPulse;           // Set the motor position value to the minimum

Serial.begin(9600);

}

void loop(){

if(Serial.available() > 0)

{

incomingBytes[8]=Serial.read(); //just read the 9th pixel

//get values & map to usable servo data

for(i=0;i<9;i++)

{

//incomingBytes[i]=Serial.read();   //get pixel values from Processing

currentPinVal[i] = map(incomingBytes[i], 0, 255, 500, 2500); //change brightness value to depth

Serial.print(“I received: “);

Serial.println(incomingBytes[i]);

}

//place servo at first position

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

}

//delay(100);

//pulse = map(incomingByte, 0, 255, minPulse, maxPulse); //changing brightness value to servo position

// pulse the servo again if rhe refresh time (20 ms) have passed:

//TO ADD: conditional servo reset to 500 & resetting magnets back on

// also, check if all magnets are off

if (millis() – lastPulse >= refreshTime)

{

if(pulse >= currentPinVal[0])//if we are have passed the pin’s value

{

digitalWrite(pixelPin, LOW)//turn off magnet through transistor

}

else

{

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

pulse += increment;

delay(delayTime);

}

}

}

speak up

Add your comment below, or trackback from your own site.

Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*Required Fields