// THIS IS TANK NUMBER 3
const int motorA_pin_1=7; // The numbers of the motor pins
const int motorA_pin_2=6; // For motor A
const int motorA_pin_speed=5;
const int motorB_pin_1=9; // The number of the motor pins
const int motorB_pin_2=8; // For motor B
const int motorB_pin_speed=10;
const int ledPin=13; // The number of the LED pin
int motorA_state_pin_1=LOW; // Used to set the state of the motors
int motorA_state_pin_2=LOW; // Low is off
int motorB_state_pin_1=LOW;
int motorB_state_pin_2=LOW;
int ledState=LOW; // The LED state is low or off
unsigned long previousMillis1=0; // Stores the time the state
unsigned long previousMillis2=0; // of the motors was checked
unsigned long previousMillis3=0;
unsigned long previousMillis4=0;
unsigned long previousMillis5=0;
unsigned long previousMillis6=0;
unsigned long previousMillis7=0;
unsigned long previousMillis8=0;
unsigned long previousMillis9=0;
const long interval_A=6000; // How long the motor will run for
const long interval_AB=5000;
const long interval_AC=4000;
const long interval_AD=3000;
const long interval_AE=2000;
const long led_interval=2000; // How long the LED will blink
void setup() { // Put your code hear to run once
pinMode(motorA_pin_1,OUTPUT); // Sets the pins to output
pinMode(motorA_pin_2,OUTPUT);
pinMode(motorA_pin_speed,OUTPUT);
pinMode(motorB_pin_1,OUTPUT);
pinMode(motorB_pin_2,OUTPUT);
pinMode(motorB_pin_speed,OUTPUT);
pinMode(ledPin,OUTPUT);
analogWrite(motorA_pin_speed,255); // sets how fast the motors will turn
analogWrite(motorB_pin_speed,255);
unsigned long currentMillis=millis();
if(currentMillis-previousMillis1>=interval_A);{ // This makes both motors
previousMillis1=currentMillis; // run forward for 6 seconds
if(motorA_state_pin_1==LOW){
if(motorB_state_pin_1==LOW)
motorA_state_pin_1=HIGH; // THIS IS LEG 1
motorB_state_pin_1=HIGH;
}else{
motorA_state_pin_1=LOW;
motorB_state_pin_1=LOW;
} // This closes the “else” statement
} // This closees the time count
} // This closes void setup
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(motorA_pin_1,motorA_state_pin_1);
digitalWrite(motorB_pin_1,motorB_state_pin_1);
digitalWrite(motorA_pin_2,motorA_state_pin_2);
digitalWrite(motorB_pin_2,motorB_state_pin_2);
digitalWrite(ledPin,ledState);
} // This closes the void loop
This is my grandsons Tank program. We can’t get the motors to turn off after the 6 seconds. He put in " void setup() " because he only wants it to run once. We have both looked and looked and can’t seem to see where we went wrong. Can some have a look and give a hint what we may have missed.