정보나눔

오픈소스하드웨어 프로젝트에 대한 다양한 정보를 나누는 공간입니다.

아두이노 키패드와 블루투스를 이용한 금고 제작 명령어인데 작동이 안됩니다.
훈빵이 | 2019-06-05

아두이노UNO , 16키패드, HC-06 사용하고있습니다.

 

#include

#include

#include

#include

 

 

int tru=0; //비밀번호가 맞는지 확인

int count=0;

char PW[4]={'1','4','5','5'}; //비밀번호

const byte ROWS =4;

const byte COLS =4;

byte rowPins[ROWS] = {11,10,9,8};

byte colPins[ROWS] = {7,6,5,4};

 

char keys[ROWS][COLS] = {

  {'1','2','3','A'},

  {'4','5','6','B'},

  {'7','8','9','C'},

  {'*','0','#','D'}

};

 

Servo myservo;

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int Tx=2;   

int Rx=3; 

SoftwareSerial mySerial(Tx, Rx); 

String AString="";

 

 

void setup() {

  Serial.begin(9600);

  myservo.attach(12);

 myservo.write(0); 

}

void Su()//성공했을시 모터를 돌려주며 성공메세지 보내기

{

      myservo.write(180);

      Serial.println("open the door");

}

 

void Fa()//실패했을시 모터를 돌려주며 실패메세지 보내기

{

     myservo.write(90);

     Serial.println("close the door");

          

}

 

void re()//비밀번호 입력중 #을 입력하면 입력중인 비밀번호 초기화

{

    tru=0;

    count=0;

    Serial.println("password reset");

}

 

void loop() {

 

  char key = keypad.getKey(); // 키패드 입력받는 부분

 

  if (key)

  {

      Serial.println(key);

      if(key==PW[count]) // 입력 비밀번호가 맞을시 count,tru++

  {

      count++;

      tru++;

  }

    else if(key!=PW[count]) //입력번호와 비밀번호가 틀릴시 count만 ++

  {

    count++;

  }

  if(key=='#')//초기화버튼

    re();//초기화 함수

 

    if(count==4)//count 개수가 비밀번호 개수와 같을 시

    {

      if(tru==4)

        Su();//성공함수

       else

        Fa();//실패함수 

 

       tru=0;

       count=0; 

    }

 while(mySerial.available())  

  {

    char myChar = (char)mySerial.read();  

    AString+=myChar;   

    delay(5);           

  }

  

  if(!AString.equals(""))  

  {

    Serial.println("input value: "+AString);

 

      if(AString=="on") 

      {

        myservo.write(150);  

        digitalWrite(8,HIGH);

        

      } else {

        myservo.write(0);

        digitalWrite(8,LOW);

      }

    AString="";

 

  }

 

  }

 

}

 

질문1)저희가 만든 명령어인데 키패드와 블루투스를 따로하면 작동이 되는데 같이 묶어서 지금의 명령어처럼 할려고하면 작동이 안됩니다.

혹시 명령어를 어떻게 수정해야 둘다 작동할까요 ㅠㅠ...

 

질문2)위에 질문에서 lcd까지 같이 할건데 어떻게 명령어를 짜야되는지 명령어 풀버전으로 작성해주시면 감사하겠습니다.

이전글   |    서보모터 및 LCD출력에 관한 질문입니다. 2019-06-05
다음글   |    아두이노 무드등 2019-06-06