Lina Maria Giraldo's Blog

Multimedia Artist and ITP Student

Digital Input (a switch), Digital Outputs (LEDs)-Week 1

with one comment


Final Frog Switch LEDs Physical Computing from Lina Giraldo on Vimeo

 

 

This is the video documentation of the Digital Input and Output (a switch and LED’s)


Switch with two LEDs inside of the frog from Lina Giraldo on Vimeo.

 

 

 

 

 

Video Documentation Digital Input (a switch and Digital Output LED’s red and Yellow)


Week 1 Lab 1 from Lina Giraldo on Vimeo.

Code:

// declare variables:

int switchPin = 2;      //  digital input pin for a switch

int yellowLedPin = 3;   //  digital output pin for an LED

int redLedPin = 4;      //  digital output pin for an LED

int switchState = 0;    // the state of the switch

 

void setup() {

  pinMode(switchPin, INPUT);       // set the switch pin to be an input

  pinMode(yellowLedPin, OUTPUT);   // set the yellow LED pin to be an output

  pinMode(redLedPin, OUTPUT);      // set the red LED pin to be an output

}

 

void loop() {

  // read the switch input:

  switchState = digitalRead(switchPin);

 

  if (switchState == 1) {

    // if the switch is closed:

    digitalWrite(yellowLedPin, HIGH);    // turn on the yellow LED

    digitalWrite(redLedPin, LOW);       // turn off the red LED

  } 

  else {

    // if the switch is open:

    digitalWrite(yellowLedPin, LOW);   // turn off the yellow LED

    digitalWrite(redLedPin, HIGH);     // turn on the red LED

  }

}

Written by admin

January 26th, 2009 at 12:19 pm

One Response to 'Digital Input (a switch), Digital Outputs (LEDs)-Week 1'

Subscribe to comments with RSS or TrackBack to 'Digital Input (a switch), Digital Outputs (LEDs)-Week 1'.

  1. excellent images. and you used a multimeter with the 7805!

    scott

    26 Jan 09 at 11:40 pm

Leave a Reply

You must be logged in to post a comment.