Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Keypad.h>
- #include <Keypad.h>
- #define Rec 0
- #define Laser 2
- #define Button 3
- bool detection;
- short a=0;
- short code[4]={'6','6','6','6'};
- const byte numRows= 4;
- const byte numCols= 4;
- char keymap[numRows][numCols]=
- {
- {'1', '2', '3', 'A'},
- {'4', '5', '6', 'B'},
- {'7', '8', '9', 'C'},
- {'*', '0', '#', 'D'}
- };
- byte rowPins[numRows] = {11,10,9,8};
- byte colPins[numCols]= {7,6,5,4};
- Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
- void setup() {
- pinMode(Laser, OUTPUT);
- digitalWrite(Laser, HIGH);
- delay(1000);
- Serial.begin(9600);
- }
- void loop() {
- short Detect = analogRead(Rec);
- Serial.println(Detect);
- delay(1000);
- if(Detect >1000)
- detection = true;
- if(detection==true)
- {
- tone(13,1000);
- delay(50);
- tone(13,200);
- delay(50);
- char keypressed = myKeypad.getKey();
- if (keypressed == '*')
- Getpass();
- }
- if(a==4){
- noTone(13);
- a=0;
- detection=false;
- }
- }
- void Getpass(){
- tone(13,2000);
- for(short i=0 ; i<4 ; i++)
- {
- char keypressed = myKeypad.waitForKey();
- Serial.println(keypressed);
- if (keypressed==code[i])
- a++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement