Go Down

Topic: Reference Material Needs Update (Read 1 time) previous topic - next topic

paulb

I don't know how this newbie bug made it through - I swear I tested this code:

Anyway - on the "for" reference page.

void loop()
{
   int x = 1;
   for (int i = 0; i > -1; i = i + x){
      analogWrite(PWMpin, i);
      if (i = 255) x = -1;             // switch direction at peak
      delay(10);
   }
}

Change the biggest newbie mistake of

     if (i = 255) x = -1;             // switch direction at peak

to       if (i == 255) x = -1;             // switch direction at peak

Maybe it's proof no one reads the docs anyway

paul






mellis


Go Up