Making Things Interactive

March 6, 2008

Midterm

Filed under: 7: Mid-Term Project,Lea — tovelet @ 1:32 pm

I made a “whisker” sensor out of a guitar string, a photoresistor, and some scrap copper. It has two ways of registering a “high” reading (which causes the sequenced motion to speed up), either by touching the spring wire to the edge of its hole, or by seeing light.

The solenoids turned out to be poor at producing motion; the force holding the center rod in position is fairly strong once tripped, but it has a hard time overcoming the force of the spring. Possibly it could be mounted to bias the forces toward tripping the solenoid. In the meantime, I set up a simple LED version of the circuit, to see if I could get the code working.

The LED charlieplexed circuit is the same as the one from the Instructables tutorial (here), and the sensors are in the simple circuit from the class notes (here).

/*
 * CharlieBlink
 *
 * Cycling through six LEDs set up according to the diagram
 * at http://www.instructables.com/id/SYK7IERF1ZM4KLB/
 * 
 */


int pinA = 9;                // 
int pinB = 10;               //
int pinC = 11;               //
int buttonPin = 2;
int photoPin = 3;
int delayTime = 500;

void setup()                   // setup
{
   pinMode(buttonPin, INPUT);  // no need to set pinmode for light pins, since we do that later
}

void loop()                    // loop
{

     lightNode(pinA, pinB, pinC);      //LED1, from http://www.instructables.com/file/FCRD7A6F1ZM4KO0/
     delay(delayTime);
     lightNode(pinB, pinA, pinC);      //LED2
     delay(delayTime);
     lightNode(pinB, pinC, pinA);      //LED3
     delay(delayTime);
     lightNode(pinC, pinB, pinA);      //LED4
     delay(delayTime);
     lightNode(pinA, pinC, pinB);       //LED5
     delay(delayTime);
     lightNode(pinC, pinA, pinB);      //LED6
     delay(delayTime);
}

void lightNode(int upPin, int downPin, int nullPin)
  {
    pinMode(upPin, OUTPUT);
    pinMode(downPin, OUTPUT);
    pinMode(nullPin, INPUT);
    digitalWrite(upPin, HIGH);
    digitalWrite(downPin, LOW);
    if (digitalRead(buttonPin) == HIGH) {delayTime = 100;}
    if (digitalRead(buttonPin) == LOW) {delayTime = 500;}
  }

I need a better way to switch sequence directions. I had thought that putting each LED’s settings for up pin, down pin, and null pin into an array would be helpful, since I could then find a way of incrementing or decrementing between arrays, instead of listing the sequence. However, it seems that reading out values from the array is more trouble than the current method if I don’t have the benefit of easily switching from array to array.

Advertisements

Leave a Comment »

No comments yet.

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

Create a free website or blog at WordPress.com.

%d bloggers like this: