[ arduino ] 키패드를 사용해서 비밀번호 확인하기 > arduino

본문 바로가기

사이트 내 전체검색

arduino

[ arduino ] 키패드를 사용해서 비밀번호 확인하기

작성일 21-01-26 12:48

페이지 정보

작성자 웹지기 조회 7,618회 댓글 0건

본문

비밀번호가 맞으면 시리얼 모니터에 OK가 뜨고 

비밀번호가 맞지 않으면 시리얼 모니터에 NO가 뜨게하는 프로그램

 

#include <Keypad.h>


const byte ROWS = 4; //four rows

const byte COLS = 3; //three columns

char keys[ROWS][COLS] = {

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

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

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

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

};

byte rowPins[ROWS] = {7, 2, 3, 5}; //connect to the row pinouts of the keypad

byte colPins[COLS] = {6, 8, 4}; //connect to the column pinouts of the keypad


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


void setup() {

  Serial.begin(9600);

  pinMode(11, OUTPUT);

  pinMode(12, OUTPUT);

  pinMode(13, OUTPUT);

}

String a = "3333";

String b = "";

boolean state = false;

void loop() {

  char key = keypad.getKey();


  if (key) {

    Serial.print(key);


    if (key == '*') {

      if (b == a) {

        //Serial.print(b);

        Serial.println("OK");

        digitalWrite(11, HIGH);

        digitalWrite(12, HIGH);

        digitalWrite(13, HIGH);

        b = "";

      } else {

        //Serial.print(b);

        Serial.println("NO");

        b = "";

      }

    } else {

      b += key;

    }

  }

}

 

KakaoTalk_20210126_114919198.png


추천0

비추천 0

댓글목록

등록된 댓글이 없습니다.

전체 25건 1 페이지

이미지 목록

게시물 검색
Copyright © 즐거운 코딩 생활 ( funyphp ). All rights reserved.
PC 버전으로 보기