Good evening folks,
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.
void setup ()
{
pinMode (2, OUTPUT);
}
void loop ()
{
digitalWrite (2, HIGH);
delayMicroseconds (5000);
digitalWrite (2, LOW);
delayMicroseconds (50000); //duty cycle 10%
}
How can I run that for five seconds and begin at another duty 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. 
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).
OP: Your calculator needs new batteries. 5000 on and 50000 off is not a 10% duty cycle. 5000/55000 = 8.8889%
Thanks to both of you. This sketch has helped give me a little insight. I'm going to keep studying the reference page. What i want is a solid 5 seconds on each 10% cycle up to 100% and then to start over. I can manually write the code if I knew how to start a counter. if counter > 5 seconds move to next cycle kind of thing.
I can manually write the code if I knew how to start a counter.
Counter and timer are NOT the same thing. You don't need either one, though.
Use the blink without delay philosophy. Turn the pin one. Record when that happens. Periodically (every pass through loop), see if it is time to turn it off (or back on). If so, do it, and record when that happened. When to perform the action will depend on what the action is (turn it off or turn it on) and what the "duty cycle" is.