H_Bridge_Led_Blink

HI Guys
I bought this 3-36v Dual 15a H-bridge DC Motor Driver 30a for Robot & Car Arduino Compatible for sale online | eBay h_bridge to try and make a wiper motor act like a big servo motor. Before I tried to get the wiper motor figured out I thought I would mess with a small motor first. I started by trying to write a sketch that would gradually speed a small motor up and then slow it down and then reverse the direction that the motor spins and cycle through the speed range again. I got this working and then I tried to add a flashing led to the sketch and the led would only flash ounce after the UNO went through the motor sketch before it would flash again. My question is can I make the led flash constantly while the motor is going through the sketch ?

Thanks GD

/*
  This is the first sketch I wrote to operate my H_Bridge
  This gradually speed up and slowed down and then reversed
  and repeated the slowing and speed back up
  I included a blinking LED but it has to go through the 
  full cycle of the motor then it blinks ounce and goes back to
  cycle through the motor sketch before blinking again
 */

int led = 13;  //pin 13 led blinking
int pwm = 9; //PWM on the H Bridge:
int dir = 8; //Dir on the H Bridge:
int i = 0;      // We’ll use this to count up and down
// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode  (pwm, OUTPUT);    
  pinMode (dir,OUTPUT); 
  pinMode (led,OUTPUT);
}

// the loop routine runs over and over again forever:




void loop(){ 
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
  digitalWrite(dir,HIGH); 
  for (i = 50; i < 255; i++) { // loop from 50 to 254 (fade in)
    analogWrite(pwm, i);      // set the LED brightness
    
    delay(100); // Wait 10ms because analogWrite
               // is instantaneous and we would
               // not see any change
  }
     digitalWrite(dir,LOW); 
  for (i = 255; i > 50; i--) { // loop from 255 to 50 (fade out)

    analogWrite(pwm, i); // set the pwm to control the motor speed---
    delay(100);           // Wait 100ms
  }

}
    analogWrite(pwm, i);      // set the LED brightness
    analogWrite(pwm, i); // set the pwm to control the motor speed---

Well, which is it?

    delay(100); // Wait 10ms because analogWrite
               // is instantaneous and we would

100 != 10. If you are going to have useless comments, you MUST keep them correct. It's a requirement.

My question is can I make the led flash constantly while the motor is going through the sketch ?

Without using delay. There's even an example sketch that you should look at, without delay.

Hi PaulS
Sorry for the mistakes. Here is the corrected comments.

GD

/*
  This is the first sketch I wrote to operate my H_Bridge
  This gradually speed up and slowed down and then reversed
  and repeated the slowing and speed back up
  I included a blinking LED but it has to go through the 
  full cycle of the motor then it blinks ounce and goes back to
  cycle through the motor sketch before blinking again
 */

int led = 13;  //pin 13 led blinking
int pwm = 9; //PWM on the H Bridge to control rpm's:
int dir = 8; //Dir on the H Bridge to control direction of rotation:
int i = 0;      // We’ll use this to count up and down
// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode  (pwm, OUTPUT);    
  pinMode (dir,OUTPUT); 
  pinMode (led,OUTPUT);
}

// the loop routine runs over and over again forever:




void loop(){ 
  digitalWrite(led, HIGH);   // turn the LED on 
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turns led off
  delay(1000);               // wait for a second
  digitalWrite(dir,HIGH);    // motor forward
  for (i = 50; i < 255; i++) { // loop from 50 to 254 (fade in)
    analogWrite(pwm, i);      // set the pwm to control the motor speed
    
    delay(100); // Wait 100ms because analogWrite
               // is instantaneous and we would
               // not see any change
  }
     digitalWrite(dir,LOW); // set the pwm to control the motor speed
  for (i = 255; i > 50; i--) { // loop from 255 to 50 (fade out)

    analogWrite(pwm, i); // set the pwm to control the motor speed---
    delay(100);           // Wait 100ms
  }

}