Last active
May 9, 2018 16:36
-
-
Save Dack000/4f42ca869c5c1577527100a9165033d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Ultrasonic.h> | |
Ultrasonic ultrasonic(7); | |
void setup() | |
{ | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
Serial.println(ultrasonic.distanceRead()); | |
float DistanceInCmeters = (ultrasonic.distanceRead()); | |
Serial.println(DistanceInCmeters); | |
int angle = static_cast<int>(getServoAngle(DistanceInCmeters)); | |
Serial.println(angle); | |
delay(60); | |
} | |
float getAngle(float distance) { | |
return 13.74312 + (51.59477 - 13.74312)/(1 + pow(distance/142.6213, 4.404875)); | |
} | |
float getServoAngle(float distance) { | |
return getAngle(distance) * (1.8); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment