I know it sounds simple to you all but I'm sitting here looking at this:
for (int i = 0; i < 255; i++) { //if i is less than 255 then increase i with 1
analogWrite(pwmLED, i); //write the i value
delay(20); //wait 5 ms then loop again
}
for (int i = 255; i > 0; i--) { //descrease i with 1
analogWrite(pwmLED, i);
delay(5);
analogWrite(pwmLED, LOW);
}
and this, with no idea where to start
const byte pwmLED = 5;
#define UP 0
#define DOWN 1
const int minPWM = 0; // constants for min and max PWM
const int maxPWM = 255;
byte fadeDirection = UP; // Fade Direction
int fadeValue = 0;
byte fadeIncrement = 5; // How smooth to fade?
unsigned long previousFadeMillis; // timing Variable,
unsigned long previousHighMillis; //How long to stay high
int fadeInterval = 45; // increment?
int highInterval = 2000;
void setup() {
analogWrite(pwmLED, fadeValue);
}
void doTheFade(unsigned long thisMillis) {
if (thisMillis - previousFadeMillis >= fadeInterval) {
if (fadeDirection == UP) {
fadeValue = fadeValue + fadeIncrement;
if (fadeValue >= maxPWM) {
fadeValue = maxPWM; // At max, limit and change direction
if (fadeValue = maxPWM) {
digitalWrite(pwmLED, HIGH); }
if(thisMillis - previousHighMillis <= highInterval) { }
fadeDirection = DOWN;
}
} else {
//if we aren't going up, we're going down
fadeValue = fadeValue - fadeIncrement;
if (fadeValue <= minPWM) {
// At min, limit and change direction
fadeValue = minPWM;
digitalWrite(pwmLED, LOW);
fadeDirection = UP;
}
}
analogWrite(pwmLED, fadeValue); // update when it changes
// reset
}
}
void loop() {
unsigned long currentMillis = millis();
doTheFade(currentMillis);
}