PComp, Week 1: Lab, 1st Arduino Program

For my NYU ITP intro to physical computing class, I was required to prepare my breadboard and Arduino Uno together and then test a switch that would toggle off a red LED and then turn on a green LED as long as the switch was pressed. The red LED would remain on again after releasing the switch, with the green LED toggling off, so that both LEDs were at their original states.

I purchased a Gorillapod for my videos, so I could mount my Flip Mino on an adjustable tripod.  The two combine to look like some type of mini-droid.  But I need a better light on my desk to get less grainy video footage.  The camera on my phone has a flash; I don’t know if I want to spend the money on a fancier camera yet.  Not until I have some better skills or show at least some talent.

I had some problems understanding how you hook up both sides of the breadboard, not understanding that the blue and red lines, which I thought were hard-coded on the breadboard to be ground and power, respectively, were arbitrary assignments, and it only depended on how you wired up your board.  So while I followed a diagram exactly and got the lab to work, I didn’t understand the underlying principles until that point.

For the exercise, here are the documentation photos:

Arduino Uno and breadboard mounted together:

Arduino & breadboard, mounted

Testing red LED blinking with uploaded script:

Testing Blinking

Video:

Basic state for toggling red and green LEDs, red on/green off:

Arduino Switch Test

Switch pressed, green LED on, red LED off:

Arduino Switch Test

Video:

And finally, the code:

// Ben Turner
// NYU-ITP PComp, Scott Fitzgerald Thu 12:30-15:00
// Switch toggles red and green LEDs.

// Init states.
void setup() {
  pinMode(2, INPUT); // Set switch pin to input.
  pinMode(3, OUTPUT); // Set green LED pin to be output.
  pinMode(4, OUTPUT); // Set red LED pin to be output.
}

// Logic to control LED toggling.
void loop() {
  if (digitalRead(2) == HIGH) { // If switch pressed/closed, then:
    digitalWrite(3, HIGH); // Turn on green LED.
    digitalWrite(4, LOW); // Turn off red LED.
  }
  else { // If switch open/not pressed, then:
    digitalWrite(3, LOW); // Turn off green LED.
    digitalWrite(4, HIGH); // Turn on red LED.
  }
}
  • atif khair

    NIce work that are using in CCTV cameras .
    Jaycon