Hi
This is my first arduino project that i am trying to learn to do myself and not some pre assembled thing. What I am trying to do is to fade the led one after another not together. And I can't seem to manage to do that. here is my code.
#include <math.h>
unsigned long previousMillis = 0; // last time update
long interval = 2000; // interval at which to do something (milliseconds)
void setup()
{
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(6, OUTPUT);
}
void loop()
{
unsigned long currentMillis = millis();
float val = (exp(sin(millis()/2000.0*PI)) - 0.36787944)*108.0;
analogWrite(11, val);
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
analogWrite(11, 0);
}
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
analogWrite(10, val);
}
}