Question: Please modify the following code so that it can calculate the rotation angle of the object and print the angle on the monitor of Arduino
Please modify the following code so that it can calculate the rotation angle of the object and print the angle on the monitor of Arduino IDE

#define trigPin1 13 // Trig for sensor 1 #define echoPin1 12 // Echo for sensor 1 #define trigPin2 11 // Trig for sensor 2 #define echoPin2 10 // Echo for sensor 2
float duration, distance, duration1, distance1, duration2, distance2; void setup() { Serial.begin (9600); //Serial communications at 9600 bps pinMode(trigPin1, OUTPUT); //Set the trigPin1 as output pinMode(echoPin1, INPUT); //Set the echoPin1 as input pinMode(trigPin2, OUTPUT); //Set the trigPin2 as output pinMode(echoPin2, INPUT); //Set the echoPin2 as input }
void loop() {
FindRange(trigPin1, echoPin1); duration1 = duration; distance1 = distance; FindRange(trigPin2, echoPin2); duration2 = duration; distance2 = distance; Serial.print(distance1); Serial.print(" cm "); Serial.print(distance2); Serial.println(" cm"); delay(100); }
void FindRange(int trigPin, int echoPin) { //Trigger the sensor by sending a HIGH pulse of 10 microseconds. But, before that, give a short LOW pulse to ensure youll get a clean HIGH pulse digitalWrite(trigPin, LOW); // Send out a Low trigger delayMicroseconds(2); // Wait 2 ms digitalWrite(trigPin, HIGH); // Send out a High trigger delayMicroseconds(10); // Wait 10 ms digitalWrite(trigPin, LOW); //Send out a Low trigger. duration = pulseIn(echoPin, HIGH); //Read the HIGH pulse whose duration is the time (in microseconds) from the sending of the ping to the reception of its echo off of an object. distance = (duration / 2) * 0.03435; //Sound speed = 0.03435cm/ct }
15 cm Rotation Angle? 15 cm Rotation Angle
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
