From the course: Arduino: Prototyping

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Blocking versus non-blocking code

Blocking versus non-blocking code - Arduino Tutorial

From the course: Arduino: Prototyping

Start my 1-month free trial

Blocking versus non-blocking code

- [Instructor] You expect your world to be responsive. When you push on a door, you expect it to respond immediately. If it doesn't, you may run into it. In our prototype, you may have noticed that the timing between pressing a button and zapping an invader is a little off. That timing issue makes the prototype a little confusing and unpredictable. Let's see what that problem is and see if we can fix that. If you look at the code in the Loop function, you can see there's quite a bit that goes on, but the Arduino is pretty fast and it finishes everything quickly. Initially, we let the loop run as quickly as it could, and the animation was way too fast. So to slow things down, we did something that's pretty common. We added a Delay statement, and that's what's causing the timing problem. The problem with Delay is when it's delaying, nothing else is happening. That's okay if you're just watching what's going on, but if…

Contents