Advertisement
Sajib_Ahmed

Laser Tripwire

Dec 6th, 2021
953
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <Keypad.h>
  2.  
  3. #include <Keypad.h>
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10. #define Rec 0
  11. #define Laser 2
  12. #define Button 3
  13.  
  14. bool detection;
  15. short a=0;
  16. short code[4]={'6','6','6','6'};  
  17.                                  
  18.  
  19. const byte numRows= 4;          
  20. const byte numCols= 4;
  21.  
  22. char keymap[numRows][numCols]=    
  23.           {
  24.           {'1', '2', '3', 'A'},
  25.           {'4', '5', '6', 'B'},
  26.           {'7', '8', '9', 'C'},
  27.           {'*', '0', '#', 'D'}
  28.           };
  29.  
  30. byte rowPins[numRows] = {11,10,9,8};
  31. byte colPins[numCols]= {7,6,5,4};
  32.  
  33. Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
  34.  
  35. void setup() {
  36.  
  37.   pinMode(Laser, OUTPUT);
  38.   digitalWrite(Laser, HIGH);
  39.   delay(1000);
  40.   Serial.begin(9600);
  41. }
  42.  
  43. void loop() {
  44.  
  45.  short Detect = analogRead(Rec);                
  46. Serial.println(Detect);
  47. delay(1000);
  48.  
  49.     if(Detect >1000)
  50.         detection = true;
  51.  
  52.     if(detection==true)
  53.         {                                      
  54.          tone(13,1000);
  55.          delay(50);
  56.          tone(13,200);
  57.          delay(50);
  58.          char keypressed = myKeypad.getKey();
  59.          if (keypressed == '*')                  
  60.          Getpass();
  61.           }
  62.    
  63.      if(a==4){                                  
  64.          noTone(13);
  65.          a=0;                                  
  66.          detection=false;
  67.          }
  68.  
  69.  
  70. }
  71.  
  72. void Getpass(){              
  73.   tone(13,2000);              
  74.   for(short i=0 ; i<4 ; i++)
  75.             {
  76.              
  77.            char keypressed = myKeypad.waitForKey();
  78.            Serial.println(keypressed);
  79.               if (keypressed==code[i])  
  80.               a++;
  81.             }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement