I was wondering how and where would I put the code for PING))) in the code below and how would I wire this to a L298N H-Bridge?
int PWM1 = 6; // PWM Pin Motor 1
int PoM1 = 7; // Polarity Pin Motor 1
int PWM2 = 5; // PWm Pin Motor 2
int PoM2 = 4; // Polarity Pin Motor 2
int ValM1 = 0; // Initial Value for PWM Motor 1
int ValM2 = 0; // Initial Value for PWM Motor 2
int i = 25; // increment
boolean goUp = true; // Used to detect acceleration or deceleration
void setup()
{
pinMode(PWM1, OUTPUT);
pinMode(PoM1, OUTPUT);
pinMode(PWM2, OUTPUT);
pinMode(PoM2, OUTPUT);
digitalWrite(PoM1, LOW); // Both motors with the sam polarity
digitalWrite(PoM2, LOW);
analogWrite(PWM1, ValM1); // Stops both motors => ValMx = 0
analogWrite(PWM2, ValM2);
Serial.begin(9600); // Used to check value
}
// Main program
void loop()
{
delay (500); // Give time to theh motor to adapt to new value
if ((ValM1 < 250) && goUp) // First phase of acceleration
{
ValM1 = ValM1 + i; // Increase PWM value => Acceleration
ValM1 = ValM1 + i;
}
else
{
goUp = false; // Accerleration completed
ValM1 = ValM1 - i; // Decrease PWM => deceleration
ValM2 = ValM2 - i;
if (ValM1 < 75)
{
ValM1 = 0;
ValM2 = 0;
goUp =
true;
}
}
if ((ValM1 > 75) && ((ValM1 < 255)))
{
analogWrite(PWM1, ValM1);
analogWrite(PWM2, ValM2);
}
Serial.print(ValM1);
Serial.print("\t");
Serial.print(ValM2);
}