diff --git a/Radar.ino b/Radar.ino index 57846c8..ba08a80 100644 --- a/Radar.ino +++ b/Radar.ino @@ -7,6 +7,9 @@ const int trigPin = 7; const int echoPin = 8; +int servoType = 180 //360 for continuous servo +int servoSpeed = 130 //Servo speed in RPM + long duration; int distance; Servo myServo; @@ -16,32 +19,52 @@ void setup() { pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); Serial.begin(9600); - myServo.attach(9); + myServo.attach(9); + + myServo.write(90); //stop } void loop() { for(int i=15;i<=165;i++){ - myServo.write(i); - delay(30); - distance = calculateDistance(); - - Serial.print(i); - Serial.print(","); - Serial.print(distance); - Serial.print("."); + if(servoType == 180) + { + myServo.write(i); + } + else if(servoType == 360) + { + myServo.write(180); //Rotate CW + delay(((1/360)/servoSpeed)*60000); + myServo.write(90); //stop + } + delay(30); + distance = calculateDistance(); + + Serial.print(i); + Serial.print(","); + Serial.print(distance); + Serial.print("."); } for(int i=165;i>15;i--){ - myServo.write(i); - delay(30); - - distance = calculateDistance(); - - Serial.print(i); - Serial.print(","); - Serial.print(distance); - Serial.print("."); + if(servoType == 180) + { + myServo.write(i); + } + else if(servoType == 360) + { + myServo.write(0); //Rotate CCW + delay(((1/360)/servoSpeed)*60000); + myServo.write(90); //stop + } + delay(30); + + distance = calculateDistance(); + + Serial.print(i); + Serial.print(","); + Serial.print(distance); + Serial.print("."); } }