Something has gone wrong and I can't find it. Can you help me? Here is my code
int brakePin = 9;
int brakePinb = 8;
int pwmPin = 3;
int pwmPinb = 11;
int directionPin = 12;
int directionPinb = 13;
const int pingPin = 7;
void setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop()
{
long duration, inches, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
if (inches < 6)
{
digitalWrite(brakePin, HIGH);
digitalWrite(brakePinb, HIGH);
}
else
{
digitalWrite(brakePin, LOW);
digitalWrite(brakePinb, LOW);
digitalWrite(pwmPin, 150);
digitalWrite(pwmPinb, 150);
digitalWrite(directionPin, HIGH);
digitalWrite(directionPinb, HIGH);
}
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
}
long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}
Thanks, Tim4tech