Arduino Forum

Development => Suggestions for the Arduino Project => Topic started by: paulb on Jan 30, 2011, 04:53 am

Title: Reference Material Needs Update
Post by: paulb on Jan 30, 2011, 04:53 am
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





Title: Re: Reference Material Needs Update
Post by: mellis on Jan 31, 2011, 03:11 pm
Fixed.