Finding some specific tutorials

Hello everyone. I have posted no code here, I just have some questions about tutorials and how to approach this project. I have been looking around for the correct tutorials or examples with no luck. I tried to write it and use examples here, but I think I’m on the wrong path. I find it easier to learn by using other’s code and then researching anything I don’t understand. I don’t want to just copy and paste without understanding the code. I have looked into local college courses but cannot find one where I live. So, I hope I can get some help this way.

This is what I am trying to do:
4 LEDs .
LED #1 Fades on and then off.
When LED#1 is 50 or 60% faded off, then LED#2 begins to fade in.
and so on through the last two LEDs.

I saw a tutorial from another member here quite some time ago, but cannot find it now. I remember it was something about a state machine.
So, if someone could point me towards some tutorials and/or examples pertaining to the above problem I would really appreciate it. Thanks in advance.

Did you check the resource list in the first threads in the forum?

Merci

there are several "LED PWM in sequence" sketches in this thread:

Thank you but this is all above my level.
Gonna have to find a different way of doing my original project without the fading LEDs

Use neoPixels and it becomes pretty straight forward.

-jim lee

Hi Polliwog,

so how would you describe your knowledge-level about programming
Just a rough estimation:

a) I know what void setup() and void loop() do but that's it
b) I can write a small program that blinks an LED using the command delay()
c) I know how non-blocking timing works I know what PWM is

So the steps are making a single LED fade in fade out.
Therefore you can look into the Arduino-example-code

file - examples - analog - fading

The demo-program uses this unspeakably bad function delay()
but it shows how analogWrite can be used to fade LEDs

As you wish to fade multiple LEDs a software-tecnique call non-blocking timing is needed.

One method to realise your LED-fading with a time-offset is to use a loop that increments a counter once every x amount of milliseconds.
To show the basic principle I use a smaller number of steps from LED OFF to full bright ON

Counter LED1        LED2       LED3       LED4       LED5       LED6
1        10%         |          |          |          |          | 
2        20%         |          |          |          |          | 
3        30%         |          |          |          |          | 
4        40%         |          |          |          |          | 
5        50%         |          |          |          |          | 
6        60%        10%         |          |          |          |    
7        70%        20%         |          |          |          |    
8        80%        30%         |          |          |          |    
9        90%        40%         |          |          |          |    
10      100%        50%         |          |          |          |    
11       90%        60%        10%         |          |          |       
12       80%        70%        20%         |          |          |       
13       70%        80%        30%         |          |          |       
14       60%        90%        40%         |          |          |       
15       50%       100%        50%         |          |          |       
16       40%        90%        60%        10%         |          |          
17       30%        80%        70%        20%         |          |       
18       20%        70%        80%        30%         |          |       
19       10%        60%        90%        40%         |          |       
20        0%        50%       100%        50%         |          |       
21                  40%        90%        60%        10%         |      
22                  30%        80%        70%        20%         |      
23                  20%        70%        80%        30%         |      
24                  10%        60%        90%        40%         |      
25                   0%        50%       100%        50%         |      
26                             40%        90%        60%        10%
27                             30%        80%        70%        20%
28                             20%        70%        80%        30%
29                             10%        60%        90%        40%
30                              0%        50%       100%        50%
31                                        40%        90%        60%
32                                        30%        80%        70%
33                                        20%        70%        80%
34                                        10%        60%        90%
35                                         0%        50%       100%
36                                                   40%        90%
37                                                   30%        80%
38                                                   20%        70%
39                                                   10%        60%
40                                                    0%        50%
41                                                              40%
42                                                              30%
43                                                              20%
44                                                              10%
45                                                               0%

if counter is between 1 and 10 fade-in LED1 by incrementing duty-value of the analogWrite by +10
if counter is between 11 and 19 fade-OUT LED1 by incrementing duty-value of the analogWrite by +10
if counter is bigger than 19 LED1 duty is 0

if counter is between 6 and 15 fade-in LED2 by incrementing duty-value of the analogWrite by +10
if counter is between 16 and 24 fade-OUT LED1 by incrementing duty-value of the analogWrite by +10
if counter is bigger than 25 LED2 duty is 0

etc. etc.

here is a "sketchy" sketch to show the principle

 [code]
// not full functional code just a "sketchy" sketch to show the principle
void setup() {
  // put your setup code here, to run once:

}

boolean TimePeriodIsOver (unsigned long &expireTime, unsigned long TimePeriod) {
  unsigned long currentMillis  = millis();  
  if ( currentMillis - expireTime >= TimePeriod )
  {
    expireTime = currentMillis; // set new expireTime
    return true;                // more time than TimePeriod) has elapsed since last time if-condition was true
  } 
  else return false;            // not expired
}

unsigned long MyTimer;
unsigned long MyIntervalInMilliSeconds = 50;

int Counter = 0;
int LED1_Duty = 0;
int LED2_Duty = 0;
int LED3_Duty = 0;
int LED4_Duty = 0;


void loop() {

  // do a timed counting up as the timebase
  if (TimePeriodIsOver (MyTestTimer, MyIntervalInMilliSeconds) ) {
    Counter++; 

    if Counter > 45 {
      Counter = 1;
    }
  }

  // max Duty = FULL BRIGHT ON is 255 so a 1/10th-step is 255 / 10 = 25.5  
  // LED1
  if (Counter > 0 && Counter =< 10) {
    LED1_Duty += 25; // fade-in
  }
  else if (Counter > 10 && Counter =< 19) {
    LED1_Duty -= 25; // fade-out
  }  
  else {
    LED1_Duty = 0;  
  }


  // LED2
  if (Counter > (0 + 5) && Counter =< (10 + 5) ) {
    LED1_Duty += 25; // fade-in
  }
  else if (Counter > (10 + 5) && Counter =< (19 + 5)) {
    LED2_Duty -= 25; // fade-out
  }  
  else {
    LED2_Duty = 0;  
  }


  // after all duty-values have bee setup up  update PWM-signals
  analogWrite(LED1_Pin, LED1_Duty); 
  analogWrite(LED2_Pin, LED1_Duty); 

}

[/code]

this sketchy sketch does not (yet) compile
best regards Stefan