Source Code. Projects. Nerd Stuff. Art Stuff.

Combination Lock


Posted on September 17th, by amoeboar in classes, pcomp. No Comments

Combination Lock

From the Lab Tutorial

Only a specific combination of pressed buttons will turn the light green. Otherwise, the light stays red.
The switches are in series with the LEDs, with a 39K pulldown resistor for each.

[gn_media url="http://www.youtube.com/watch?v=maI_OKkM6hE&feature=plcp" width="600" height="400"]

[gn_spoiler title="Combo Lock Source Code" open="0" style="1"]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void setup() {
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
}

void loop() {
  if (digitalRead(2) == HIGH && digitalRead(3) == HIGH
        && digitalRead(4) == LOW && digitalRead(5) == HIGH) {
      digitalWrite(7, HIGH);
      digitalWrite(6, LOW);
  } else {
      digitalWrite(7, LOW);
      digitalWrite(6, HIGH);
  }
}
[/gn_spoiler]




Leave a Reply