Controlling PWM pin

I have hooked up LED driver to one of PWM pins. It is for night time moon light. How I cut off light at day ?

analogWrite (moon, 0 ); or digitalWrite (moon,LOW ); or ...

Thanks

Odd as it may seem…

Those are exactly the same thing:

#define HIGH 0x1
#define LOW  0x0 // <- same as 0

How do you have your LED hooked up? Is it inverted logic?

muda: I have hooked up LED driver to one of PWM pins. It is for night time moon light. How I cut off light at day ?

analogWrite (moon, 0 );

Yes, that is proper form. or digitalWrite (moon,LOW ); Interesting if you dig down into the source code for the analogWrite() function, I believe that analogWrite(pin,0); results in simply using a digitalWrite(pin, LOW). As I recall in some early IDE versions the analogWrite(pin,0) showed up a bug where instead of a constant low output there was a single one count duty cycle output and would show up as as very dim light if wired to a high efficiency led. I recall hooking up my oscilloscope to a PWM output set to 0 and still seeing a single high pulse, so something was screwy with the timer counter/resetting/overflow or interrupt or something along those lines. I guess the simple fix was to have the function check for a 0 duty cycle request and just force the output pin LOW. :D Lefty or ...

Thanks

bubulindo:
Odd as it may seem…

Those are exactly the same thing:

#define HIGH 0x1

#define LOW  0x0 // ← same as 0




How do you have your LED hooked up? Is it inverted logic?

I think his question rather was to use the analogWrite or the digitalWrite function. ?

Lefty

retrolefty:
Interesting if you dig down into the source code for the analogWrite() function, I believe that analogWrite(pin,0); results in simply using a digitalWrite(pin, LOW). As I recall in some early IDE versions the analogWrite(pin,0) showed up a bug where instead of a constant low output there was a single one count duty cycle output and would show up as as very dim light if wired to a high efficiency led. I recall hooking up my oscilloscope to a PWM output set to 0 and still seeing a single high pulse, so something was screwy with the timer counter/resetting/overflow or interrupt or something along those lines. I guess the simple fix was to have the function check for a 0 duty cycle request and just force the output pin LOW. :smiley:
Lefty

Not a bug but the way the PWM works in the AVR. I don’t have the manual, or time to chase that down, but it is written there (had that problem myself before).

retrolefty:

bubulindo:
Odd as it may seem…

Those are exactly the same thing:

#define HIGH 0x1

#define LOW  0x0 // ← same as 0




How do you have your LED hooked up? Is it inverted logic?

I think his question rather was to use the analogWrite or the digitalWrite function. ?

Lefty

You are right. Some dyslexia there, I read two analogWrite(). Disregard my previous post.

Thanks for thorough explanation.

Cheers