Include

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

#include <LiquidCrystal.h> #include <Servo.

h>

Servo pingServo; int delayTime = 1000; LiquidCrystal lcd(12, 11, 8, 3, 2, 1); const int pingPin = 10; byte dir=0; byte speed1=250; //250 byte speed2=255; //255 int turn90=600; //110 int turn45=300; //55 int straight=500; int stopTime=200; int IRdistance=0; int treshold=20; void setup () { lcd.begin(16, 2); pingServo.attach(13); } void loop () { long duration, cm; pingServo.write(90); delay(delayTime); pinMode (pingPin, OUTPUT); digitalWrite(pingPin, LOW); delayMicroseconds (2);

digitalWrite(pingPin, HIGH); delayMicroseconds (5); digitalWrite(pingPin, LOW); pinMode (pingPin, INPUT); duration = pulseIn(pingPin, HIGH); cm = microsecondsToCentimeters (duration);

lcd.clear(); lcd.home(); lcd.print(cm); lcd.print(" cm"); delay (1000); } long microsecondsToCentimeters (long microseconds) { return microseconds /29 /4; } void driver ()

You might also like