github/training-kit

Lock code

Akbar0333 opened this issue · 1 comments

#include <SoftwareSerial.h>
SoftwareSerial bt(0,2);
String inputs;

bool sw =1;
int s1=0;
int ss = 20;
#include <EEPROM.h>
#define Lock 4
#define relay1 5
#define relay2 6
#define relay3 7
#define relay4 8
#define relay5 9
#define relay6 10
#define relay7 11
#define relay8 12
#define dipar 13

long re1 = 0, re2 = 0, re3 = 0, re4 = 0, re5 = 0, re6 = 0,
re7 = 0, re8 = 0;
void setup() {
Serial.begin(9600);
bt.begin(9600);
pinMode(Lock, OUTPUT);
pinMode(dipar, OUTPUT);

pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(relay5, OUTPUT);
pinMode(relay6, OUTPUT);
pinMode(relay7, OUTPUT);
pinMode(relay8, OUTPUT);
re1 = EEPROM.read(1);
re2 = EEPROM.read(2);
re3 = EEPROM.read(2);
re4 = EEPROM.read(4);
re5 = EEPROM.read(5);
re6 = EEPROM.read(6);
re7 = EEPROM.read(7);
re8 = EEPROM.read(8);
digitalWrite(relay1, re1);
digitalWrite(relay2, re2);
digitalWrite(relay3, re3);
digitalWrite(relay4, re4);
digitalWrite(relay5, re5);
digitalWrite(relay6, re6);
digitalWrite(relay7, re7);
digitalWrite(relay8, re8);
}
void loop() {

if (sw== 1) {

if (ss>0) {ss = ss - 1;
  delay(500);
  
  Serial.println(ss);
  bt.println(ss);
  bt.println(";");
  delay(100);
  digitalWrite(dipar, HIGH);

if (ss == 0) {
 digitalWrite(dipar, LOW);
 ss=0;
 s1=0;
  while (Serial.available()==0) {}
}
}

}

if (s1==0) {

s1 = Serial.parseInt();

for (int l = 1; l <= s1; l += 1) {

delay(500);

  digitalWrite(Lock, HIGH);
  delay(500);
  digitalWrite(Lock, LOW);
  delay(500);

  if (s1==1) {
    ss = 20;
  }
  Serial.println(l);
}

}

while (Serial.available())

{

delay(10);
char c = Serial.read();



inputs += c;
if (inputs.length() > 0) {
  
ss=20;  


  Serial.println(inputs);

  if (inputs == "A") {

    digitalWrite(relay1, HIGH);
    EEPROM.write(1, 1);
  } else if (inputs == "B")

  {

    digitalWrite(relay2, HIGH);
    EEPROM.write(2, 1);

  } else if (inputs == "C") {

    digitalWrite(relay3, HIGH);
    EEPROM.write(3, 1);
  }

  else if (inputs == "D") {

    digitalWrite(relay4, HIGH);
    EEPROM.write(4, 1);
  }

  else if (inputs == "E") {

    digitalWrite(relay5, HIGH);
    EEPROM.write(5, 1);
  }

  else if (inputs == "F") {
    re6 = ~re6;
    digitalWrite(relay6, HIGH);
    EEPROM.write(6, 1);
  }

  else if (inputs == "G") {

    digitalWrite(relay7, HIGH);
    EEPROM.write(7, 1);
  }

  else if (inputs == "H") {

    digitalWrite(relay8, HIGH);
    EEPROM.write(8, 1);
  } else if (inputs == "a") {

    digitalWrite(relay1, LOW);
    EEPROM.write(1, 0);
  } else if (inputs == "b")

  {

    digitalWrite(relay2, LOW);
    EEPROM.write(2, 0);

  } else if (inputs == "c") {

    digitalWrite(relay3, LOW);
    EEPROM.write(3, 0);
  }

  else if (inputs == "d") {

    digitalWrite(relay4, LOW);
    EEPROM.write(4, 0);
  }

  else if (inputs == "e") {

    digitalWrite(relay5, LOW);
    EEPROM.write(5, 0);
  }

  else if (inputs == "f") {
    re6 = ~re6;
    digitalWrite(relay6, LOW);
    EEPROM.write(6, 0);
  }

  else if (inputs == "g") {

    digitalWrite(relay7, LOW);
    EEPROM.write(7, 0);
  }

  else if (inputs == "h") {

    digitalWrite(relay8, LOW);
    EEPROM.write(8, 0);
  }

  else if (inputs == "W") {
    digitalWrite(relay1, 1);
    EEPROM.write(1, 1);

    digitalWrite(relay2, 1);
    EEPROM.write(2, 1);

    digitalWrite(relay3, 1);
    EEPROM.write(3, 1);

    digitalWrite(relay4, 1);
    EEPROM.write(4, 1);

    digitalWrite(relay5, 1);
    EEPROM.write(5, 1);

    digitalWrite(relay6, 1);
    EEPROM.write(6, 1);

    digitalWrite(relay7, 1);
    EEPROM.write(7, 1);

    digitalWrite(relay8, 1);
    EEPROM.write(8, 1);

  }

  else if (inputs == "w") {

    digitalWrite(relay1, 0);
    EEPROM.write(1, 0);

    digitalWrite(relay2, 0);
    EEPROM.write(2, 0);

    digitalWrite(relay3, 0);
    EEPROM.write(3, 0);

    digitalWrite(relay4, 0);
    EEPROM.write(4, 0);

    digitalWrite(relay5, 0);
    EEPROM.write(5, 0);

    digitalWrite(relay6, 0);
    EEPROM.write(6, 0);

    digitalWrite(relay7, 0);
    EEPROM.write(7, 0);

    digitalWrite(relay8, 0);
    EEPROM.write(8, 0);
  }

  for (int l = 1; l <= 3; l++) {
    digitalWrite(dipar, HIGH);
    delay(100);
    digitalWrite(dipar, LOW);
    delay(100);
    inputs = "";
  }
}

}
}

Bluetooth