Pages: [1]   Go Down
Author Topic: Reference Material Needs Update  (Read 1320 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 267
dinosaur cork
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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





Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Fixed.
Logged

Pages: [1]   Go Up
Jump to: