During Luncheon, Jugaadu was told by his father that they need to change their main locker. They replaced their main locker twice in the previous week as it got jammed. As all their important things are kept in a locker, Jugaadu's father asked Jugaadu to do something that can solve this. Can you help Jugaadu here?
Bag Items:
"
#include
Servo myservo;
int pos = 0;
int out1_pin=2;
int out2_pin=3;
int out3_pin=4;
int out4_pin=5;
int sum = 0;
int count = 0;
void setup() {
pinMode(out1_pin,INPUT);
pinMode(out2_pin,INPUT);
pinMode(out3_pin,INPUT);
pinMode(out4_pin,INPUT);
myservo.attach(9);
Serial.begin(9600);
}
void loop() {
delay(100);
if(digitalRead(out1_pin)){
digitalWrite(out1_pin,HIGH);
if(count == 3){
count++;
sum+=1;
Serial.println(sum);
sum = 0;
}
else{
count++;
sum+=1;
}
Serial.println(sum);
}else
{
digitalWrite(out1_pin,LOW);
}
if(digitalRead(out2_pin))
{digitalWrite(out2_pin,HIGH);
if(count == 3){
count++;
sum+=2;
Serial.println(sum);
sum = 0;
}
else{
count++;
sum+=2;
}
Serial.println(sum);
}else
{digitalWrite(out2_pin,LOW);
}
if(digitalRead(out3_pin))
{digitalWrite(out3_pin,HIGH);
if(count == 3){
count++;
sum+=3;
Serial.println(sum);
sum = 0;
}
else{
count++;
sum+=3;
}
Serial.println(sum);
}else
{digitalWrite(out3_pin,LOW);
}
if(digitalRead(out4_pin))
{digitalWrite(out4_pin,HIGH);
if(count == 3){
count++;
sum+=4;
Serial.println(sum);
sum = 0;
}
else{
count++;
sum+=4;
}
Serial.println(sum);
} else
{digitalWrite(out4_pin,LOW);
}
if(count==4){
count = 0;
if (sum==10 )
{
myservo.write(90);
}
else{
myservo.write(0);
}
}}