// include the library code:
#include <LiquidCrystal.h>
#include <Servo.h>
// initialize the library with the numbers of the interface pins
////const int buttonPin = 28;
////int buttonState = 0;
Servo myepicservo;
const int echoPin = 49;
const int trigPin = 51;
int targAngle=0;
//int pressTime = 0;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
long duration, milimeters;
void setup() {
pinMode(echoPin, INPUT);
pinMode(trigPin, OUTPUT);
myepicservo.attach(53);
// pinMode(buttonPin, INPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("deez NUTS");
}
void loop() {
//// buttonState = digitalRead(buttonPin);
//delay(250);
//lcd.setCursor(0, 0);
//// if (buttonState == HIGH){
// if (pressTime%10>=5){
// pressTime = pressTime + 1;
//lcd.print("Button Pressed.");
//}
//else{
//pressTime = pressTime + 1;
//lcd.print("No press. ");
//}
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
// print the number of seconds since reset:
//lcd.print(millis() / 1000);
delayMicroseconds(38);//gap time
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);//pulse time
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);//listen
lcd.setCursor(0,0);
milimeters=duration*343/2000;//distance over 2
lcd.print(String(milimeters/10.00)+"cm ");
lcd.setCursor(0, 1);
//targAngle = (pressTime*10) % 180;
targAngle = milimeters/10 % 180;
myepicservo.write(targAngle);
lcd.print(String(targAngle) +" " );
}