/*
* Programming: Security Box Following Among Us - Electric Wiring Task
* Author: Gold Screw
* Email: goldscrewdiy@gmail.com
* Date: Sat, 28 Nov 2020
*/
#include <Servo.h>
// LEFT SIDE LED
const int L_WhiteLED = 2;
const int L_RedLED = 3;
const int L_YellowLED = 4;
const int L_GreenLED = 5;
// RIGHT SIDE LED
const int R_WhiteLED = 6;
const int R_RedLED = 9;
const int R_YellowLED = 7;
const int R_GreenLED = 8;
const int LockedStatusLED = 11;
const int OpenedStatusLED = 12;
// Servo
Servo locker;
void setup() {
// Serial connection with baudrate 960
Serial.begin(9600);
// PinMode Output
pinMode(L_WhiteLED, OUTPUT);
pinMode(L_RedLED, OUTPUT);
pinMode(L_YellowLED, OUTPUT);
pinMode(L_GreenLED, OUTPUT);
pinMode(LockedStatusLED, OUTPUT);
pinMode(OpenedStatusLED, OUTPUT);
// PinMode Input
pinMode(R_WhiteLED, INPUT);
pinMode(R_RedLED, INPUT);
pinMode(R_YellowLED, INPUT);
pinMode(R_GreenLED, INPUT);
//======== SERVO MOTOR =======//
locker.attach(13);
locker.write(0);
//Turn On Left Side LED
digitalWrite(L_WhiteLED, HIGH);
digitalWrite(L_RedLED, HIGH);
digitalWrite(L_YellowLED, HIGH);
digitalWrite(L_GreenLED, HIGH);
// Set LED Locked status
digitalWrite(LockedStatusLED, HIGH);
digitalWrite(OpenedStatusLED, LOW);
}
void loop() {
// Check all wiring
if((digitalRead(R_WhiteLED) == 1) && (digitalRead(R_RedLED) == 1) && (digitalRead(R_YellowLED) == 1) && (digitalRead(R_GreenLED) == 1))
{
// Unlocked successfully
Serial.println("===SUCCESS===");
digitalWrite(LockedStatusLED, LOW);
digitalWrite(OpenedStatusLED, HIGH);
locker.write(90);
} else {
// Unclocked failed
Serial.println("===FAILED===");
digitalWrite(LockedStatusLED, HIGH);
digitalWrite(OpenedStatusLED, LOW);
locker.write(0);
}
}
Comments