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.

Implement button functions

Implement button functions - Arduino Tutorial

From the course: Arduino: Prototyping

Start my 1-month free trial

Implement button functions

- [Instructor] As you prototype, you'll begin to realize that you're using some of the same code patterns over and over. For example, the debounce code that we created earlier might be useful in any prototype we build that uses buttons. We can easily Copy and Paste this code from one sketch to another, but then we'd have to edit the code to reflect the pin number being debounced and the interval being used in the new sketch. Another way to reuse the debounce code from sketch to sketch is to create a debounce function. The function can be copied to different sketches, just like sharing the original code. But we'll see in the finished version that the function won't require any editing to reflect different pin numbers or debounce times. A simple version of the debounce function just uses the exact same code as the sketch, but the code is included in the function definition. A function definition begins with the function…

Contents