moonlight cycle

Hi,

Do you know what's the best way to obtain a sinusoidal wave of brightness of LEDs with a period of 29.5 days?
I would like to change the brightness of the LEDs from 0 to X (during 14.75 days) and then from X to 0 (during 14.75 days) to simulate a moonlight cycle.

I am using arduino uno and RTC.

I found some sketch on the forum, but not sure how to start the project.

Any suggestions?

Some good old percentages?

Get the day of the month, pop it into an if statement. If itâ€™s <=15, then proceed to work out the percentage of the value out of 15. Then just multiply that percentage by 255 to get a value to send out on a PWM pin.

Do the same (but with a little adaptation) for days >15.

Remember to get your floats and int correctly

but in such case it is not precise.....isn't?

valerio83:
but in such case it is not precise.....isn't?

What's all the interest in "precision"?

The human eye has difficulty discerning differences in light intensity less than say, 20%. The slightest shading or reflection introduces much more than that (which is why you can discern shading). Visual response is essentially logarithmic,

speaking about the precision of the sinusoidal curve compared to the moonlight cycle.

If I use the day of the month it is not a precise cycle of brigthness with a period of 29.53 days.

do you what I mean?

V

valerio83:
with a period of 29.5 days?

How accurate does that need to be? I mean, do you care if it is 29.5 days and a few minutes, or does this need to stay synchronised to some real-world events such as time-of-day or the actual phase of the moon?

I think as a first step 29.5 days and few minutes is ok.

do you have any suggestions.

I was thinking about use fading and delay(). What do you think?

V

delay() would be OK-ish, if you don't have anything else to do, like monitoring switches, but have a look at the blink without delay example and see if you can do better, and not use delay at all.

valerio83:
I think as a first step 29.5 days and few minutes is ok.

do you have any suggestions.

In that case you probably don't need it any more accurate than the Arduino's hardware clock so you can just use millis() to control your timing. The algorithm would be to calculate the frequency of the sin wave you are generating, multiply that by elapsed time since the sine wave started to get the current phase angle, take the sin of the angle and offset that to get a positivce value giving your required brightness. You might want to perform gamma correction to convert from the required brightness to the PWM value.

You would evaluate this algorithm however often you wanted - I doubt there is much point doing it more often than once per minute, but if you have nothing better to do then there's no harm in doing it more often.