Pages: 1 [2]   Go Down
Author Topic: What's wrong with my library...?  (Read 1478 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 611
Posts: 49092
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Since the sketch works fine when the increment is 1, I would change the type of the loop variable from byte to int.

I suspect that what is happening is that, when the for loop variable gets incremented, by 2 for instance, that it gets set to 0, 2, 4, ..., 254. The next increment operation tries to set the variable to 256, which causes an overflow, and the value ends up at 0. It goes through the loop again with values of 0, 2, 4, ... 254. The increment and overflow occurs again, and the loop repeats.

Changing the loop variable type to int would prevent this problem.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It worked. Thanks so much!

I was following the LED library example by using "byte" in mine.
Thanks for the help
Logged

Pages: 1 [2]   Go Up
Jump to: