Making lighthouse

Hi you all

I really love arduino , and I'm using it most of all for lightning effects.
Too bad I struggle with the code... i do not have the magic braincel for programming.... :o 

So , I hope you can help me out with this project?

I want to blink a led 3 times for 1 second , then a 4 second pause , and then endless loop this.
I have allready the code for this.

[code]int led = 9;

void setup() {
 pinMode(led, OUTPUT);
}

void loop() {
 digitalWrite(led, HIGH);
 delay(1000);
 digitalWrite (led, LOW);
 delay(1000);
 digitalWrite(led, HIGH);
 delay(1000);
 digitalWrite (led, LOW);
 delay(1000);
 digitalWrite(led, HIGH);
 delay(1000);
 digitalWrite (led, LOW);
 delay(1000);
 { 
 digitalWrite(led, LOW);
 delay(4000);

}
}


But I want to fade the leds as well , and now I'm stuck... 
I have found this library   https://github.com/jgillick/arduino-LEDFader 

and now I want to integrate the 2 together so the leds fade in and out .

Greetings from Bart

[/code]

If you only have one process running, then it is ok to use the delay() function. But when you want two things to be running at the same time, you need to get rid of the delay() function and use soft delays.
Look at the example "blink Led without delay). If you need further info, let us know.

Oh, so you are not wanting to do two things at once?
You want to turn the led attached to pin 9, on, then off, then make it fade (all in sequence, not at the same time).

Ok, you have the "turning on and off" working already.
You have code to do the fade? Have you tested it? I assume so, and that it works.
So add a function call as the last line inside the loop() function, that calls a fade function (which you will create, putting the fade code in). You can name whatever you want, but myFade() sounds good to me.

The function would be sorta like this pseudo code:

void myFade() 
{
   // fade code goes here
   // when the function finishes, it will return back to the loop() automatically.
}

If That is not clear, or doesn't work ask again.

Ok, good try.

  1. you should put a call to your new function on the line just after delay(4000);
    The line would be myFade();

  2. Inside your new function you have ' void loop() { '. That should be removed.

  3. Inside your new function you are calling 'led.update(), and also led.fade() . I don't see those functions available anywhere.

I think you have some of your braces {} not matching up right. Check each pair of braces and make sure they have their mate in the right spot.

Using ctrl-T to autoformat in the IDE will sometimes help spot problems with braces placement. It will also make your code more readable.

using the fade example and not a library, here is an option.

timing is off, but you need to fix the rough spots.

it uses delay()

total use of fade in the examples

added a delay between the fade up to hold the light on.

added a delay between fades
and added a count field,
counts 4 time through, then after the repeat delay, it adds another 2 seconds.

int count;

int ledPin = 9;    // LED connected to digital pin 9

void setup() {
}

void loop() {
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
    analogWrite(ledPin, fadeValue);
    delay(10);
  }
digitalWrite(ledPin,HIGH);
delay(2000);

  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
    analogWrite(ledPin, fadeValue);
    delay(10);
  }
  
  delay(2000);
  count=count+1;
  
  if(count>=4){
    digitalWrite(13,HIGH);
    delay(2000); //adds a second 2 seconds
    digitalWrite(13,LOW);
    count=0;
  }
  
}

I was not sure if you wanted a 1 second on, then 1 second off
on and off in a 1 second cycle
or all 3 on/off cycles in one second.

timing needs to be adjused in both of the delays that follow each of the for() loops.
each for() loop has a delay on each step. currently at 10ms, there would be 26 steps

you can change the delay(10) to speed up the ramp

By having the fade, you need to adjust the timing.

On a fixed lighthouse, the light sweeps on a timing, called a characteristic
Guessing that your characteristic is 3 pulses in 3 seconds, you would need to consider that you need to ramp up, hold the light on, then ramp down, stay off, all in one second.

That way the start of each fade-up would start every 1 second.

The sketch was written with a 10ms per increment, 26 increment, fade-in time
A 2 second hold to be on
A 10ms per increment, 26 increment fade-out time and
A 2 second hold-off time.

The total per pulse is 4 seconds and 420ms

You can speed up the fade in, by either changing the increment value
And/or, by changing the 10ms fade-in time.
I would adjust the fade time first

In reality, most lighthouses in the past used a rotating Fresnel lens. This had a very short bright point, so the full ON brightness was very fast. Also, the characteristic of the fade is linear in numbers, but LED lights are not linear in brightness.

I think you could eliminate the entire delay between fade in and fade out and just fade in and fade out, then change the off delay to 680ms to get a 1 second pulse.

The 1 second would be timed from start of fade-in to start of fade-in

Of course the 4 second delay would be whatever is needed to be added to the delay of the off to get the total off time.

the only part I was not sure about was the for() loop timing.

if you have

void loop() {
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
analogWrite(ledPin, fadeValue);
delay(10);
}

I see 255 / 10 as 26 increments.
0-10, delay... up to 250-260 at which time the loop is complete.

not sure how the timing goes if you use a number like 10 as it goes into 255 with a remainder.
not sure if there is a delay on that last run through.

also, this whole project is based on only the light, and not other activity as this is all based on blocking when using delay()

I don't have any familiarity with that device, nor RGB LED's

this sketch uses delay(), you would have to have a good idea how you wanted to light the three sets.

at first glance, it would seems you would want all the LED's to light, but one side to light faster, then the center and then the right side the fade as if the light were a wave.

maybe someone who knows the neopixel can help..

Bartie67:
I have one like that for another project , but could it be possible to fade in the 2 left leds , then lit up the 3 middle pixels to full brightness and then fade out again to the 2 right leds . The 2 neopixels from the left and the right would not lit up to full brightness. and this only with a white light ?

fade in one side to about 80%
turn full on left/center/right in very fast order.
then fade out on the right.
this would simulate the sweep of a lighthouse.

is the only thing the Arduino is to be used for, is just this one set of lights ?

That should be doable. And if this is the only thing the Arduino is to be used for, then you can use the delay() function with confidence.

Your description seems sound.

Where are you stuck at?

the OP wanted to use this
a neopixel jewel led - NeoPixel Jewel - 7 x 5050 RGB LED with Integrated Drivers : ID 2226 : Adafruit Industries, Unique & fun DIY electronics and kits

dave-in-nj:
the OP wanted to use this
a neopixel jewel led - NeoPixel Jewel - 7 x 5050 RGB LED with Integrated Drivers : ID 2226 : Adafruit Industries, Unique & fun DIY electronics and kits

Oh, I missed that part. Then, I should retract my last few statements.