splitting into functions
This commit is contained in:
		
							parent
							
								
									e6de56c167
								
							
						
					
					
						commit
						48dbd127a2
					
				
							
								
								
									
										17
									
								
								.project
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								.project
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="UTF-8"?>
 | 
				
			||||||
 | 
					<projectDescription>
 | 
				
			||||||
 | 
						<name>FaceRecognition-python</name>
 | 
				
			||||||
 | 
						<comment></comment>
 | 
				
			||||||
 | 
						<projects>
 | 
				
			||||||
 | 
						</projects>
 | 
				
			||||||
 | 
						<buildSpec>
 | 
				
			||||||
 | 
							<buildCommand>
 | 
				
			||||||
 | 
								<name>org.python.pydev.PyDevBuilder</name>
 | 
				
			||||||
 | 
								<arguments>
 | 
				
			||||||
 | 
								</arguments>
 | 
				
			||||||
 | 
							</buildCommand>
 | 
				
			||||||
 | 
						</buildSpec>
 | 
				
			||||||
 | 
						<natures>
 | 
				
			||||||
 | 
							<nature>org.python.pydev.pythonNature</nature>
 | 
				
			||||||
 | 
						</natures>
 | 
				
			||||||
 | 
					</projectDescription>
 | 
				
			||||||
							
								
								
									
										5
									
								
								.pydevproject
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								.pydevproject
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="UTF-8" standalone="no"?>
 | 
				
			||||||
 | 
					<?eclipse-pydev version="1.0"?><pydev_project>
 | 
				
			||||||
 | 
					<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
 | 
				
			||||||
 | 
					<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
 | 
				
			||||||
 | 
					</pydev_project>
 | 
				
			||||||
@ -7,7 +7,9 @@ const int buzzerPin = 3;
 | 
				
			|||||||
int inputVal = 0;
 | 
					int inputVal = 0;
 | 
				
			||||||
long duration;
 | 
					long duration;
 | 
				
			||||||
int distance;
 | 
					int distance;
 | 
				
			||||||
char piInput = 'N';
 | 
					boolean IROK = false;
 | 
				
			||||||
 | 
					boolean UltraOK = false;
 | 
				
			||||||
 | 
					char pi = 'N';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void setup() {
 | 
					void setup() {
 | 
				
			||||||
  pinMode(trigPin, OUTPUT);
 | 
					  pinMode(trigPin, OUTPUT);
 | 
				
			||||||
@ -15,7 +17,7 @@ void setup() {
 | 
				
			|||||||
  pinMode(LED_BUILTIN, OUTPUT);
 | 
					  pinMode(LED_BUILTIN, OUTPUT);
 | 
				
			||||||
  pinMode(relayPin, OUTPUT);
 | 
					  pinMode(relayPin, OUTPUT);
 | 
				
			||||||
  pinMode(buzzerPin, OUTPUT);
 | 
					  pinMode(buzzerPin, OUTPUT);
 | 
				
			||||||
  pinMode(ProxSensor,INPUT);
 | 
					  pinMode(ProxSensor, INPUT);
 | 
				
			||||||
  digitalWrite(buzzerPin, LOW);
 | 
					  digitalWrite(buzzerPin, LOW);
 | 
				
			||||||
  digitalWrite(relayPin, LOW);
 | 
					  digitalWrite(relayPin, LOW);
 | 
				
			||||||
  Serial.begin(9600);
 | 
					  Serial.begin(9600);
 | 
				
			||||||
@ -24,9 +26,63 @@ void setup() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void loop() {
 | 
					void loop() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  IROK = false;
 | 
				
			||||||
 | 
					  UltraOK = false;
 | 
				
			||||||
 | 
					  pi = 'N';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  boolean IROK = false;
 | 
					  distance = readDistance();
 | 
				
			||||||
  boolean UltraOK = false;
 | 
					  if (distance < 70) UltraOK = true;
 | 
				
			||||||
 | 
					  else UltraOK = false;
 | 
				
			||||||
 | 
					  if (digitalRead(ProxSensor) == LOW ) IROK = true;
 | 
				
			||||||
 | 
					  else  IROK = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  if (Serial.available() > 0) {
 | 
				
			||||||
 | 
					    pi = Serial.read();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  delay(500);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Serial.println(pi);
 | 
				
			||||||
 | 
					  Serial.println(IROK);
 | 
				
			||||||
 | 
					  Serial.println(UltraOK);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (IROK && UltraOK && pi == 'o') {
 | 
				
			||||||
 | 
					    openShifter();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  IROK = false;
 | 
				
			||||||
 | 
					  UltraOK = false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void openShifter() {
 | 
				
			||||||
 | 
					  digitalWrite(relayPin, HIGH);
 | 
				
			||||||
 | 
					  playBuzzer(300, true);
 | 
				
			||||||
 | 
					  delay(7000);
 | 
				
			||||||
 | 
					  digitalWrite(relayPin, LOW);
 | 
				
			||||||
 | 
					  IROK = false;
 | 
				
			||||||
 | 
					  UltraOK = false;
 | 
				
			||||||
 | 
					  pi = 'N';
 | 
				
			||||||
 | 
					  serialFlush();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void serialFlush() {
 | 
				
			||||||
 | 
					  while (Serial.available() > 0) {
 | 
				
			||||||
 | 
					    char t = Serial.read();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void playBuzzer(int time, boolean ok) {
 | 
				
			||||||
 | 
					  tone(buzzerPin, 3000);
 | 
				
			||||||
 | 
					  delay(time / 2);
 | 
				
			||||||
 | 
					  noTone(buzzerPin);
 | 
				
			||||||
 | 
					  delay(100);
 | 
				
			||||||
 | 
					  tone(buzzerPin, 3000);
 | 
				
			||||||
 | 
					  delay(time / 2);
 | 
				
			||||||
 | 
					  noTone(buzzerPin);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int readDistance() {
 | 
				
			||||||
  // Clears the trigPin
 | 
					  // Clears the trigPin
 | 
				
			||||||
  digitalWrite(trigPin, LOW);
 | 
					  digitalWrite(trigPin, LOW);
 | 
				
			||||||
  delayMicroseconds(2);
 | 
					  delayMicroseconds(2);
 | 
				
			||||||
@ -37,56 +93,6 @@ void loop() {
 | 
				
			|||||||
  // Reads the echoPin, returns the sound wave travel time in microseconds
 | 
					  // Reads the echoPin, returns the sound wave travel time in microseconds
 | 
				
			||||||
  duration = pulseIn(echoPin, HIGH);
 | 
					  duration = pulseIn(echoPin, HIGH);
 | 
				
			||||||
  // Calculating the distance
 | 
					  // Calculating the distance
 | 
				
			||||||
  distance= duration*0.034/2;
 | 
					  return duration * 0.034 / 2;
 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (distance < 70) UltraOK = true;  
 | 
					 | 
				
			||||||
  else UltraOK = false;
 | 
					 | 
				
			||||||
  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 && pi == 'o'){
 | 
					 | 
				
			||||||
    //if (Serial.read() == 'o') {
 | 
					 | 
				
			||||||
      digitalWrite(relayPin, HIGH);
 | 
					 | 
				
			||||||
      playBuzzer(300,true);
 | 
					 | 
				
			||||||
      delay(4000);
 | 
					 | 
				
			||||||
      digitalWrite(relayPin, LOW);
 | 
					 | 
				
			||||||
      IROK = false;
 | 
					 | 
				
			||||||
      UltraOK = false;
 | 
					 | 
				
			||||||
      pi = 'N';
 | 
					 | 
				
			||||||
      serialFlush();
 | 
					 | 
				
			||||||
    //}
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  IROK = false;
 | 
					 | 
				
			||||||
  UltraOK = false;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void serialFlush(){
 | 
					 | 
				
			||||||
  while(Serial.available() > 0) {
 | 
					 | 
				
			||||||
    char t = Serial.read();
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void playBuzzer(int time, boolean ok){
 | 
					 | 
				
			||||||
  tone(buzzerPin, 3000);
 | 
					 | 
				
			||||||
  delay(time/2);
 | 
					 | 
				
			||||||
  noTone(buzzerPin);
 | 
					 | 
				
			||||||
  delay(100);
 | 
					 | 
				
			||||||
  tone(buzzerPin, 3000);
 | 
					 | 
				
			||||||
  delay(time/2);
 | 
					 | 
				
			||||||
  noTone(buzzerPin);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user