From 30c8e4b074345459e0ee51bbb3d0543383b28b1f Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sat, 24 Nov 2018 16:58:35 +0000 Subject: [PATCH] Working with buzzer --- SensorsArd/SensorsArd.ino | 47 ++++++++++++++++++--------------------- main.py | 8 +++---- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/SensorsArd/SensorsArd.ino b/SensorsArd/SensorsArd.ino index ff703bd..e89cd15 100644 --- a/SensorsArd/SensorsArd.ino +++ b/SensorsArd/SensorsArd.ino @@ -44,25 +44,27 @@ void loop() { if(digitalRead(ProxSensor) == LOW ) IROK = true; else IROK = false; - + char pi = 'N'; + if (Serial.available() > 0) { pi = Serial.read(); } + delay(500); + Serial.println(pi); + Serial.println(IROK); + Serial.println(UltraOK); //if (IROK && UltraOK) Serial.println("A"); - if (IROK && UltraOK && Serial.available() > 0 ){ - if (Serial.read() == 'O') { + if (IROK && UltraOK && pi == 'o'){ + //if (Serial.read() == 'o') { digitalWrite(relayPin, HIGH); - playBuzzer(2,false); - delay(5000); + playBuzzer(300,true); + delay(7000); digitalWrite(relayPin, LOW); IROK = false; UltraOK = false; + pi = 'N'; serialFlush(); - - } + //} } IROK = false; UltraOK = false; - - //Read from Pi here - } void serialFlush(){ @@ -72,21 +74,14 @@ void serialFlush(){ } void playBuzzer(int time, boolean ok){ - if (ok) { - tone(buzzerPin, 1000); - delay(time/3); - noTone(buzzerPin); - delay(time/5); - tone(buzzerPin,1000); - delay(time/3); - noTone(buzzerPin); - } - else { - tone(buzzerPin, 1000); - delay(time); - noTone(buzzerPin); - - } + tone(buzzerPin, 3000); + delay(time/2); + noTone(buzzerPin); + delay(100); + tone(buzzerPin, 3000); + delay(time/2); + noTone(buzzerPin); + } @@ -94,3 +89,5 @@ void playBuzzer(int time, boolean ok){ + + diff --git a/main.py b/main.py index 5bb9acd..b2d0873 100644 --- a/main.py +++ b/main.py @@ -65,7 +65,7 @@ def start( camera, face_cascade): roi_gray = gray[y:y+h, x:x+w] roi_color = img[y:y+h, x:x+w] person = recognize(roi_gray) - if person == 'Hesham' or person == 'Saeed': + if person == 'Hesham' or person == 'Saeed':#Change to if 'unknown' elif openShifter OpenShifter() print('Sending to Arduino!') cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2) @@ -89,17 +89,17 @@ def recognize(image): face_recognizer.load('faces/m') img = image.copy() label= face_recognizer.predict(img) - print(label) if label[1] > 120: return 'unknown' else: + print(str(label) + ' >>'+names[label[0]]) return names[label[0]] def OpenShifter(): try: ser = serial.Serial('/dev/ttyUSB0',9600) - #ser.open() - ser.write('O') + ser.open() + ser.write('o') ser.close() except Exception as ex: print('[ Error ] Can not connect to Arduino at /dev/ttyUSB1 ..')