Magnetic gear solenoid clock.

Hello clever people.

I require help with a code for lighting six led’s in a circle one after the other in two seconds, but with

overlapping fade in and out (like a round nightrider blink). As one is fading at around 50% duty cycle the

next is getting brighter at 50% duty cycle.

I am using a uno and a RTC for timing. Three led’s in one second and three in the next second,

or six in two seconds (same thing).

I have the RTC output at 1Hz and using a library debounce code to light one led every two seconds.

I do not have the skill to do the timing, fading, overlapping output to the six led,s.

I refer to the solenoids with pole pieces on each end (North and South) that turn the 30 tooth gear in one

minute as led,s for easy communication and testing. Will have to bump the voltage up for that, twelve

You've got to do it something like this to light the leds ( say leds[0] through to led[5] ) in sequence where the trailing and leading leds are less bright than the current led.
You have a clock which runs from 0 to 5, and depending on the number on the clock, you light 3 leds. The outer 2 at 50% and the middle at 100%.
If it is all too fast, experiment first with interleaving delay() between the analogWrite() statements, then work out a better way using millis().

byte clock = 0 ;
byte led[6] = { 2,3,4,5,6,7 } ;  // led[0] on pin 2 , led[1] on pin through to led[5] on pin 7
...
...

loop() {

    analogWrite(  led[ ( clock + 0 ) % 6 ] , 127  )  ; // trailing led half brightness.
    analogWrite(  led[ ( clock + 1 ) % 6 ] , 256  )  ; // central led full brightness 
    analogWrite(  led[ ( clock + 2 ) % 6 ] , 127  )  ; // leading led half brightness 
    analogWrite(  led[ ( clock + 3 ) % 6 ] , 0      )  ; // off 
    analogWrite(  led[ ( clock + 4 ) % 6 ] , 0      )  ; // off 
    analogWrite(  led[ ( clock + 5 ) % 6 ] , 0      )  ; // off 

    clock ++ ;
    if ( clock > 5 ) clock = 0 ;
    
}

I'm not sure what you intend with the solenoids. That is not clearly explained.

Great, except 2, 4 and 7 aren't PWM pins on an UNO and they won't fade. 3, 5, 6, 9, 10, 11 would be a better choice if you have an UNO.

MorganS:
Great, except 2, 4 and 7 aren't PWM pins on an UNO and they won't fade. 3, 5, 6, 9, 10, 11 would be a better choice if you have an UNO.

True indeed. Of course, it wasn't intended as full tested solution, just as a pointer to set the OP in a possible direction. I won't edit it now but I'd also reduce the maximum PWM rate to fit in a single byte (as a Uno - if that is what he has got - requires).
He also has to tell us a bit more about what he is up to, and maybe even finish off the sentence at the end of his post.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Do you need the accuracy of a RTC?

Are you doing the complete 6 LED scan in 2seconds?
OR
2Seconds for each LED?

You might find some help googling arduino night rider fade

Tom... :slight_smile: