Archive for September, 2011

Christmas lights

There’s satisfaction to be had in watching lights blink especially when those lights turn on by your command.

greenredlight

The code is relatively simple enough now that I’ve had the weekend to digest the meaning of all these pins and ports.

//double lights green light and red light
void setup(){
pinMode(3,INPUT); //SWITCH
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);
}
void loop(){
// if (digitalRead(3) == true) {
digitalWrite(5,true);
digitalWrite(4,false);
delay(500);
//}
// else {
digitalWrite(5, false);
digitalWrite(4, true);
delay (500);
// }
}

Using the same setup but different program and allowing the “if”s and “else” commands, this tells the chip to perfrom an action that will respond differently. In this case, when the switch is pressed the light will either be switched between red and green.

Feeling a little bold, I added more lights.

Trying something out

I wanted to get the switch to cascade the lights using the code below but it seemed that it wasn’t reacting to the switch and thus acting on switching the lights on it’s own. I’ll work on it some more.

//christmas lights
void setup(){
pinMode(9,INPUT); //SWITCH
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
// pinMode(8,OUTPUT);
}
void loop(){
if (digitalRead(9) == true && digitalRead(2) ==true){
digitalWrite (2, true);
delay(1000);
digitalWrite (3, true);
delay(1000);
digitalWrite (4, true);
delay(1000);
digitalWrite (5, true);
delay(1000);
digitalWrite (6, true);
delay(1000);
digitalWrite (7, true);
delay(1000);
// digitalWrite (8, true);
//  delay(1000);
//digitalWrite (8, false);
//delay(1000);
digitalWrite (7, false);
delay(1000);
digitalWrite (6, false);
delay(1000);
digitalWrite (5, false);
delay(1000);
digitalWrite (4, false);
delay(1000);
digitalWrite (3, false);
delay(1000);
digitalWrite (2, false);
}
}

Blink that light

We don’t give it much thought when we turn on a light bulb. For us it’s just a flick of the switch and that’s it! So it shouldn’t be too much trouble. Or could it?

I picked up the ITP PCOMP kit at the NYU Computer Store for around $93 including taxes. Inside it’s a box of chips, LEDs, wires, boards, cables and so on to supposedly help me make magic.

openbox

boxcontents

blankslate

First thing to setup is the breadboard (that white thing above) and the arduino board to the plastic mounting. You’ll need screws for the arduino but the breadboard has doublesided tape.

GET THAT THING TO LIGHT UP

No switches or anything just power up the LED using the microcontroller via USB power. Even if the kit comes with a 9V adapter, I think it’s safer using USB. You can’t accidentally burn out the circuits as the computer will automatically turn off the port if it detects a short.

firstwire

What’s wrong with this picture?

The board via the PWR lead as marked by the red wire and inserted a resistor and a green LED. Obviously this wouldn’t work since the breadboard isn’t powered and there’s no way that the digital lead is going to provide power to the board.

usbplugin

Let’s get some power.

The Arduino app is another matter entirely. Even though the user interface is similar to Processing, some of the syntax and commands are similar to a point.

I used the code in class and replaced the port numbers since I was using different ones than the ones in class. I learned the important part was to keep it simple and understand the logic of the board and it’s there!

BLINK THAT LIGHT

The trick to making the LED blink is all in code using the “delay(x)” .

SWITCH

The switch was more challenging than the earlier two.

toocomplicated

Now this needed a little more patience since I was adding another item which is the switch that needed a separate command for the microcontroller to command.

I ended up with this board.

onemoretime

And there you have it! A working switch. I’ll toy around with kit some more over the weekend but it’s great building something with your hands or in this case my hands and the computer.