andrewf:
Hi all!
I'm new to Arduino, but am learning pretty quickly.
I was wondering if there was any way to use PWM to steadily increase something.
...
Or maybe you want the LED to increase in brightness 10% each 15 minutes that go by.
How could this be done?Thanks!
I'm winging this off the top of my head, so here goes:
#define INTERVAL 60000 // change interval in milliseconds
#define DELTAB 25 // change in brightness
const int LedPin = 13;
int LedBrightness = 0;
unsigned long previousMillis;
void setup(void)
{
previousMillis = millis();
analog.write(LedPin, LedBrightness);
}
void loop(void)
{
if (millis() - previousMillis > INTERVAL)
{
previousMillis = millis();
if (LedBrightness < 256)
{
LedBrightness += DELTAB;
analog.write(LedPin, LedBrightness);
}
}
// do other stuff here ( or not)
}
This code will start the LED off, and then once a minute (60,000 ms) increase the pulse width by DELTAB until it's full on. LED brightness may not be a linear function of pulse width. I have code very similar to this controlling the brightness of 12 volt incandescent lamps.