Working with buzzer

This commit is contained in:
HeshamTB 2018-11-24 16:58:35 +00:00
parent 03490f1a25
commit 30c8e4b074
2 changed files with 26 additions and 29 deletions

View File

@ -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){

View File

@ -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 ..')