Tuesday 29 April 2008

Week 3 - Switch



During this workshop we were instructed to create a circuit which and LED would be controlled by a switch. We were given a handout which gave some basic information on how switches work and how they are used. We were also introduced to resistors and also given brief information on their purpose.
Here are images of my completed circuit:

And here is a video of my working switch within the circuit:

On the worksheet we were provided with the code in order to make this circuit work:
int ledPin = 13;
int inPin = 2;
int val = 0;

void setup() {
  pinMode (ledPin, OUTPUT);
  pinMode (inPin, INPUT);
}

void loop () {
  val = digitalRead(inPin);
  if (val ==HIGH) {
  digitalWrite(ledPin, LOW);
  } else {
    digitalWrite (ledPin, HIGH);
  }
}

No comments: