int ledfwd = 11;
int ledrvs = 10;
int led = ledrvs;
int ledrly = 12;
long rampuptime = 5000;
long pwm1 = 5; //pwm1
long pwm2 = 20;//pwm2 max
unsigned long previousMillis = 0;
long interval1 = rampuptime / pwm1;
long interval2 = rampuptime / pwm2;
long ontime1 = 15000;
long switchtime = 10000;
long turnon = 30000;
int brightness1 = 0;
int fadeAmount = 1; //change to 1 for final code
int on = 0;
unsigned long currentMillis = millis();
void setup() {
Serial.begin(9600);
int brightness = 0;
pinMode(led, OUTPUT);
}
void loop()
{currentMillis = millis();
start();
}
void rampup1()
{
analogWrite(led, brightness1);
if (brightness1 <= pwm1)
{
Serial.println("ramp1");
brightness1 = constrain(brightness1, 0, pwm1);
Serial.println((String)"BRIGHTNESS1:" + brightness1 + " Time:" + currentMillis);
if (currentMillis - previousMillis >= interval1) {
previousMillis = currentMillis;
brightness1 = brightness1 + fadeAmount;
}
}
else if (brightness1 >= pwm1 && brightness1 < pwm2)
{
Serial.println("ramp2");
brightness1 = constrain(brightness1, pwm1, pwm2);
Serial.println((String)"BRIGHTNESS1:" + brightness1 + " Time:" + currentMillis);}
{
brightness1 = pwm2;
}
if (currentMillis - previousMillis >= interval2) {
previousMillis = currentMillis;
brightness1 = brightness1 + fadeAmount;
}
}
void switch1 ()
{
if (ontime1 >= switchtime)
{ led = ledfwd;}
else {led = ledrvs;}
}
void start ()
{
if (currentMillis >= on)
{rampup1();}
else if (currentMillis >= on && currentMillis <= ontime1)
{brightness1 = pwm2;
analogWrite(led, brightness1);}
else (currentMillis > ontime1 && currentMillis <= turnon)
;{brightness1 = 0;
analogWrite(led, brightness1);
switch1 ();}
}
the above code is SUPPOSED to turn on the ramp up (which works) but the void start statement is not turning it on at all.... well it does but keeps pwm at 0.
the idea is that if current millis is more then on (0) and less then ontime1 (15000) run the ramp up code
after that brightness = pwm2 and stays on untill offtime
after that pwm = 0 until next cycle
at the moment it keeps pwm at 0