Thursday, December 1, 2011

Wings Update

So, it looks like the wings were better received than I thought they'd be. Its a tremendous relief since I thought I was going to be fending off judgemental remarks at the sheer scale of my nerdiness.

Popular Mechanics listed me as one of the 7 coolest projects of World Maker Faire 2011!

I got news from the CEO of my museum (New York Hall of Science) that we're going to turn the wings into an installation piece that will live on the museum floor. They are going to be placed up on a stand and programmed to flap on their own continuously. I might even build a manual control box to allow visitors to control them. Then again, I might not. Visitors destroy everything. Everything.

And last but not least, the museum's fund raising department asked me to bring the wings to our annual gala to show it off to the big wig trustees and investors! Was definitely a nice photo op (see below).

Sunday, September 4, 2011

Great Success!!!

So, Im a little speechless right now. Like I said before, I have been sitting on this idea for about a year so to see it get to this point is kind of a big moment. Im not going to say too much more, but here is a video of the wings in operation, both front view and back:





I have to admit, they work well, but not quite as well as I had built them up in my mind. Because of the limitations of the springs and servos, the wings are very easily overcome by gravity. That means I have to stand pretty straight up so that the wings' weight are neutral and the pushing of the spring hinges and pulling of the servos can do their job. Overall the wings weigh under 20 pounds and have a wingspan of close to 12 feet. There is still a lot of work to be done in terms of making them more robust and sturdy and also polishing them up to display status (which might have to wait till after Maker Faire). Feel free to comment and share your thoughts!

-Adiel

P.S. I want to thank everyone that didnt laugh and call me a ridiculous nerd (there really isnt any doubt that I am one, but its nice not to have other people call you one :P) as soon as I told them I was building a giant set of wings based on a super hero. My roommate Marcia for tolerating the insane mess and aluminum shavings and dust that now coat our apartment, and my great friends from work (too many of you to name, but you know who you are), you guys really are awesome. If anything, thanks for just being excited for me.

Above all, I want to thank my girlfriend Valery for being so supportive and not leaving my obsessive compulsive ass when I worked on them for 12 hour stints when I should have been taking her out to a fancy dinner.

Thursday, September 1, 2011

Shrunken Circuits and Reinforcement

Hey Everyone,

I am starting to get tired. Really tired. I'm so into this project that Im losing massive amounts of sleep slouching over a soldering iron inhaling some fine lead fumes in the middle of the night. But, I regret nothing. I've been thinking about this project for about a year now and there were times where I thought it wasn't going to happen due to cost or that it just wouldn't work. Seeing it get to a point where I can actually wear them and operate the electronics with a pair of gloves has made me more excited and determined than ever. And thats right, you heard me, they are developed enough that I can put them on and walk around! However, I'm not posting any pictures just yet. Not until they are more polished, I gotta build up a little bit of anticipation. I've been working at these for months, you guys can wait in suspense for a week :)

Last night, I spend a good amount of time reinforcing the wings, but more on that in a later post.

Most of my time, however, was spent moving the electronics from the purely-prototype stage into a more robust version that will actually go on the wings. Here's what the electronics looked like before without all the servos and gloves:


And here it is next to the gloves and servos for scale:

 
For those that don't know, a normal Arduino (the blue microcontroller thats doing all the thinking) and a "breadboard" (the white rectangle you put all the parts on) are a bit bulky because they are designed to be totally plug and play. Wires and pins can be pushed into slots and moved around very quickly to build a circuit and get a working prototype very quickly. However, because it's so easy to put together, it falls apart very easily and is a bit on the bulky size.

The next stage is moving all those components (like resistors, lights, switches, etc) onto a board you can hardwire them onto called a perfboard. Since theres much more flexibility regarding positioning on a perfboard, you can also make the whole circuit much smaller by routing the little connections more efficiently. Also, by using a different microcontroller, in this case the Arduino Pro Mini, thats designed to be hardwired (and not so plug and play) you can shrink it down to a fraction of the size. It took me hours, well into the wee hours of the morning, to optimize the arrangement and solder it onto the perfboard, but here is how it turned out:

With a new (and better) battery pack, servos and gloves for scale:

By itself with a sharpie (again for scale)


Considering it was my first time wiring anything onto a perfboard, I'm extremely proud of how it came out. Now its small enough to be concealed in a small space between the backplate and my back so everything but the servos will be completely hidden from view, giving the wings a very minimal tech-presence.

Thats it for now, next up will be a little bit of switch debugging and mounting everything onto the wings! Are you excited over there? Because I am kind of freaking out from the excitement over here.

Tuesday, August 30, 2011

Gloves and Code Update

So, I've made a bit of progress the past few days/weeks but I'll update it in stages.

Ive put together the gloves and general circuit that controls the servos that will be attached to the wings. The gloves took me several hours to do just because the buttons I am using are so small (not to mention have tiny tiny metal contacts that are made for surface mount PCBs) that it took me a while to solder them, wire them, sew them into the gloves and then reinforce them so they stand up to repeated bending and pushing while I am wearing them. I think the result is fairly robust. Of course, if I get my hand caught in a car door it doesnt matter how much hot glue I use, the push-button is gonna be totaled.

Here are some pictures of the gloves solo and attached to the circuit board.


So, each finger has its own push-button responsible for a different behavior in the wings. Also, I built the gloves so that they could be detached from the leads that connect them to the microcontroller.




Messy, I know. You can see the servos in the back with little metal bobbins attached to the servo horns. I used epoxy rated for 3200 PSI to glue the bobbins. Im sure I couldve gotten away with krazy glue, but the epoxy was the same price at home depot so I figured I'd over engineer it so I wouldnt have to worry about it later on.

I've spent the past few days working on changing the code to give me better functionality out of the wings. The way I originally had it setup, holding a button on a finger would cause the servo to wind up the line that would pull or release the wing, so if you let go the button it would stop. This is easy to use, but because the Arduino is so focused on the button thats being pressed, it isnt able to do anything else in the meantime. That means I was restricted to moving only one segment at a time which is kinda boring and awkward to look at.

To solve this, I designed the code so that pushing (and releasing a button) would start the servo and pushing it again would stop it. This means that once a servo is activated, the arduino is free to do whatever else it pleases, i.e. activate other servos. This means that now, all the servos are free to be operated simultaneously, so I can move the wings any way I see fit, when I see fit.

But, that was a pain in the ass to do. I am the first one to admit, I am not a very strong programmer. I've only really been at it for a few months and its still a little new. With this new method of using the buttons, I had to combat this weird property of electric circuits called "bouncing". Basically, when you try to push a button down, the electricity tends to bounce back and forth in the button, so much so that the microcontroller thinks its switching back and forth a dozen times. So now I have to make it smart enough to recognize this noisey button for what it is and really identify whether or not Im pressing the button. Also, it has to remember what the button was the last time it was pressed.

I was able to get it done, but not without a lot of frustration. But, I think Im a more experienced programmer for it, so all's well that ends well. I could post a video of the gloves turning on the servos, but all you would see are the little silver spools spinning. Once I get the servos mounted to the wings I'll take a video and post it.

Below is the code. If you dont speak code, then feel free to take this as the end of the blog post, theres nothing really interesting down there :)


#include //call up library


#define RI_Pin 2 //Define pins
#define RM_Pin 3
#define RR_Pin 4
#define RP_Pin 5
#define LI_Pin 6
#define LM_Pin 7
#define LR_Pin 8
#define LP_Pin 9
#define rightOuterServoPin 10
#define rightInnerServoPin 11
#define leftInnerServoPin 12
#define leftOuterServoPin 13

int RI_State = LOW; //Current switch states
int RM_State = LOW;
int RR_State = LOW;
int RP_State = LOW;
int LI_State = LOW;
int LM_State = LOW;
int LR_State = LOW;
int LP_State = LOW;

int RI_Old_State = LOW; //Old switch states
int RM_Old_State = LOW;
int RR_Old_State = LOW;
int RP_Old_State = LOW;
int LI_Old_State = LOW;
int LM_Old_State = LOW;
int LR_Old_State = LOW;
int LP_Old_State = LOW;

int RI_Servo_State = LOW; //Switch state stored to send to servo
int RM_Servo_State = LOW;
int RR_Servo_State = LOW;
int RP_Servo_State = LOW;
int LI_Servo_State = LOW;
int LM_Servo_State = LOW;
int LR_Servo_State = LOW;
int LP_Servo_State = LOW;

const int EXPAND = 0; //expand = servo value 0 = CCW motion
const int STOP = 90;
const int CONTRACT = 180; //contract = servo value 180 = CW motion

Servo rightOuterServo; //Create instances of Servos
Servo rightInnerServo;
Servo leftInnerServo;
Servo leftOuterServo;


void setup() {
rightOuterServo.attach(rightOuterServoPin); //attach servos to proper pins
rightInnerServo.attach(rightInnerServoPin);
leftInnerServo.attach(leftInnerServoPin);
leftOuterServo.attach(leftOuterServoPin);


pinMode(RI_Pin,INPUT); //set finger buttons as inputs
pinMode(RM_Pin,INPUT);
pinMode(RR_Pin,INPUT);
pinMode(RP_Pin,INPUT);
pinMode(LI_Pin,INPUT);
pinMode(LM_Pin,INPUT);
pinMode(LR_Pin,INPUT);
pinMode(LP_Pin,INPUT);

rightOuterServo.write(STOP); //make sure servos begin sketch as stopped
rightInnerServo.write(STOP);
leftInnerServo.write(STOP);
leftOuterServo.write(STOP);
}


void loop() {

//Read Switch States
RI_Old_State = digitalRead(RI_Pin);
RM_Old_State = digitalRead(RM_Pin);
RR_Old_State = digitalRead(RR_Pin);
RP_Old_State = digitalRead(RP_Pin);
LI_Old_State = digitalRead(LI_Pin);
LM_Old_State = digitalRead(LM_Pin);
LR_Old_State = digitalRead(LR_Pin);
LP_Old_State = digitalRead(LP_Pin);
delay(10);
RI_State = digitalRead(RI_Pin);
RM_State = digitalRead(RM_Pin);
RR_State = digitalRead(RR_Pin);
RP_State = digitalRead(RP_Pin);
LI_State = digitalRead(LI_Pin);
LM_State = digitalRead(LM_Pin);
LR_State = digitalRead(LR_Pin);
LP_State = digitalRead(LP_Pin);

//Right Index
if (RI_State != RI_Old_State) {
if(RI_State == 1) {
RI_Servo_State = !RI_Servo_State;
}
if (RI_Servo_State == 1) {
rightOuterServo.write(EXPAND);
} else {
rightOuterServo.write(STOP);
}
}

//Right Middle
if (RM_State != RM_Old_State) {
if(RM_State == 1) {
RM_Servo_State = !RM_Servo_State;
}
if (RM_Servo_State == 1) {
rightInnerServo.write(EXPAND);
} else {
rightInnerServo.write(STOP);
}
}

//Right Ring
if (RR_State != RR_Old_State) {
if(RR_State == 1) {
RR_Servo_State = !RR_Servo_State;
}
if (RR_Servo_State == 1) {
rightOuterServo.write(CONTRACT);
} else {
rightOuterServo.write(STOP);
}
}

//Right Pinky
if (RP_State != RP_Old_State) {
if(RP_State == 1) {
RP_Servo_State = !RP_Servo_State;
}
if (RP_Servo_State == 1) {
rightInnerServo.write(CONTRACT);
} else {
rightInnerServo.write(STOP);
}
}

//Left Index
if (LI_State != LI_Old_State) {
if(LI_State == 1) {
LI_Servo_State = !LI_Servo_State;
}
if (LI_Servo_State == 1) {
leftOuterServo.write(EXPAND);
} else {
leftOuterServo.write(STOP);
}
}

//Left Middle
if (LM_State != LM_Old_State) {
if(LM_State == 1) {
LM_Servo_State = !LM_Servo_State;
}
if (LM_Servo_State == 1) {
leftInnerServo.write(EXPAND);
} else {
leftInnerServo.write(STOP);
}
}

//Left Ring
if (LR_State != LR_Old_State) {
if(LR_State == 1) {
LR_Servo_State = !LR_Servo_State;
}
if (LR_Servo_State == 1) {
leftOuterServo.write(CONTRACT);
} else {
leftOuterServo.write(STOP);
}
}

//Left Pinky
if (LP_State != LP_Old_State) {
if(LP_State == 1) {
LP_Servo_State = !LP_Servo_State;
}
if (LP_Servo_State == 1) {
leftInnerServo.write(CONTRACT);
} else {
leftInnerServo.write(STOP);
}
}

}













Saturday, August 27, 2011

Archangel Wings: Full Disclosure

So, I've told most people about my Maker Faire project, but I havent mentioned it on here very often because this site was restricted mostly to ITP class assignments. But, class is over and all of you loyal fans (all 3 of you, you are too kind) are here waiting for more, so here goes a full description of the project.

The details:
Life size metal wings inspired by the superhero Archangel
They are going to be made from 7075 alloy, air-craft grade aluminum with a final wingspan of close to 12 feet wide, not exactly to scale from the photo, but those would be impossible to wear. The wing will be be articulated at two joints per wing, one on the aluminum backplate I'll be wearing, and another joint half-way down the wing. At the joints will be spring hinges that spring the wings outwards when contracted. Here is a picture of all the panels laid out on the floor with me in the middle for scale:
The wings were originally supposed to be actuated by shape memory alloy ("muscle wire"), but due to limitations of the high maintenance material I had to abandon it in favor of using servos. All's well that ends well, because they will now be completely under my control with full range of motion as opposed to the 20-30 degrees of motion that the muscle wire was capable of producing. The servos will be attached to the wing panels and backplate and will wind up a low-profile, high-strength fishing line, pulling the wings towards them. Wind it one direction and the wings contract, spin the servo in the other direction and the spring hinges take over and open the wings. Heres a video I made while testing the servo control on small sample pieces of aluminum:



I am working on two different methods of control. Manual control of the wings will definitely be ready by Maker Faire (if not sooner), but I am having a really hard time procuring the right components to make the other work. The other method is to have a heart rate monitor I am wearing send signals to the arduino microcontroller which will then flap the wings at a rate proportional to beating of my heart. A simple toggle switch will alternate between one mode and the other (if I can just get that damn heart rate receiver!)

Manual control of the wings will be wired into two gloves I'll be wearing. Each glove will have small push-button switches hidden in the tips of each of the fingers, each responsible for an individual wing panel. Pressing one finger tip will move a certain panel outwards, pressing another finger will bring it back. This will allow me to control each of the wing panels individually and position them any way I want (even fold them up behind me) just by moving certain fingers. I'm hoping it will give the illusion that they are moving on their own since most people dont often notice what you're doing with your finger tips.

So, thats the full description. I hope you got as excited and curious to see it as I am to build it, because I am pretty F**king stoked.

More updates to come, but on that note, Peace!

Wednesday, August 17, 2011

Final Project - Interactive Table Top Slide Museum Installation

Hey Everyone, I know its really late, but heres a video of my final project for physical computing.

Most of the description is in the video, but the basic idea is that a museum visitor can walk up to the slide, drop a random object at the top and depending on how fast the object slides down and how much it weighs, an animation is displayed that shows how the energy is transfered from potential energy to kinetic energy and how much is lost to friction. Once its running better, students could use the slide as a way to perform their own investigations of friction and energy by sliding objects of different shape, size, weight and texture, or even putting different surfaces on the slide itself like sand paper, wax paper, grease (probably not), etc.

It still needs to be painted, polished and finished, but I think it's looking pretty sleek and minimalist which is what I was going for. Enjoy!

Sunday, August 7, 2011

Final Project Progress Slow Going

Im not going to lie. Im a little bit frustrated. I thought the hardware part of this project (arduino and code) was going to be easy compared to the software part (Max/MSP), but the code Im running into speed bumps everywhere. I wrote what I assumed was working code on the train the other day, but when I put all the components on the breadboard it failed miserably. Things were going wrong everywhere in the code. I basically had to scrap the whole sketch and start over.

Progress is ok so far, but once I started getting anywhere my lasers started dying out. I knew they were rated for 3.0 volts, but I hoped that I could get away with the 3.3 volt source on the arduino without decreasing their lifespan too much. Turns out even the extra 0.3 volts was enough to damage them after a 15-20 (cumulative, not consecutive) minutes of testing.

I snagged a 10 mega-ohm resistor from the ITP shelves that Im thinking I can wire in series with the laser to pull down the voltage, but Im a little hazy on the specifics. I got my bachelors degree in physics, but it was so theoretical I dont feel nearly as comfortable with all the circuitry as I do with the theory (I hope my old professors dont read this, its seriously embarrassing). I can recite ohms law and its applications with the best of them, but when it comes to actually selecting the right resistor to get the proper voltage Im really hesitant. The digital multimeter says that the laser has an internal resistance of just under 20 mega-ohms, so Im thinking if I add in 20 mega-ohms in series it should halve the 5v from the arduino and deliver a much safer 2.5 volts to the laser. Lets see how it goes.

Also, Max is being a real pain in the ass. I've got most of it working, but Im having a hard time making some floating point boxes respond automatically to values that are being fed to them. The thing is I need to have those number boxes update automatically if the values from the arduino are going to be interpreted and fed into the animation by Max. Going to ask Luke before class tomorrow.

Here's a pic of what IM working with, hardware-wise:

I taped the components to a plank of wood to make it easy to tweak the code without having to fiddle with the sensors and getting the alignment right. The force sensing resistor is on the left and the two lasers and light sensing resistors are next to it. There are a few status LEDs n the breadboard, but nothing really noteworthy.

This code doesnt seem like it should be so difficult. One problem I spotted so far is that I was using an if function where I should have been using a do (or a while) function. I want the program to be continually listening to the light sensors to tell when an object has passed by, I was using an IF command to listen and act accordingly, but I think it was moving on to the next part of the program before it actually was triggered. If I use a DO/WHILE command then Im can tell it to listen to the light sensor and do nothing else until it is triggered. Only then should it move to the next task in the code.

Im hoping I can get this running fairly satisfactory before going to sleep. Wish me luck.

Wednesday, July 20, 2011

Stupid Pet Trick

So, I finished my midterm, the "stupid pet trick", and well before 2 am to boot! With the exception of the LED face not working 100% like I wanted it to, it all came together relatively easily.

The "sleepy robot" is now the "peaceful robot", it just seems more fitting. The robot basically just displays a peaceful, happy face when left undisturbed, but when a light is shined in its face or the surface it is on is disturbed, its face changes to a slightly alarmed look and it shakes its head repeatedly. Then after a few seconds of inactivity it shuts off.

Note: the adjectives peaceful, happy and alarmed are used loosely. Its just a few LEDs for eyes and a mouth so Im not exactly on the cutting edge of artificial emotion.





The code for the robot is below. The alarmed look and head shake routine was really simple so I didnt even bother using any for loops to create the motion. I am, however, kind of proud of the initial calibration feature you can see it the void setup area. After you turn it on, the program waits for 3 seconds for you to close the back of the robot and step away so it can take a baseline reading of the ambient light without casting your own shadow over it, then it uses a specified value as a threshold to determine what constitutes "light in my face". I didnt put in a calibration step for the piezo because it wasnt as sensitive as the photoresistor so it wouldnt have been worth it. One cool feature to add later: an analog input to increase or decrease sensitivity of the robot on the fly.



#include //loads servo library

Servo neck; //creates servo object to control a servo

int onLedPin = 2;
int happyLedPin = 3;
int sadLedPin = 4;
int ldrPin = 0;
int ldrBaseline = 0; //sets ambient ldr value
int ldrThreshold = 100; //sets threshold for activation
int piezoPin = 1;
int piezo = 0; //stores piezo value
int inactivity = 5000; //time inactive before going to sleep
int neckDelay = 300; //delay between neck movements
int neckNeutral = 90; //sets neutral position for neck servo
int neckLeft = 45;
int neckRight = 135;


void setup() {
neck.attach(9); //attaches servo to pin 9
pinMode(onLedPin, OUTPUT);
pinMode(happyLedPin, OUTPUT);
pinMode(sadLedPin, OUTPUT);
delay(3000);
ldrBaseline = analogRead(ldrPin); //sets ambient ldr value
neck.write(neckNeutral); //sets head to neutral position

}

void loop() {
digitalWrite(sadLedPin, LOW); //makes sure sad face is off
digitalWrite(onLedPin, HIGH); //Sets sleepy state
digitalWrite(happyLedPin, HIGH);
piezo = analogRead(piezoPin); //reads piezo and assigns value to variable

Serial.println(piezo);

if((piezo > 100) || (analogRead(ldrPin) > ldrBaseline + ldrThreshold)){ //if ldr or piezo are activated, activate wake up sequence
delay(500);
digitalWrite(happyLedPin, LOW); //turns off happy face, sets neutral face
digitalWrite(sadLedPin, HIGH); //turns on sad face
neck.write(neckRight); //begins shaking of head to one direction
delay(neckDelay);
neck.write(neckLeft); //moves head to other direction
delay(neckDelay);
neck.write(neckRight);
delay(neckDelay);
neck.write(neckLeft);
delay(neckDelay);
neck.write(neckRight);
delay(neckDelay);
neck.write(neckLeft);
delay(neckDelay);
neck.write(neckRight);
delay(neckDelay);
neck.write(neckLeft);
delay(neckDelay);
neck.write(neckNeutral); //returns head to neutral position
delay(500);
delay(inactivity); //waits predetermined amount of time
} //returns to begining to fall asleep
}

Thursday, July 14, 2011

Calibration! Of course!

So, I was just rooting around the arduino website looking for ideas and cool new commands when I found this page: http://arduino.cc/en/Tutorial/Calibration


I totally could've used this in the last assignment with the glove. The flex sensor was a little tough to get consistent results because changing the bend slightly drastically affects the values it sends out. What I couldve done was calibrate the sensor when the sketch runs initially (or after a button press) then map those calibrated values to the sensor.

Now I know...

Tuesday, July 12, 2011

Homework for Class #2

Here it is, I wired together a circle of LEDs and had them illuminate in sequence to make it look like the light was travelling around the circle. Then I wired some analog inputs (one flex sensor and two pressure sensors) into a glove and had them control certain features of the lights. See below




With regards to me "dream project"... I dont know if it counts as a dream project since Im actually in the process of making it, but the project has been in my head for over a year now so Im gonna go ahead and say that it counts. By the way, major nerdiness is about to ensue, so try not to judge and if you must, save the wedgies till after class.

Last year I was inspired by my brother a big comic book nerd (and coincidentally a comic book artist) and was thinking of one of my favorite comic book characters and wondered why no one had attempted to make a realistic costume of Archangel, the big metal winged version of the X-man. So, I took it upon my self to be the first one to do it. However, the more I thought of it the more I wanted to trick out these 6-8 foot metal wings. I've started cutting the aluminum that they will be made out of but havent quite gotten to the fun stuff, the stuff that is actually making me list this project here as my ITP assignment: sensors and actuation.

The wings are going to be powered by this really amazing material I found called shape memory alloy. Its a very thin wire made of nickel and titanium that will actually contract in length much like our muscles. All you have to do is heat them electrically and you have muscle wire! You can kind of see it here: http://www.youtube.com/watch?v=3-coGuDTb-Y

As for the sensor side I was always fascinated by the fact that the character had such a strong connection with his wings. They would even drive him to do things with a mind of their own. So, I'd like to hack into a heart rate monitor and use the beating of my own heart to trigger the electrical pulses that will cause the muscles wires to make the wings flap. Aside from getting a brainwave sensor, I think using my actual heart rate to trigger the wing flapping is about as strong as a human connection can get.

I might add even more sensory inputs, but my goal is to have them ready to present at World Maker Faire this september. I'll try to bring in a sample of the muscle wire and a scale model I made of what the wings will look like.

Sensor Walk

Just around my house there are a lot of different sensors, but most of them are the typical on/off or trim pots. Light switchers are a simple switch, but the dimmers are like the ones potentiometers we used in class except linear rather than rotational. My roommate's antique stereo is complete with giant volume knobs that are even more similar to the rotational potentiometers. I guess that same stereo has a magnetic sensor that allows it to read the magnetic tape from old cassettes. Come to think along those same lines, the DVD player has a light sensor that it uses to pick up the laser light that bounces off the DVD itself. The camera that connects to the PS3 is a type of light sensor as well, albeit a more sophisticated one.

Moving on to the kitchen there are pushbutton switches on the microwave and the dishwasher and a nice little temperature sensor inside the oven. I would imagine the fridge has a temperature sensor as well, not to mention that tricky little switch that always manages to keep us entertained by flipping the light on and off when we open and close the door. The reptile tank in the corner has a different kind of temperature sensor that uses infrared light rather than heat thats conducted directly onto it. The capacitive touch sensor on my phone is pretty swell.

Hmm, I think that might be all the interesting ones.

Wednesday, July 6, 2011

Homework Assignment #1

Pendulum Switch: every time the pendulum makes contact with the metal brush at the bottom it triggers the LEDs to switch from one side to the other.



Success!!!

I fixed the bouncing issue! I read a tutorial online that helped me figure it out, but I had to modify their method because theirs wasn't actually debouncing, though it the method seemed to make sense. I used the following code:

void loop() {
    switchState=digitalRead(switchPin);
    delay(10);
    switchState2=digitalRead(switchPin);
   
    if(switchState != switchState2){
        if(switchState==1){
        ledState = 1 - ledState;
        } 
           
        if(ledState==0){
            digitalWrite(yellowLed,HIGH);
            digitalWrite(redLed,LOW);
        }else{
            digitalWrite(yellowLed,LOW);
            digitalWrite(redLed,HIGH);
        }
    }

So there are two variables for the state of the switch: switchState and switchState2. By storing both of them 10 milliseconds apart and comparing them, you can kind of ignore those erratic few milliseconds where the current is bouncing around from 0 to 1. The tutorial I found suggested comparing them to make sure they were the same (i.e. if(switchState==switchstate2)...), but that really didnt work very well, so I altered the if statement to allow the rest of the LED switching code to run only if the two switchState values were different. This results in the LED state changing only when the program finds a 10 millisecond period where it starts as one switchState and ends as another. Functionally, this means that the led switches from red to yellow or yellow to red (and stays that way until the next button press) only when you release the button after pressing it.

Now that I've proved the concept using just the push button on the breadboard I can try incorporating the pendulum switch I was thinking about before. I'll post a pic if I get a chance.

P.S. I hope the stuff I wrote makes sense, its kind of hard to describe code verbally. I'm not even sure if I can explain things 100% correctly.

Debouncing.

Argh. So, I've run into debouncing problems before but this one just isnt going away. Debouncing happens when you flip a crappy mechanical switch. In the brief instant that you perceive as a single button press, the current jumps from high to low (or 1 to 0) a bunch of times confusing your program since it doesnt know if its on or off. This means that when you try to press a button to switch an LED on and make it stay on after you release the button, you only get that outcome by chance since the program sees the button as switching back and forth multiple times.

Im working on making a pendulum that will swing past a metal brush, thus closing the circuit. I want to design it so that just the single contact with the metal brush causes it to flip from one LED to another, but the bouncing issue doesnt allow it to switch consistently. I'm sure I'm just being impatient and that Scott will cover it in class, but I like trying to figure it out on my own. Back to work now.

Tuesday, July 5, 2011

First Blog Post. Ever.

Just started classes at ITP @ NYU. Not as a full time student, unfortunately, but as a casual summer student. One of the first assignments was to create a blog and distribute a link to said blog to the rest of the class. Not something I would normally do on my own, but its probably a good career move to make one, so here it is.

I'll be taking two classes this summer, "intro to physical computing" and "live image processing and performance", both of which sound thoroughly amazing if not slightly intimidating. Will be posting more of my work soon.