Advertisement
CHU2

KnockbutnotPattern

Oct 24th, 2024
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 3.31 KB | Source Code | 0 0
  1. int soundSens = 2;
  2. int opButt = 3;
  3. int setButt = 4;
  4.  
  5. String millisOp[10] = {"0", "0", "0", "0", "0", "0", "0", "0", "0", "0"};
  6. String tempo[8] = {"400", "400", "0", "0", "0", "0", "0", "0"}; // Test value
  7. int countOp = 0;
  8. int count = 0;
  9. int countSave = 2;  // Test value
  10. int opState01 = 0;
  11. int opLastState01 = 0;
  12. boolean lockState01 = true;
  13. int opState02 = 0;
  14. int opLastState02 = 0;
  15. boolean lockState02 = true;
  16.  
  17. void iCheck();
  18. void tempoCheck();
  19.  
  20. void setup() {
  21.   for (int i = 2; i <= 4; i++) {
  22.     pinMode(i, INPUT);
  23.   }
  24.  
  25.   Serial.begin(9600);
  26. }
  27.  
  28. void loop() {
  29.   int sens = digitalRead(soundSens);
  30.   opState01 = digitalRead(opButt);
  31.   opState02 = digitalRead(setButt);
  32.  
  33.   // Toggle lock state on button press
  34.   if (opState01 != opLastState01) {
  35.     if (opState01 == LOW) { // Button pressed
  36.       lockState01 = !lockState01; // Toggle the lock state
  37.     }
  38.     opLastState01 = opState01;
  39.   }
  40.  
  41.   if (!lockState01) { // Check if lock is engaged
  42.     if (sens == HIGH) {
  43.       countOp++;
  44.  
  45.       delay(100);
  46.     }
  47.   }
  48.   if (lockState01) {
  49.     iCheckbutnotPattern();
  50.   }
  51.  
  52.   // Toggle lock state on button press
  53.   if (opState02 != opLastState02) {
  54.     if (opState02 == LOW) { // Button pressed
  55.       lockState02 = !lockState02; // Toggle the lock state
  56.     }
  57.     opLastState02 = opState02;
  58.   }
  59.  
  60.   if (lockState02) { // Check if lock is engaged
  61.     if (sens == HIGH) {
  62.       count++;
  63.  
  64.       delay(100);
  65.     }
  66.   }
  67.   if (!lockState02) {
  68.     if (count != 0) {
  69.       countSave = count;  // countCheck
  70.      
  71.       count = 0;
  72.     }
  73.   }
  74. }
  75.  
  76. void iCheck() {
  77.   if (millisOp[1].toInt() >= millisOp[0].toInt() + tempo[0].toInt() && millisOp[1].toInt() <= millisOp[2].toInt() - tempo[0].toInt() + 400) {
  78.     if (millisOp[2].toInt() >= millisOp[1].toInt() + tempo[1].toInt() && millisOp[2].toInt() <= millisOp[3].toInt() - tempo[1].toInt() + 400) {
  79.       if (millisOp[3].toInt() >= millisOp[2].toInt() + tempo[2].toInt() && millisOp[3].toInt() <= millisOp[4].toInt() - tempo[2].toInt() + 400) {
  80.         if (millisOp[4].toInt() >= millisOp[3].toInt() + tempo[3].toInt() && millisOp[4].toInt() <= millisOp[5].toInt() - tempo[3].toInt() + 400) {
  81.           if (millisOp[5].toInt() >= millisOp[4].toInt() + tempo[4].toInt() && millisOp[5].toInt() <= millisOp[6].toInt() - tempo[4].toInt() + 400) {
  82.             if (millisOp[6].toInt() >= millisOp[5].toInt() + tempo[5].toInt() && millisOp[6].toInt() <= millisOp[7].toInt() - tempo[5].toInt() + 400) {
  83.               if (millisOp[7].toInt() >= millisOp[6].toInt() + tempo[6].toInt() && millisOp[7].toInt() <= millisOp[8].toInt() - tempo[6].toInt() + 400) {
  84.                 if (millisOp[8].toInt() >= millisOp[7].toInt() + tempo[7].toInt() && millisOp[8].toInt() <= millisOp[9].toInt() - tempo[7].toInt() + 400) {
  85.                   Serial.println("UNLOCK YEHEY!!"); // ig kakadi an lock motor chuchu
  86.                 }
  87.               }
  88.             }
  89.           }
  90.         }
  91.       }
  92.     }
  93.   }
  94.   else {
  95.     Serial.println("LOCKED NOO!!");
  96.   }
  97. }
  98.  
  99. void iCheckbutnotPattern() {
  100.   if (countOp == countSave) {
  101.     Serial.println("UNLOCK YEHEY!!"); // ig kakadi an lock motor chuchu
  102.   }
  103.   else {
  104.     Serial.println("LOCKED NOO!!");
  105.   }
  106. }
  107.  
  108. void tempoCheck() {
  109.   for (int i = 1; i <= 8; i++) {
  110.     tempo[i - 1] = (millisOp[i].toInt() - millisOp[i - 1].toInt()) - 200;
  111.   }
  112. }
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement