Open Sessame

I created a mini wall that turns 90 degrees only when both of the switches are pressed. This is a prototype for a piece that I am thinking of expending on for my Capstone project.

Here is the schematic:

servo_swipe

The code itself is very simple. When both switches are pressed, it turns 90 degrees, revealing the other side of the wall, and when it is not, it returns back to the original position, blocking the view of the other side.

#include <Servo.h> 
 
Servo myservo;
 
int pos = 90;
int val;
int switch1 = 2;
int switch2 = 4;
 
void setup() 
{ 
  myservo.attach(9);  
  myservo.write(pos);
  pinMode(switch1, INPUT);
  pinMode(switch2, INPUT);
} 
 
void loop() 
{ 
    if(digitalRead(switch1) == LOW && digitalRead(switch2) == LOW){
      myservo.write(pos-90);
    }
    if(digitalRead(switch1) == HIGH && digitalRead(switch2) == HIGH){
      myservo.write(pos);
    }
}

Leave a Reply