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