Trying to blink after fade.

As a learning exercise, I took the example programs of Blink and Fade and tried to combine them.

They both work as I can comment out either part and the other will work.
However when I combine them, only the blink works and I cannot see why.

Here is my kludge.
Thanks

int led = 9;           // the PWM pin the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
int i = 0;

void setup()
{
// declare pin 9 to be an output:
  pinMode(led, OUTPUT);
}

// The Fade section 

void loop()
{
  // set the brightness of pin 9:

  // change the brightness for next time through the loop:

  for (i = 0; i <= 255; i++);
  {
    analogWrite(led, brightness);
    brightness = brightness + fadeAmount;
  }

  // reverse the direction of the fading at the ends of the fade:

  for (i = 0; i <= 255; i++);
  if (brightness <= 0 || brightness >= 255)
  {
    fadeAmount = -fadeAmount;
  }

  // wait for 30 milliseconds to see the dimming effect
  delay(30);

// and the Blink section 

for (i = 0; i < 255; i+5)
  {
    analogWrite(led, 255);   // turn the LED on (HIGH is the voltage level)
    delay(300);                       // wait for a second
    analogWrite(led, 0);    // turn the LED off by making the voltage LOW
    delay(1000);
  }
}

Maybe your eye simply isn't fast enough.

You need to move the delay(30); inside of the for loops, otherwise the loops execute too fast for you to see, as hinted at by AWOL.

Also, take a closer look at the top two for loops - they are not error free.

Thank you all for the help though,

Arduarn, I moved the delay(30) into both of the loops and no change.
Plus I dont see any errors in the code and it compiled with no errors.
I dont think that my vision is the issue as when I comment out certain sections, the other section works perfectly and I can see the fade and blink.

Still a mystery.

Say, I wonder if there is some reset that I need to do/push between each version of these kludges ?
Is there a reset button that says " Clear memory and start over ? "
Hmmm

Fade only…

int led = 9;           // the PWM pin the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
int i = 0;

void setup()
{
// declare pin 9 to be an output:
  pinMode(led, OUTPUT);
}

// The Fade section 

void loop()
{
  // set the brightness of pin 9:

  // change the brightness for next time through the loop:

  for (i = 0; i <= 255; i++);
  {
    analogWrite(led, brightness);
    brightness = brightness + fadeAmount;
    delay(30);
  }

  // reverse the direction of the fading at the ends of the fade:

  for (i = 0; i <= 255; i++);
  if (brightness <= 0 || brightness >= 255)
  {
    fadeAmount = -fadeAmount;
    delay(30);
  }
}

Blink only,

int led = 9;           // the PWM pin the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
int i = 0;

void setup()
{
// declare pin 9 to be an output:
  pinMode(led, OUTPUT);
}

// The Fade section 

void loop()
{
  // set the brightness of pin 9:

  // change the brightness for next time through the loop:

  /*for (i = 0; i <= 255; i++);
  {
    analogWrite(led, brightness);
    brightness = brightness + fadeAmount;
    delay(30);
  }

  // reverse the direction of the fading at the ends of the fade:

  for (i = 0; i <= 255; i++);
  if (brightness <= 0 || brightness >= 255)
  {
    fadeAmount = -fadeAmount;
    delay(30);
  }
*/
  // wait for 30 milliseconds to see the dimming effect
  

// and the Blink section 

for (i = 0; i < 255; i+5)
  {
    analogWrite(led, 255);   // turn the LED on (HIGH is the voltage level)
    delay(300);                       // wait for a second
    analogWrite(led, 0);    // turn the LED off by making the voltage LOW
    delay(1000);
  }
}

Well, I saw something that didnt look right so I changed it a bit and it still works the same…

This code…

for (i = 0; i < 255; i+5)
{
analogWrite(led, 255); // turn the LED on (HIGH is the voltage level)
delay(300); // wait for a second
analogWrite(led, 0); // turn the LED off by making the voltage LOW
delay(1000);
}

Changed to this…

for (i = 0; i < 5; i++ )
{
analogWrite(led, 255); // turn the LED on (HIGH is the voltage level)
delay(300); // wait for a second
analogWrite(led, 0); // turn the LED off by making the voltage LOW
delay(1000);
}

  for (i = 0; i <= 255; i++);
                            ^
----------------------------|

  {
    analogWrite(led, brightness);
    brightness = brightness + fadeAmount;
  }
  // reverse the direction of the fading at the ends of the fade:

  for (i = 0; i <= 255; i++);
  if (brightness <= 0 || brightness >= 255)
  {
    // Wot? No alalogWrite() ?
    fadeAmount = -fadeAmount; // 5 = -5, -5 = 5, 5 = -5...
  }

And there may be more mistakes…

hextejas:
I dont think that my vision is the issue as …

Thank you again Arduarn, you da man !
I am surprised that the error in the syntax of the if command was not caught by the compiler.
I have a lot to learn.

anyhow, I took the erroneous ;;; out and it works better now, I still have stuff to try and fix.

This code came straight from the “Fade” example. I put the “for” around it.

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);

And I dont understand your comment

// Wot? No alalogWrite() ?
    fadeAmount = -fadeAmount; // 5 = -5, -5 = 5, 5 = -5...

I am surprised that the error in the syntax of the if command was not caught by the compiler.

Probably because there is no syntax error.

And I dont understand your comment

I think they were noting the absence of an analogWrite

This code came straight from the "Fade" example. I put the "for" around it.

Yeah, but once you modify it you own it.

AWOL: I think he was noting the absence of an analogWrite

That and the fact that fadeAmount = -fadeAmount may make perfect sense in the fade example, but makes much less sense with the explicit for loops as shown.