problem with multipul pwn/delay

heres how the program is settup

const int RevRelay = 11;
const int Step = 12;

void setup() {
pinMode(Step, OUTPUT);
pinMode(RevRelay, OUTPUT);
}

void loop() {
digitalWrite(Step, HIGH);
delay(4);
digitalWrite(Step, LOW);
delay(4);
digitalWrite(RevRelay, HIGH);
delay(1000);
digitalWrite(RevRelay, LOW);
delay(1000);
}

heres what it acts like

const int RevRelay = 11;
const int Step = 12;

void setup() {
pinMode(Step, OUTPUT);
pinMode(RevRelay, OUTPUT);
}

void loop() {
digitalWrite(Step, HIGH);
delay(1000);
digitalWrite(Step, LOW);
delay(1000);
digitalWrite(RevRelay, HIGH);
delay(1000);
digitalWrite(RevRelay, LOW);
delay(1000);
}

any ideas to why it dose thst dnd if their is a nother way to right it let me know thenks

What does the code have to do with PWM?

Are you expecting to see a 4 millisecond delay?

What is connected to the Step pin?

The step relay stays on for a whole second? It should be staying on for 4ms and then off for 2004ms while the other relay does its thing.

Very strange, it should not do that.

Which Arduino board do you have ?
Do you use the newest Arduino IDE version 1.0.6 or 1.5.8 ?
Are you sure that you are uploading the sketch ? Can you make a led blink ?

Delta_G, you think a step relay is used ? then 4ms is too short.

Peter_n:
Delta_G, you think a step relay is used ? then 4ms is too short.

I wouldn't try to guess all that. I was just going off the name of the variable.

would adding a another void loop help

vinaton:
would adding a another void loop help

You can't do that. You're only allowed one function with that name.

Do you want one to change every 4ms and the other to change every 1000ms? If so, I suspect you need to learn and embrace the "Blink Without Delay" paradigm.

Have a look at this: Demonstration code for several things at the same time - Project Guidance - Arduino Forum

No. You can only have one loop() function. What were you thinking of doing with it ?

Can you tell us what the program is intended to do and what hardware you are using ?

the 4 ms is the step timer and the 1000 ms is the reverse switch

vinaton:
the 4 ms is the step timer and the 1000 ms is the reverse switch

That tells me nothing. A step timer and reverse switch for what? What do you want them to do?

the pin 11 puts power to a bace of a NPN tranzistor alowing the steper moter to reverce and the 4 ms is makeing the steper moter step bye aplying pasitive pulces to the step pin on the bipolar driver bord from pin 12 so i want pin 12 to have a 4ms delay and the pin 11 to have a 1000 ms delay dose that make more sence

vinaton:
the pin 11 puts power to a bace of a NPN tranzistor alowing the steper moter to reverce and the 4 ms is makeing the steper moter step bye aplying pasitive pulces to the step pin on the bipolar driver bord from pin 12 so i want pin 12 to have a 4ms delay and the pin 11 to have a 1000 ms delay dose that make more sence

That's what I thought you wanted to do. Well, you can't do that and use the delay function because during that 1 second of delay the board won't do anything but sit there like a lump. And from what I understand you'd like that other output to keep going.

Have you had a look at the link that I gave you in reply #6? That will show you how to write non-blocking code so you can handle doing more than one thing at a time.

witch code do i use for what i am doing

vinaton:
witch code do i use for what i am doing

Did you read it? Do you understand it? If not then read it again. Once you understand it then it should be quite trivial. That write-up that I linked you to is incredibly simple.

On each pass through the loop function, check the time and see if it is time to switch one of the pins. If 4ms have passed since the last time the step pin was toggled, then its time to toggle it and remember what time you did so. Same with the 1000ms time period only for the other pin.

so this code should do what i want it to do

const int Step = 12;
const int NPNRev = 11;

const int Step_Interval = 2;
const int NPNRev_Interval = 1000;

const int blinkDuration = 0;

byte Step_State = LOW;
byte NPNRev_State = LOW;

unsigned long currentMillis = 0;
unsigned long previous_Step_Millis = 0;
unsigned long previous_NPNRev_Millis = 0;

void setup() {
pinMode(Step, OUTPUT);
pinMode(NPNRev, OUTPUT);

}

void loop() {
currentMillis = millis();
update_Step_State();
updateLed_B_State();
}

void update_Step_State() {

if (Step_State == LOW) {
if (currentMillis - previous_Step_Millis >= Step_Interval) {
Step_State = HIGH;
previous_Step_Millis += Step_Interval;
}
}
else {
if (currentMillis - previous_Step_Millis >= blinkDuration) {
Step_State = LOW;
previous_Step_Millis += blinkDuration;
}
}
}
void update_NPNRev_State() {

if (NPNRev_State == LOW) {
if (currentMillis - previous_NPNRev_Millis >= NPNRev_Interval) {
NPNRev_State = HIGH;
previous_NPNRev_Millis += led_B_Interval;
}
}
else {
if (currentMillis - previous_NPNRev_Millis >= blinkDuration) {
NPNRev_State = LOW;
previous_NPNRev_Millis += blinkDuration;
}
}
}

  if (NPNRev_State == LOW) {
    if (currentMillis - previous_NPNRev_Millis >= NPNRev_Interval) {
       NPNRev_State = HIGH;
       previous_NPNRev_Millis += led_B_Interval;
    }
  }
  else {
    if (currentMillis - previous_NPNRev_Millis >= blinkDuration) {
       NPNRev_State = LOW;
       previous_NPNRev_Millis += blinkDuration;
    }
  }

Do you want blinkDuration or the NPNRev_Interval here?

It looks like you've got the concept. The only thing you're doing wrong here is not setting the pins. You get the new state for the pins, but at some point you'll need to actually do a digitalWrite(Step, Step_State) to actually put that out on the pin.

that is how the code was wrote so i coppyed it and modifyed the variebls so it would do what i want so what needs to be fixed what line and what number

it verifies ok so i will test it

no output on the io pins what is wrong with this virshion

const int Step = 12;
const int NPNRev = 11;

const int Step_Interval = 2;
const int NPNRev_Interval = 1000;

const int blinkDuration = 0;

byte Step_State = LOW;
byte NPNRev_State = LOW;

unsigned long currentMillis = 0;
unsigned long previous_Step_Millis = 0;
unsigned long previous_NPNRev_Millis = 0;

void setup() {
pinMode(Step, OUTPUT);
pinMode(NPNRev, OUTPUT);

}

void loop() {
currentMillis = millis();
update_Step_State();
update_NPNRev_State();
}

void update_Step_State() {

if (Step_State == LOW) {
if (currentMillis - previous_Step_Millis >= Step_Interval) {
Step_State = HIGH;
previous_Step_Millis += Step_Interval;
}
}
else {
if (currentMillis - previous_Step_Millis >= blinkDuration) {
Step_State = LOW;
previous_Step_Millis += blinkDuration;
}
}
}
void update_NPNRev_State() {

if (NPNRev_State == LOW) {
if (currentMillis - previous_NPNRev_Millis >= NPNRev_Interval) {
NPNRev_State = HIGH;
previous_NPNRev_Millis += NPNRev_Interval;
}
}
else {
if (currentMillis - previous_NPNRev_Millis >= blinkDuration) {
NPNRev_State = LOW;
previous_NPNRev_Millis += blinkDuration;
}
}
}

Would writing the current states to the pins help I wonder ?

Delta_G did tell you earlier

The only thing you're doing wrong here is not setting the pins. You get the new state for the pins, but at some point you'll need to actually do a digitalWrite(Step, Step_State) to actually put that out on the pin.