This is URGENT! Reply ASAP! Deadline Feb 1!
Facts: I have a car which is based on a Arduino Mega 2560, is a 4WD (all 4 wheels are connected to a motor), runs on a 12.60-12.65V battery, motors are controlled by a L298N, has an LCD, motors recieve 10.15V-10.25V (transistors suck up about 1.4V).
Problem: This might be a little hard to understand, so don't be frustrated if you don't get it the first time. Now, the problem is that I have programmed it to run at full speed (255), and it is going crazy fast, in fact WAY to fast. So I want to slow it down. But, I also need to insert a delay for how long it needs to perform the actions I need it to perform. I already have the correct delay timings. I need to reduce the speed, but increase time. SPEED: LOWER. TIME: HIGHER. But its not like I can just do it. I need to do the math. But I DON"T KNOW THE FORMULA. I know what I need to know. Just tell me what the formula is, and make an example with 1 as the speed. Don't worry about the delays in "void setup()". Here is the code:
const int IN1 = 51;
const int IN2 = 50;
const int IN3 = 53;
const int IN4 = 52;
const int ENA = 13;
const int ENB = 12;
void Turn_Right() {
digitalWrite (IN1, HIGH);
digitalWrite (IN2, LOW);
digitalWrite (IN3, LOW);
digitalWrite (IN4, LOW);
analogWrite (ENA, 255);
analogWrite (ENB, 0);
delay(330);
analogWrite(ENA, 0);
analogWrite(ENB, 0);
}
void Turn_Left() {
digitalWrite (IN1, LOW);
digitalWrite (IN2, LOW);
digitalWrite (IN3, HIGH);
digitalWrite (IN4, LOW);
analogWrite (ENA, 0);
analogWrite (ENB, 255);
delay(330);
analogWrite(ENA, 0);
analogWrite(ENB, 0);
}
void Move_Forward() {
digitalWrite (IN1, HIGH);
digitalWrite (IN2, LOW);
digitalWrite (IN3, HIGH);
digitalWrite (IN4, LOW);
analogWrite (ENA, 255);
analogWrite (ENB, 255);
delay(382);
analogWrite(ENA, 0);
analogWrite(ENB, 0);
}
void setup() {
delay(4000);
Move_Forward();
Turn_Right();
Move_Forward();
Move_Forward();
Move_Forward();
Move_Forward();
Turn_Left();
Move_Forward();
Move_Forward();
Turn_Left();
Move_Forward();
Move_Forward();
delay(30000);
Move_Forward();
Move_Forward();
Move_Forward();
Move_Forward();
Turn_Left();
Move_Forward();
Move_Forward();
delay(40000);
Turn_Left();
Turn_Left();
Move_Forward();
Move_Forward();
Turn_Right();
Move_Forward();
Move_Forward();
Move_Forward();
Move_Forward();
Move_Forward();
Move_Forward();
Turn_Left();
Move_Forward();
Move_Forward();
Turn_Right();
analogWrite(ENA, 0);
analogWrite(ENB, 0);
}
void loop() {
}