Loop run for period and begin another cycle

macarpenter:
Good evening folks,

Your good wishes are appreciated, but this is a world-wide forum, so your evening is the middle of the night here, afternoon in some places and morning in others. :slight_smile:

I want to visually see the duty cycle change every 10% on my DC motor. I want to start from 10% and get to 100%. Forgive me if this seems trivial but I am an extreme novice. Here is my sketch so far at a 10% cycle.

I'm not certain what you want, but try this:

int a;
int z;
void setup (){
  pinMode (2, OUTPUT);
}
void loop (){
  for(z =1; z<10; z++){
     a = z * 50;
     digitalWrite (2, HIGH);
     delay(a);  //no need to use micros when millis will do
     digitalWrite (2, LOW);
     delay (500-a); //duty cycle 10% to 90%
  }
  digitalWrite (2, HIGH);
  delay(500); //duty cycle 100%
  digitalWrite (2, LOW);
}

That should, by my rough calculation, give about a 5 second cycle. To adjust it, just alter all the delays by the same amount and the multiplier to 1/10 of the delay figure (Eg. delay (550-a), delay(550) and the multiplier 55).