This is the code for the ultrasonic sensor. The code has two classes (Pwm and Distance) and a main. In the class Pwm is the method called servoMovement. This method allows the servo to move back and forth in a small area so that it can recognize objects within an area. In the class Distance is the method called carDistance. With this method, we calculate the distance between the sensor and the object in front of the sensor, in centimeters. We use threads to make the two functions work at the same time.
This is the code for the ultrasonic sensor. The code has two classes (Pwm and Distance) and a main. In the class Pwm is the method called servoMovement. This method allows the servo to move back and forth in a small area so that it can recognize objects within an area. In the class Distance is the method called carDistance. With this method, we calculate the distance between the sensor and the object in front of the sensor, in centimeters. We use threads to make the two functions work at the same time.