Arduino Tutorial Lesson 5 Program Question

For makers who have purchased an Adafruit Starter Pack, get help with the tutorials here!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mew211
 
Posts: 1
Joined: Tue Nov 27, 2012 4:20 pm

Arduino Tutorial Lesson 5 Program Question

Post by mew211 »

Hi,

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.
Thanks!

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino Tutorial Lesson 5 Program Question

Post by adafruit_support_bill »

During the delay, you are not checking the button state. With a longer delay you are more likely to miss the button press.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Starter Pack”