Delay function in a subroutine

Hi,
I am trying to change Timer2 and Timer1 parameters in order to manipulate my PWM signal from pin #3 and pin #10 of the Arduino Uno.

I do so by calling certain function (named: SWING) in which I am changing OCR1B and OCR2B from 0 to 200, thus I am trying to have a LED dimming effect.

The problem I am facing is that I cannot call the "delay (Time)" function from another function (other than the "setup" or "void" functions).

Does anyone have an idea how to overcome this problem?

Thanks, Eran

Don't use delay. (period).

There are myriads of threads in this forum about how the delay function causes problems.
Take a look at blink without delay for how to overcome that

(other than the "setup" or "void" functions).

Can you expand on this ? I do not understand what you mean in the context of your question.

You can't have a function called void. That's why you can't call delay() from the void function.

EranBenja:
Hi,
I am trying to change Timer2 and Timer1 parameters in order to manipulate my PWM signal from pin #3 and pin #10 of the Arduino Uno.

I do so by calling certain function (named: SWING) in which I am changing OCR1B and OCR2B from 0 to 200, thus I am trying to have a LED dimming effect.

The problem I am facing is that I cannot call the "delay (Time)" function from another function (other than the "setup" or "void" functions).

Does anyone have an idea how to overcome this problem?

Thanks, Eran

Unless you post your code we can't find the causes of your problem. And
if it doesn't compile post all the error messages.

The problem I am facing is that I cannot call the "delay (Time)" function from another function (other than the "setup" or "void" functions).

That is just plane wrong. You can call delay in any function.
By the way the title is wrong, there are no subroutines in C.

Hi all,
Thank you for yours responses.
I found the problem.
here is the code I used:

void Swing (int pin, int time, int bottom, int top, int delay){

  • delay (pin);*
    }

Apparently I used the string "delay" as one of my parameters.
That's how I got an Error" re the delay.

Thank you and best regards, Eran

  delay (pin);

delay(pin) ?
Wouldn't you want to delay whatever the time or delay amount was?

You have an int called delay, yet you're trying to call it as a function.

There is only one namespace of identifiers in C, not a separate one for functions,
so when you declare locally a variable called "delay" it shadows the global function "delay"