Go Down

Topic: slow lighting or dimming (Read 366 times) previous topic - next topic

artuksa

Hello there, have started with a very simple for loop to brighten/or dim an led lamp.

// Dim an LED using PWM
int PWMpin = 10; 

void setup() {
 
}

void loop() {
  for (int i = 0; i <= 255; i=i++)
  {
    analogWrite(PWMpin, i);
    delay(5000);
  }
}

Can anyone suggest the approach I could take to make a very slow dim/brighten loop up to 60 minutes or longer, or is a 'slow loop' not a good approach to this, would appreciate some suggestions as to how I might approach this, thanks.

Grumpy_Mike

Just change the delay to make the process longer.

To make that code last an hour then the delay should be for:-
(60 * 60) / 256 seconds

PaulRB

is a 'slow loop' not a good approach to this
It depends what else you need your Arduino to do at the same time. If it needs to react to events like button presses during lighting/dimming, then this slow loop is not suitable. But if the Arduino has nothing else to do, then its OK.

artuksa

Thanks for the replies, appreciated

Go Up