Have run into a wall

Hello everyone.

I have run into a brick wall here. I am trying to fade the led up and down .

Trying to set a delay after the if statement as there is only a delay on the way down.

I try to put in a delay between if and else statement but only come up with errors no matter what I do.

Scratching my head.

Here is my code.

/*
Fade

This example shows how to fade an LED on pin 9
using the analogWrite() function.

This example code is in the public domain.
*/

int led = 9; // the pin that the LED is attached to
int brightness = 0; // how bright the LED is at beginning
int fadeAmount = 10; // how many points to fade up the LED by
int brightness1 = 255; //how bright the led is after step up
int fadeamount2 = 10; //how many points to fade down by

// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:

analogWrite(led, brightness);
//analogWrite(led, brightness);
analogWrite(led, brightness1);
//analogWrite(led, brightness1);

// change the brightness for next time through the loop:
if (brightness == 0)
brightness = brightness + fadeAmount;

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

else (brightness1 == 255);
brightness1 = brightness1 - fadeamount2;

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

Must be something simple I cannot see.
Any help would be appreciated.

onecansay

else (brightness1 == 255);

What's that?

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

30, you say?

analogWrite(led, brightness);
  //analogWrite(led, brightness);
  analogWrite(led, brightness1);

Why write a value that varies, then immediately one that overwrites it?

Ya', well I was trying to put a delay between the up fade and down fade. The goal is to fade up and then hold it there. Did not realize that this is the delay function. In the future I need to program this to work with an RTC. Also have individual channels fade separately but me knows that will come. Actually the next thing I do.

Guess it got out of hand. That is how one learns.

Thanks for bonkin' me on the head though.

onecansay

Still trying to put a delay between the time the fade ends and begins.

That is where all this started LOL.

Thanks,
onecansay

Post your code.

Just using the basic digital fade routine.

Have tried to apply a delay between where fade stops at bottom and starts again. I have tried to put in a delay just above the reverse scenario but no go.

/*
Fade

This example shows how to fade an LED on pin 3
using the analogWrite() function.

This example code is in the public domain.
*/

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

// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
analogWrite(led, brightness);

// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;

// 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);
}

Thanks,
onecansay

// reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }

This is where the minimum and maximum values are detected. If you want the LED to stay fully bright or fully dim for a period of time, here is where to do it.

Thanks, I did get it doing what I desired.

On to the next lesson(s). :astonished:

onecansay