The new Raspberry Pi B Model B+ is here - Pick one up in the store and check our detailed guide!

Arduino Tutorial Lesson 5 Program Question

by mew211 on Sun Dec 16, 2012 2:55 pm


I just did Design Challenge part 3 in Lesson 5 of the Arduino tutorials.
I wrote my own code and it would go through each of the modes fine, but when it got to the wave mode, pressing the button again would not return to the "off" mode.
I tested the code on the site, which of course worked fine.

I noticed that the only difference between the two was that in the wave function I had a delay(500) in my program, while the tutorial had delay(50) in their program.
I changed mine to delay(50) and the code worked fine. Then I changed the code from the tutorial to delay(500) and it had the same problem as mine.

Can anyone explain why this happens? Does the wave function have to run through a certain number of cycles or something? I don't see what in the code would be causing this.
Posts: 1
Joined: Tue Nov 27, 2012 3:20 pm

Re: Arduino Tutorial Lesson 5 Program Question

by adafruit_support_bill on Mon Dec 17, 2012 5:52 am

During the delay, you are not checking the button state. With a longer delay you are more likely to miss the button press.
User avatar
Posts: 28015
Joined: Sat Feb 07, 2009 9:11 am