From the course: Arduino: Prototyping
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Implement non-blocking interaction - Arduino Tutorial
From the course: Arduino: Prototyping
Implement non-blocking interaction
- [Instructor] Using a timer is a way to time things in your sketch without holding up or blocking the main loop. This allows an animation to continue, for example, while still being responsive waiting for a button press. Here's a reminder of the basic timer pseudocode. We start the timer by saving the current millis as the start time, and then each time through the loop, we check if the current time minus the start time is greater than the timer length. When our timer has expired, we update the animation and reset the timer. So now let's look at how this would actually be implemented in our prototype. Okay, so we're looking at our previous sketch, RETRO_2. Let's right off the bat save this as RETRO_3. First of all, let's get rid of our delay, because we're going to be replacing that with our timer. So we can do that. And then we need a couple of variables up here to manage our timer, three in particular. First of all, we…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.